mirror of
https://github.com/junegunn/fzf.vim.git
synced 2026-10-04 09:23:46 +08:00
Take an address fragment only where the whole line is in hand
:BTags reads the address field on its own, so a tab inside a ctags pattern leaves a fragment such as '/^', which matched whatever line came next and recorded it in the quickfix list. ctags always terminates its patterns, so on the field alone a fragment is the cut and is refused. The '/*:Ag*' of a helptags file has no terminator and still goes through, :Tags having the whole line.
This commit is contained in:
1 file changed
+20
-17
+20
-17
@@ -547,21 +547,21 @@ function! s:sandboxed(cmd)
|
|||||||
return 'sandbox execute '.string(a:cmd)
|
return 'sandbox execute '.string(a:cmd)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Address of a tag, given the rest of the line after the file name. Only the
|
" Address of a tag, given the rest of the line after the file name, or, with
|
||||||
" forms a tags file is meant to hold, a line number and a search pattern,
|
" 'whole' off, the address field alone as :BTags reads it. Only the forms a tags
|
||||||
" chained with ';' for '--excmd=combine' and cut at the ';"' terminator as
|
" file is meant to hold, a line number and a search pattern, chained with ';' for
|
||||||
" Vim's find_extra() does. Returns an empty string for anything else, which is
|
" '--excmd=combine' and cut at the ';"' terminator as Vim's find_extra() does.
|
||||||
" then not run.
|
" Returns an empty string for anything else, which is then not run.
|
||||||
"
|
"
|
||||||
" A pattern holding a tab reaches :BTags cut short, since it reads the field on
|
" A pattern holding a tab reaches :BTags cut short. Where earlier parts parsed,
|
||||||
" its own. Where earlier parts parsed, keep those and drop the fragment, since a
|
" keep those, since a line number beats half a pattern. A fragment on its own is
|
||||||
" line number beats half a pattern. A fragment on its own is indistinguishable
|
" an address only where the whole line is in hand, as in a helptags file, whose
|
||||||
" from a helptags address such as '/*:Ag*', so it goes through unterminated, the
|
" '/*:Ag*' carries no terminator. ctags always terminates, so on the field alone
|
||||||
" way a builtin tag jump takes the same field. Running to the end of the line, it
|
" a fragment is the cut, and it would match some other line. Running to the end
|
||||||
" takes any '|' or ';' with it, so it cannot chain a command either.
|
" of the line it takes any '|' or ';' with it, so it cannot chain a command.
|
||||||
let s:tag_address_part = '\%(\d\+\|/\%(\\.\|[^/\\]\)*/\|?\%(\\.\|[^?\\]\)*?\)'
|
let s:tag_address_part = '\%(\d\+\|/\%(\\.\|[^/\\]\)*/\|?\%(\\.\|[^?\\]\)*?\)'
|
||||||
let s:tag_address_open = '\%(/\%(\\.\|[^/\\]\)*\|?\%(\\.\|[^?\\]\)*\)'
|
let s:tag_address_open = '\%(/\%(\\.\|[^/\\]\)*\|?\%(\\.\|[^?\\]\)*\)'
|
||||||
function! s:tag_address(rest)
|
function! s:tag_address(rest, whole)
|
||||||
" :BTags aligns its columns, so its field arrives padded
|
" :BTags aligns its columns, so its field arrives padded
|
||||||
let rest = s:strip(a:rest)
|
let rest = s:strip(a:rest)
|
||||||
let chain = '^'.s:tag_address_part.'\%(;'.s:tag_address_part.'\)*'
|
let chain = '^'.s:tag_address_part.'\%(;'.s:tag_address_part.'\)*'
|
||||||
@@ -570,7 +570,10 @@ function! s:tag_address(rest)
|
|||||||
return address
|
return address
|
||||||
endif
|
endif
|
||||||
let address = matchstr(rest, chain.'\ze;[/?]')
|
let address = matchstr(rest, chain.'\ze;[/?]')
|
||||||
return empty(address) ? matchstr(rest, '^'.s:tag_address_open.'$') : address
|
if !empty(address)
|
||||||
|
return address
|
||||||
|
endif
|
||||||
|
return a:whole ? matchstr(rest, '^'.s:tag_address_open.'$') : ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" [key, [filename, [stay_on_edit: 0]]]
|
" [key, [filename, [stay_on_edit: 0]]]
|
||||||
@@ -768,7 +771,7 @@ function! s:goto_entry(winid, bufnr, dir, kind, entry) abort
|
|||||||
if len(parts) < 3
|
if len(parts) < 3
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let excmd = s:tag_address(join(parts[2:-2], '')[:-2])
|
let excmd = s:tag_address(join(parts[2:-2], '')[:-2], 1)
|
||||||
let relpath = parts[1][:-2]
|
let relpath = parts[1][:-2]
|
||||||
let path = relpath =~ (s:is_win ? '^[A-Z]:\' : '^/')
|
let path = relpath =~ (s:is_win ? '^[A-Z]:\' : '^/')
|
||||||
\ ? relpath : join([fnamemodify(parts[-1], ':h'), relpath], '/')
|
\ ? relpath : join([fnamemodify(parts[-1], ':h'), relpath], '/')
|
||||||
@@ -783,7 +786,7 @@ function! s:goto_entry(winid, bufnr, dir, kind, entry) abort
|
|||||||
if len(parts) < 3 || !bufexists(a:bufnr)
|
if len(parts) < 3 || !bufexists(a:bufnr)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let excmd = s:tag_address(parts[2])
|
let excmd = s:tag_address(parts[2], 0)
|
||||||
if empty(excmd)
|
if empty(excmd)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@@ -1703,7 +1706,7 @@ function! s:btags_sink(from, lines)
|
|||||||
for line in a:lines[1:]
|
for line in a:lines[1:]
|
||||||
try
|
try
|
||||||
let parts = split(line, "\t")
|
let parts = split(line, "\t")
|
||||||
let excmd = s:tag_address(parts[2])
|
let excmd = s:tag_address(parts[2], 0)
|
||||||
if empty(excmd)
|
if empty(excmd)
|
||||||
throw 'Unsupported tag address: '.s:strip(parts[0])
|
throw 'Unsupported tag address: '.s:strip(parts[0])
|
||||||
endif
|
endif
|
||||||
@@ -1786,7 +1789,7 @@ function! s:tags_sink(from, lines)
|
|||||||
for line in list
|
for line in list
|
||||||
try
|
try
|
||||||
let parts = split(line, '\t\zs')
|
let parts = split(line, '\t\zs')
|
||||||
let excmd = s:tag_address(join(parts[2:-2], '')[:-2])
|
let excmd = s:tag_address(join(parts[2:-2], '')[:-2], 1)
|
||||||
if empty(excmd)
|
if empty(excmd)
|
||||||
throw 'Unsupported tag address: '.s:strip(parts[0])
|
throw 'Unsupported tag address: '.s:strip(parts[0])
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in new issue
Block a user