tags: jump to pattern when opening buffer (closes #245)

main
bhagwan 3 years ago
parent 46c9e2bcd2
commit e7c4970146

@ -67,6 +67,7 @@ M.vimcmd_file = function(vimcmd, selected, opts)
local curbuf = vim.api.nvim_buf_get_name(0)
for i = 1, #selected do
local entry = path.entry_to_file(selected[i])
entry.ctag = path.entry_to_ctag(selected[i])
-- Java LSP entries, 'jdt://...'
if entry.uri then
vim.cmd("normal! m`")
@ -85,13 +86,17 @@ M.vimcmd_file = function(vimcmd, selected, opts)
-- when `:set nohidden`
return
end
-- add current location to jumplist
vim.cmd("normal! m`")
if vimcmd ~= "e" or curbuf ~= fullpath then
vim.cmd(vimcmd .. " " .. vim.fn.fnameescape(entry.path))
end
if entry.line > 1 or entry.col > 1 then
-- add current location to jumplist
vim.cmd("normal! m`")
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
if entry.ctag or entry.line>1 or entry.col>1 then
if entry.ctag then
vim.fn.search(entry.ctag, "W")
else
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
end
vim.cmd("norm! zvzz")
end
end

@ -129,6 +129,18 @@ local function stripBeforeLastOccurrenceOf(str, sep)
return str:sub(idx+1), idx
end
function M.entry_to_ctag(entry)
local scode = entry:match("%:.-/^?\t?(.*)/")
if scode then
scode = string.gsub(scode, "[$]$", "")
scode = string.gsub(scode, [[\\]], [[\]])
scode = string.gsub(scode, [[\/]], [[/]])
scode = string.gsub(scode, "[*]", [[\*]])
end
return scode
end
function M.entry_to_location(entry)
local uri, line, col = entry:match("^(.*://.*):(%d+):(%d+):")
line = line and tonumber(line-1) or 0

@ -602,19 +602,11 @@ end
function Previewer.tags:parse_entry(entry_str)
-- first parse as normal entry
local entry = self.super.parse_entry(self, entry_str)
-- add the ctag part:
-- must use 'super.' and send self as 1st arg
-- or the ':' syntactic suger will send super's
-- self which doesn't have self.opts
local scode = entry_str:match("%:.-/^?\t?(.*)/")
if scode then
scode = string.gsub(scode, "[$]$", "")
scode = string.gsub(scode, [[\\]], [[\]])
scode = string.gsub(scode, [[\/]], [[/]])
scode = string.gsub(scode, "[*]", [[\*]])
end
entry.ctag = scode
local entry = self.super.parse_entry(self, entry_str)
entry.ctag = path.entry_to_ctag(entry_str)
return entry
end

Loading…
Cancel
Save