tags|btags: properly handle all special characters (closes #371)

main
bhagwan 2 years ago
parent 1d93315328
commit 97a63e66bf

@ -332,7 +332,13 @@ M.tag = function(opts, x)
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-);?(/.*/)")
-- unescape ctags special chars
-- '\/' -> '/'
-- '\\' -> '\'
for _, s in ipairs({ '/', '\\' }) do
text = text:gsub([[\]]..s, s)
end
local line, tag = text:match("(%d-);?(/.*/)")
line = line and #line>0 and tonumber(line)
return ("%s%s: %s %s"):format(
M.file(opts, file),

@ -140,18 +140,20 @@ end
function M.entry_to_ctag(entry, noesc)
local scode = entry:match("%:.-/^?\t?(.*)/")
local ctag = 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, [[\\]], [[\]])
scode = string.gsub(scode, [[\/]], [[/]])
scode = string.gsub(scode, "[*]", [[\*]])
ctag = ctag and ctag:match("/^(.*)") or ctag
if ctag and not noesc then
-- required escapes for vim.fn.search()
-- \ ] ~ *
ctag = ctag:gsub('[\\%]~*]',
function(x)
return '\\' .. x
end)
end
return scode
return ctag
end
function M.entry_to_location(entry)

Loading…
Cancel
Save