v3
Some checks failed
ci / ci (push) Has been cancelled

- range: extmarks/tsquery
- mise for dev env
- get rid of obsolete modules
- implement as single file module
This commit is contained in:
2025-06-11 20:04:46 -06:00
parent 12945a4cdf
commit c1a8af8b7c
50 changed files with 3535 additions and 5338 deletions

51
examples/matcher.lua Normal file
View File

@@ -0,0 +1,51 @@
--
-- Bracket matcher: highlights the nearest matching pair of brackets (like MatchParen)
-- when the cursor is near them. Updates dynamically on CursorMoved in normal mode.
--
local u = require 'u'
local Range = u.Range
local M = {}
--- @type { clear: fun() }[]
local HIGHLIGHTS = {}
local LAST_RANGE = nil
local function clear_highlights()
for _, hl in ipairs(HIGHLIGHTS) do
hl.clear()
end
HIGHLIGHTS = {}
end
local function update()
local mode = vim.fn.mode():sub(1, 1)
if mode ~= 'n' then return end
local last_range = LAST_RANGE
local bracket_range = Range.find_nearest_brackets()
LAST_RANGE = bracket_range
if not bracket_range then return clear_highlights() end
if bracket_range == last_range then return end
clear_highlights()
local open = Range.new(bracket_range.start, bracket_range.start, 'v')
local close = Range.new(bracket_range.stop, bracket_range.stop, 'v')
HIGHLIGHTS = {
open:highlight('MatchParen', { priority = 999 }),
close:highlight('MatchParen', { priority = 999 }),
}
end
function M.setup()
local group = vim.api.nvim_create_augroup('Matcher', { clear = true })
vim.api.nvim_create_autocmd({ 'CursorMoved' }, {
group = group,
callback = update,
})
end
return M