@@ -377,21 +377,43 @@ function M.lengthen(path)
377377 or string.format (" <glob expand failed for '%s'>" , glob_expr )
378378end
379379
380- function M .entry_to_ctag (entry , noesc )
381- local ctag = entry :match (" %:.-[/\\ ]^?\t ?(.*)[/\\ ]" )
382- -- if tag name contains a slash we could
383- -- have the wrong match, most tags start
384- -- with ^ so try to match based on that
385- ctag = ctag and ctag :match (" [/\\ ]^(.*)" ) or ctag
386- if ctag and not noesc then
387- -- required escapes for vim.fn.search()
388- -- \ ] ~ *
389- ctag = ctag :gsub (" [\\ %]~*]" ,
390- function (x )
391- return " \\ " .. x
392- end )
393- end
394- return ctag
380+ --- @param excmd string
381+ --- @param do_not_strip_slashes boolean ?
382+ --- @return number ?, string ?
383+ function M .parse_ctag_excmd (excmd , do_not_strip_slashes )
384+ -- remove anything after excmd ;" postfix
385+ excmd = excmd :gsub ([[ ;".-$]] , " ;" )
386+ -- test for "--excmd={number|combine}"
387+ local line = excmd :match (" ^(%d+);" )
388+ -- adjust for line, position cursor after ;
389+ if line then excmd = excmd :sub (# line + 2 ) end
390+ -- extract ctag
391+ local tag = do_not_strip_slashes
392+ and excmd :match (" /.*/" )
393+ or excmd :match (" /(.*)/" )
394+ return tonumber (line ), tag
395+ end
396+
397+ --- @param raw string
398+ --- @param opts table
399+ --- @return fzf-lua.path.Entry
400+ function M .entry_to_ctag (raw , opts )
401+ assert (opts ._ctag )
402+ local _ , file , excmd = raw :match (" ([^\t ]+)\t ([^\t ]+)\t (.*)" )
403+ if not file or not excmd then return {} end
404+ file = file :match (" .*" .. utils .nbsp .. " (.+)$" ) or file
405+ local cwd = opts .cwd or opts ._cwd
406+ if cwd and not M .is_absolute (file ) then file = M .join ({ cwd , file }) end
407+ if opts .path_shorten then file = M .lengthen (file ) end
408+ local line , tag = M .parse_ctag_excmd (excmd )
409+ return {
410+ path = file ,
411+ ctag = tag ,
412+ line = line or 0 ,
413+ col = 0 ,
414+ stripped = string.format (" %s:%s %s" , file , line and line .. " :" or " " , tag or " " ),
415+ debug = opts .debug and raw :match (" ^%[DEBUG]" ) and raw or nil ,
416+ } --- @as fzf-lua.path.Entry
395417end
396418
397419--- @param entry string
437459function M .entry_to_file (entry , opts , force_uri )
438460 -- NOTE: see note in meta.lua:global regarding alt options
439461 opts = opts and opts .__alt_opts or opts or {}
462+ assert (opts )
440463 if opts ._fmt then
441464 if type (opts ._fmt ._from ) == " function" then
442465 entry = opts ._fmt ._from (entry , opts )
@@ -450,6 +473,10 @@ function M.entry_to_file(entry, opts, force_uri)
450473 if opts .render_crlf then
451474 entry = entry :gsub (" ␊" , " \n " ):gsub (" ␍" , " \r " )
452475 end
476+ -- ctag processing is done separately
477+ if opts ._ctag then
478+ return M .entry_to_ctag (entry , opts )
479+ end
453480 local stripped , idx = (function ()
454481 -- Returns the first viable path:line?:col? + rest of line
455482 -- stripping until the last occurrence of utils.nbsp may err
@@ -556,7 +583,6 @@ function M.entry_to_file(entry, opts, force_uri)
556583 line = utils .tointeger (type (opts .line_query ) == " function" and
557584 (opts .line_query (FzfLua .get_info ().query )) or line ) or 0 ,
558585 col = utils .tointeger (col ) or 0 ,
559- ctag = opts ._ctag and M .entry_to_ctag (stripped ) or nil ,
560586 debug = opts .debug and entry :match (" ^%[DEBUG]" ) and entry or nil ,
561587 }
562588end
0 commit comments