/_dir/vim/bundle/tagbar/plugin/tagbar.vim

https://github.com/joshuamorse/dotfiles · Vim Script · 149 lines · 112 code · 14 blank · 23 comment · 19 complexity · 11f4acffb0821113b25d20fd54179cd2 MD5 · raw file

  1. " ============================================================================
  2. " File: tagbar.vim
  3. " Description: List the current file's tags in a sidebar, ordered by class etc
  4. " Author: Jan Larres <jan@majutsushi.net>
  5. " Licence: Vim licence
  6. " Website: http://majutsushi.github.com/tagbar/
  7. " Version: 2.7
  8. " Note: This plugin was heavily inspired by the 'Taglist' plugin by
  9. " Yegappan Lakshmanan and uses a small amount of code from it.
  10. "
  11. " Original taglist copyright notice:
  12. " Permission is hereby granted to use and distribute this code,
  13. " with or without modifications, provided that this copyright
  14. " notice is copied with it. Like anything else that's free,
  15. " taglist.vim is provided *as is* and comes with no warranty of
  16. " any kind, either expressed or implied. In no event will the
  17. " copyright holder be liable for any damamges resulting from the
  18. " use of this software.
  19. " ============================================================================
  20. scriptencoding utf-8
  21. if &cp || exists('g:loaded_tagbar')
  22. finish
  23. endif
  24. " Basic init {{{1
  25. if v:version < 700
  26. echohl WarningMsg
  27. echomsg 'Tagbar: Vim version is too old, Tagbar requires at least 7.0'
  28. echohl None
  29. finish
  30. endif
  31. if v:version == 700 && !has('patch167')
  32. echohl WarningMsg
  33. echomsg 'Tagbar: Vim versions lower than 7.0.167 have a bug'
  34. \ 'that prevents this version of Tagbar from working.'
  35. \ 'Please use the alternate version posted on the website.'
  36. echohl None
  37. finish
  38. endif
  39. function! s:init_var(var, value) abort
  40. if !exists('g:tagbar_' . a:var)
  41. execute 'let g:tagbar_' . a:var . ' = ' . string(a:value)
  42. endif
  43. endfunction
  44. function! s:setup_options() abort
  45. if !exists('g:tagbar_vertical') || g:tagbar_vertical == 0
  46. let previewwin_pos = 'topleft'
  47. else
  48. let previewwin_pos = 'rightbelow vertical'
  49. endif
  50. let options = [
  51. \ ['autoclose', 0],
  52. \ ['autofocus', 0],
  53. \ ['autopreview', 0],
  54. \ ['autoshowtag', 0],
  55. \ ['case_insensitive', 0],
  56. \ ['compact', 0],
  57. \ ['expand', 0],
  58. \ ['foldlevel', 99],
  59. \ ['hide_nonpublic', 0],
  60. \ ['indent', 2],
  61. \ ['left', 0],
  62. \ ['previewwin_pos', previewwin_pos],
  63. \ ['show_visibility', 1],
  64. \ ['show_linenumbers', 0],
  65. \ ['singleclick', 0],
  66. \ ['sort', 1],
  67. \ ['systemenc', &encoding],
  68. \ ['vertical', 0],
  69. \ ['width', 40],
  70. \ ['zoomwidth', 1],
  71. \ ['silent', 0],
  72. \ ]
  73. for [opt, val] in options
  74. call s:init_var(opt, val)
  75. endfor
  76. endfunction
  77. call s:setup_options()
  78. if !exists('g:tagbar_iconchars')
  79. if has('multi_byte') && has('unix') && &encoding == 'utf-8' &&
  80. \ (empty(&termencoding) || &termencoding == 'utf-8')
  81. let g:tagbar_iconchars = ['▶', '▼']
  82. else
  83. let g:tagbar_iconchars = ['+', '-']
  84. endif
  85. endif
  86. function! s:setup_keymaps() abort
  87. let keymaps = [
  88. \ ['jump', '<CR>'],
  89. \ ['preview', 'p'],
  90. \ ['previewwin', 'P'],
  91. \ ['nexttag', '<C-N>'],
  92. \ ['prevtag', '<C-P>'],
  93. \ ['showproto', '<Space>'],
  94. \ ['hidenonpublic', 'v'],
  95. \
  96. \ ['openfold', ['+', '<kPlus>', 'zo']],
  97. \ ['closefold', ['-', '<kMinus>', 'zc']],
  98. \ ['togglefold', ['o', 'za']],
  99. \ ['openallfolds', ['*', '<kMultiply>', 'zR']],
  100. \ ['closeallfolds', ['=', 'zM']],
  101. \ ['nextfold', 'zj'],
  102. \ ['prevfold', 'zk'],
  103. \
  104. \ ['togglesort', 's'],
  105. \ ['togglecaseinsensitive', 'i'],
  106. \ ['toggleautoclose', 'c'],
  107. \ ['zoomwin', 'x'],
  108. \ ['close', 'q'],
  109. \ ['help', ['<F1>', '?']],
  110. \ ]
  111. for [map, key] in keymaps
  112. call s:init_var('map_' . map, key)
  113. unlet key
  114. endfor
  115. endfunction
  116. call s:setup_keymaps()
  117. augroup TagbarSession
  118. autocmd!
  119. autocmd SessionLoadPost * nested call tagbar#RestoreSession()
  120. augroup END
  121. " Commands {{{1
  122. command! -nargs=0 Tagbar call tagbar#ToggleWindow()
  123. command! -nargs=0 TagbarToggle call tagbar#ToggleWindow()
  124. command! -nargs=? TagbarOpen call tagbar#OpenWindow(<f-args>)
  125. command! -nargs=0 TagbarOpenAutoClose call tagbar#OpenWindow('fcj')
  126. command! -nargs=0 TagbarClose call tagbar#CloseWindow()
  127. command! -nargs=1 -bang TagbarSetFoldlevel call tagbar#SetFoldLevel(<args>, <bang>0)
  128. command! -nargs=0 TagbarShowTag call tagbar#highlighttag(1, 1)
  129. command! -nargs=? TagbarCurrentTag echo tagbar#currenttag('%s', 'No current tag', <f-args>)
  130. command! -nargs=1 TagbarGetTypeConfig call tagbar#gettypeconfig(<f-args>)
  131. command! -nargs=? TagbarDebug call tagbar#StartDebug(<f-args>)
  132. command! -nargs=0 TagbarDebugEnd call tagbar#StopDebug()
  133. command! -nargs=0 TagbarTogglePause call tagbar#toggle_pause()
  134. " Modeline {{{1
  135. " vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1