aboutsummaryrefslogtreecommitdiff
path: root/.vim/plugin/util.vim
blob: de2dadd3f1504e9e193e5b1ef05eb8c646650384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function! PushTagStackOnCommand(command_name) abort
    call s:PushTagStackBefore()
    exec a:command_name
    call s:PushTagStackAfter()
endfunction

function! PushTagStackOnFunction(function_name) abort
    call s:PushTagStackBefore()
    call a:function_name()
    call s:PushTagStackAfter()
endfunction

function! s:PushTagStackBefore() abort
    let dotag = &tagstack && exists('*gettagstack') && exists('*settagstack')
    if dotag
        let from = [bufnr('%'), line('.'), col('.'), 0]
        let tagname = expand('<cword>')
        let stack = gettagstack()
        if stack.curidx > 1
            let stack.items = stack.items[0:stack.curidx-2]
        else
            let stack.items = []
        endif
        let stack.items += [{'from': from, 'tagname': tagname}]
        let stack.curidx = len(stack.items)
        call settagstack(win_getid(), stack)
    endif
endfunction

function! s:PushTagStackAfter() abort
    let dotag = &tagstack && exists('*gettagstack') && exists('*settagstack')
    if dotag
        let curidx = gettagstack().curidx + 1
        call settagstack(win_getid(), {'curidx': curidx})
    endif
endfunction