Update tag stack after BTags and Tags commands

Let CTRL-T function just as after builtin tag jumps.

Close #240
This commit is contained in:
Pavol Juhas
2026-09-06 23:51:12 +09:00
committed by Junegunn Choi
parent 88104829b1
commit dfeb973a54
+43 -5
View File
@@ -1613,18 +1613,46 @@ function! s:btags_source(tag_cmds)
return map(s:align_lists(map(lines, 'split(v:val, "\t")')), 'join(v:val, "\t")')
endfunction
function! s:btags_sink(lines)
" Position to return to with CTRL-T. Captured before fzf opens, because the
" show key can move the window before the sink runs
function! s:current_position()
let pos = getpos('.')
let pos[0] = bufnr('')
return pos
endfunction
function! s:end_tagstack_with(tagname, from_position)
" Builtin tag jumps push nothing when 'tagstack' is off
if !&tagstack || !exists('*settagstack')
return
endif
let winid = win_getid()
let stack = gettagstack(winid)
let item = {
\ 'bufnr': a:from_position[0],
\ 'from': a:from_position,
\ 'tagname': a:tagname}
let stack['items'] = [item]
return settagstack(winid, stack, 't')
endfunction
function! s:btags_sink(from, lines)
if len(a:lines) < 2
return
endif
if s:is_paste(a:lines)
return fzf#vim#paste(map(a:lines[1:], 's:strip(split(v:val, "\t")[0])'))
endif
let tagname = ''
call s:action_for(a:lines[0])
let qfl = []
for line in a:lines[1:]
call s:execute_silent(split(line, "\t")[2])
let parts = split(line, "\t")
call s:execute_silent(parts[2])
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
if empty(tagname)
let tagname = s:strip(parts[0])
endif
endfor
if len(qfl) > 1
@@ -1635,6 +1663,9 @@ function! s:btags_sink(lines)
else
normal! zvzz
endif
if !empty(tagname)
call s:end_tagstack_with(tagname, a:from)
endif
endfunction
" query, [tag commands], [spec (dict)], [fullscreen (bool)]
@@ -1652,7 +1683,7 @@ function! fzf#vim#buffer_tags(query, ...)
try
return s:fzf('btags', {
\ 'source': s:btags_source(tag_cmds),
\ 'sink*': s:function('s:btags_sink'),
\ 'sink*': function(s:function('s:btags_sink'), [s:current_position()]),
\ '_show': 'btags',
\ '_hint': [],
\ '_paste': 1,
@@ -1665,7 +1696,7 @@ endfunction
" ------------------------------------------------------------------
" Tags
" ------------------------------------------------------------------
function! s:tags_sink(lines)
function! s:tags_sink(from, lines)
if len(a:lines) < 2
return
endif
@@ -1677,6 +1708,7 @@ function! s:tags_sink(lines)
" Remember the current position
let buf = bufnr('')
let view = winsaveview()
let tagname = ''
let qfl = []
let [key; list] = a:lines
@@ -1698,6 +1730,9 @@ function! s:tags_sink(lines)
endif
call s:execute_silent(excmd)
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
if empty(tagname)
let tagname = s:strip(parts[0])
endif
catch /^Vim:Interrupt$/
break
catch
@@ -1722,6 +1757,9 @@ function! s:tags_sink(lines)
else
normal! ^zvzz
endif
if !empty(tagname)
call s:end_tagstack_with(tagname, a:from)
endif
endfunction
function! fzf#vim#tags(query, ...)
@@ -1763,7 +1801,7 @@ function! fzf#vim#tags(query, ...)
let args = insert(map(tagfiles, 'fzf#shellescape(fnamemodify(v:val, ":p"))'), fzf#shellescape(a:query), 0)
return s:fzf('tags', {
\ 'source': join(['perl', fzf#shellescape(s:bin.tags), join(args)]),
\ 'sink*': s:function('s:tags_sink'),
\ 'sink*': function(s:function('s:tags_sink'), [s:current_position()]),
\ '_show': 'tags',
\ '_hint': [],
\ '_paste': 1,