tags|btags bugfix: preview/action when tag name contains / or <Tab>

main
bhagwan 2 years ago
parent 1c30a354d2
commit b98bb2618c

@ -319,9 +319,10 @@ M.file = function(opts, x)
end
M.tag = function(opts, x)
local name, file, text = x:match("^(.*)\t(.*)\t(.*/)")
local line, tag = text:match("(%d-);?(/.*/)")
if not file then return x end
local name, file, text = x:match("([^\t]+)\t([^\t]+)\t(.*)")
if not file or not name or not text then return x end
text = text:match('(.*);"') or text -- remove ctag comments
local line, tag = text:gsub("\\/", "/"):match("(%d-);?(/.*/)")
return ("%s%s: %s %s"):format(
M.file(opts, file),
(not line or #line==0) and "" or ":"..utils.ansi_codes.green(tostring(line)),

@ -141,6 +141,10 @@ end
function M.entry_to_ctag(entry, noesc)
local scode = entry:match("%:.-/^?\t?(.*)/")
-- if tag name contains a slash we could
-- have the wrong match, most tags start
-- with ^ so try to match based on that
scode = scode and scode:match("/^(.*)") or scode
if scode and not noesc then
-- scode = string.gsub(scode, "[$]$", "")
scode = string.gsub(scode, [[\\]], [[\]])

@ -13,7 +13,6 @@ function Previewer.base:new(o, opts)
self.type = "cmd";
self.cmd = o.cmd;
self.args = o.args or "";
self.relative = o.relative
self.opts = opts;
return self
end
@ -77,7 +76,7 @@ function Previewer.cmd:action(o)
o = o or {}
local act = shell.raw_action(function (items, _, _)
-- only preview first item
local entry = path.entry_to_file(items[1], not self.relative and self.opts.cwd)
local entry = path.entry_to_file(items[1], self.opts.cwd)
return entry.bufname or entry.path
end, self.opts.field_index_expr or "{}")
return act
@ -159,13 +158,15 @@ local grep_tag = function(file, tag)
local out = utils.io_system(cmd)
if not utils.shell_error() then
line = out:match("[^:]+")
else
utils.warn(("Unable to find pattern '%s' in file '%s'"):format(pattern, file))
end
-- if line == 1 then print(cmd) end
return line
end
function Previewer.cmd_async:parse_entry_and_verify(entrystr)
local entry = path.entry_to_file(entrystr, not self.relative and self.opts.cwd)
local entry = path.entry_to_file(entrystr, self.opts.cwd)
local filepath = entry.bufname or entry.path or ''
if self.opts._ctag and entry.line<=1 then
-- tags without line numbers
@ -176,6 +177,7 @@ function Previewer.cmd_async:parse_entry_and_verify(entrystr)
if not line and ctag then
entry.ctag = ctag
entry.line = grep_tag(filepath, entry.ctag)
print("line", entry.line, entry.ctag)
end
end
local errcmd = nil
@ -272,7 +274,7 @@ function Previewer.git_diff:cmdline(o)
self.git_icons['?'] ..
self.git_icons['C'] ..
"]"..utils.nbsp) ~= nil
local file = path.entry_to_file(items[1], not self.relative and self.opts.cwd)
local file = path.entry_to_file(items[1], self.opts.cwd)
local cmd = nil
if is_modified then cmd = self.cmd_modified
elseif is_deleted then cmd = self.cmd_deleted

Loading…
Cancel
Save