Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: allow complete motion customization #52

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lua/precognition/horizontal_motions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function M.matching_bracket(str, cursorcol, linelen)
end
end

--[[]]
if not idxFound then
for i, bracket in ipairs(supportedBrackets.close) do
if bracket == under_cursor then
Expand All @@ -198,7 +199,10 @@ function M.matching_bracket(str, cursorcol, linelen)
if char == openBracket then
depth = depth + 1
end
if char == closeBracket or char == middleBracket then
if
--[[]]
char == closeBracket or char == middleBracket
then
depth = depth - 1
if depth == 0 then
break
Expand All @@ -210,7 +214,7 @@ function M.matching_bracket(str, cursorcol, linelen)

if under_cursor == closeBracket then
local depth = 1
offset = offset - 2
offset = offset - 1
while offset >= 0 do
local char = vim.fn.strcharpart(str, offset - 1, 1)
if char == closeBracket then
Expand Down Expand Up @@ -272,21 +276,19 @@ end

---@param str string
---@param cursorcol integer
---@param _linelen integer
---@return function
function M.matching_pair(str, cursorcol, _linelen)
---@param line_len integer
---@return Precognition.PlaceLoc
function M.matching_pair(str, cursorcol, line_len)
local char = vim.fn.strcharpart(str, cursorcol - 1, 1)
if char == "/" or char == "*" then
return M.matching_comment
return M.matching_comment(str, cursorcol, line_len)
end

if vim.tbl_contains(supportedBrackets.open, char) or vim.tbl_contains(supportedBrackets.close, char) then
return M.matching_bracket
return M.matching_bracket(str, cursorcol, line_len)
end

return function()
return 0
end
return 0
end

return M
86 changes: 52 additions & 34 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,28 @@ local M = {}

---@type Precognition.HintConfig
local defaultHintConfig = {
Caret = { text = "^", prio = 2 },
Dollar = { text = "$", prio = 1 },
MatchingPair = { text = "%", prio = 5 },
Zero = { text = "0", prio = 1 },
w = { text = "w", prio = 10 },
b = { text = "b", prio = 9 },
e = { text = "e", prio = 8 },
W = { text = "W", prio = 7 },
B = { text = "B", prio = 6 },
E = { text = "E", prio = 5 },
-- Caret = { text = "^", prio = 2, fn = hm.line_start_non_whitespace },
-- Dollar = { text = "$", prio = 1, fn = hm.line_end },
MatchingPair = { text = "%", prio = 50, fn = hm.matching_pair },
Zero = {
text = "0",
prio = 1,
fn = function()
return 1
end,
},
-- w = { text = "w", prio = 10, fn = hm.next_word_boundary },
-- b = { text = "b", prio = 9, fn = hm.prev_word_boundary },
-- e = { text = "e", prio = 8, fn = hm.end_of_word },
-- W = {
-- text = "W",
-- prio = 7,
-- fn = hm.next_word_boundary,
-- -- FIXME: Is this needed? We can probably just check if the motion letter is uppercase.
-- big = true,
-- },
-- B = { text = "B", prio = 6, fn = hm.prev_word_boundary, big = true },
-- E = { text = "E", prio = 5, fn = hm.end_of_word, big = true },
}

---@type Precognition.Config
Expand All @@ -80,10 +92,10 @@ local default = {
hints = defaultHintConfig,
gutterHints = {
--prio is not currentlt used for gutter hints
G = { text = "G", prio = 1 },
gg = { text = "gg", prio = 1 },
PrevParagraph = { text = "{", prio = 1 },
NextParagraph = { text = "}", prio = 1 },
G = { text = "G", prio = 1, fn = vm.file_end },
gg = { text = "gg", prio = 1, fn = vm.file_start },
PrevParagraph = { text = "{", prio = 1, fn = vm.prev_paragraph_line },
NextParagraph = { text = "}", prio = 1, fn = vm.next_paragraph_line },
},
}

Expand Down Expand Up @@ -162,14 +174,11 @@ end

---@return Precognition.GutterHints
local function build_gutter_hints()
---@type Precognition.GutterHints
local gutter_hints = {
G = vm.file_end(),
gg = vm.file_start(),
PrevParagraph = vm.prev_paragraph_line(),
NextParagraph = vm.next_paragraph_line(),
}
return gutter_hints
return vim.iter(config.gutterHints)
:map(function(_, opts)
return opts.fn()
end)
:totable()
end

---@param gutter_hints Precognition.GutterHints
Expand Down Expand Up @@ -232,18 +241,27 @@ local function display_marks()
-- get char offsets for more complex motions.
--
---@type Precognition.VirtLine
local virtual_line_marks = {
Caret = hm.line_start_non_whitespace(cur_line, cursorcol, line_len),
w = hm.next_word_boundary(cur_line, cursorcol, line_len, false),
e = hm.end_of_word(cur_line, cursorcol, line_len, false),
b = hm.prev_word_boundary(cur_line, cursorcol, line_len, false),
W = hm.next_word_boundary(cur_line, cursorcol, line_len, true),
E = hm.end_of_word(cur_line, cursorcol, line_len, true),
B = hm.prev_word_boundary(cur_line, cursorcol, line_len, true),
MatchingPair = hm.matching_pair(cur_line, cursorcol, line_len)(cur_line, cursorcol, line_len),
Dollar = hm.line_end(cur_line, cursorcol, line_len),
Zero = 1,
}
local virtual_line_marks = vim.iter(config.hints)
:map(function(hint, opts)
return hint, opts.fn(cur_line, cursorcol, line_len, opts.big or false)
end)
:fold({}, function(acc, hint, pos)
acc[hint] = pos
return acc
end)

-- local virtual_line_marks = {
-- Caret = hm.line_start_non_whitespace(cur_line, cursorcol, line_len),
-- w = hm.next_word_boundary(cur_line, cursorcol, line_len, false),
-- e = hm.end_of_word(cur_line, cursorcol, line_len, false),
-- b = hm.prev_word_boundary(cur_line, cursorcol, line_len, false),
-- W = hm.next_word_boundary(cur_line, cursorcol, line_len, true),
-- E = hm.end_of_word(cur_line, cursorcol, line_len, true),
-- B = hm.prev_word_boundary(cur_line, cursorcol, line_len, true),
-- MatchingPair = hm.matching_pair(cur_line, cursorcol, line_len)(cur_line, cursorcol, line_len),
-- Dollar = hm.line_end(cur_line, cursorcol, line_len),
-- Zero = 1,
-- }

--multicharacter padding
utils.add_multibyte_padding(cur_line, extra_padding, line_len)
Expand Down
Loading