Skip to content

Commit

Permalink
feat(ctags): match hl for ctags -R --excmd=combine
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 5, 2024
1 parent 865a46f commit 9958d6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,11 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
regex = require("fzf-lua.make_entry").glob_parse(regex, self.opts)
end

-- If called from tags previewer, can happen when using ctags cmd
-- "ctags -R --c++-kinds=+p --fields=+iaS --extras=+q --excmd=combine"
regex = regex and utils.regex_to_magic(regex)
or entry.ctag and utils.ctag_to_magic(entry.ctag)

pcall(vim.api.nvim_win_call, self.win.preview_winid, function()
local cached_pos = self.cached_bufnrs[tostring(self.preview_bufnr)]
if type(cached_pos) ~= "table" then cached_pos = nil end
Expand All @@ -885,7 +890,7 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
local regex_match_len = 0
if regex and self.win.hls.search then
-- vim.regex is always magic, see `:help vim.regex`
local ok, reg = pcall(vim.regex, utils.regex_to_magic(regex))
local ok, reg = pcall(vim.regex, regex)
if ok then
_, regex_match_len = reg:match_line(self.preview_bufnr, lnum - 1, math.max(1, col) - 1)
regex_match_len = tonumber(regex_match_len) or 0
Expand Down
4 changes: 4 additions & 0 deletions lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ function M.regex_to_magic(str)
return [[\v]] .. str:gsub("[=&<>]", function(x) return [[\]] .. x end)
end

function M.ctag_to_magic(str)
return [[\v]] .. str:gsub("[=&@<>{%(%)%.%[]", function(x) return [[\]] .. x end)
end

function M.sk_escape(str)
if not str then return str end
return str:gsub('["`]', function(x)
Expand Down

0 comments on commit 9958d6a

Please sign in to comment.