aboutsummaryrefslogtreecommitdiff
path: root/.vim/plugin
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2022-04-08 00:42:37 +0800
committerGuangxiong Lin <[email protected]>2022-04-08 00:42:37 +0800
commit40e266a131d8bfc9f2f48c5e40846436a9c9e64f (patch)
tree7cccdb62d99552e028ed8daa66fe463469e441a8 /.vim/plugin
parentcb8f83dd1106515a76eeb4d7d87fabbbb98f67ca (diff)
downloaddotfiles-40e266a131d8bfc9f2f48c5e40846436a9c9e64f.tar.gz
dotfiles-40e266a131d8bfc9f2f48c5e40846436a9c9e64f.tar.bz2
dotfiles-40e266a131d8bfc9f2f48c5e40846436a9c9e64f.zip
Use tagstack for ycm (vim)
Diffstat (limited to '.vim/plugin')
-rw-r--r--.vim/plugin/util.vim36
1 files changed, 36 insertions, 0 deletions
diff --git a/.vim/plugin/util.vim b/.vim/plugin/util.vim
new file mode 100644
index 0000000..de2dadd
--- /dev/null
+++ b/.vim/plugin/util.vim
@@ -0,0 +1,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