2011-01-11 17:36:49 +08:00
|
|
|
" ============================================================================
|
|
|
|
" File: tagbar.vim
|
|
|
|
" Description: List the current file's tags in a sidebar, ordered by class etc
|
2011-02-16 20:19:24 +08:00
|
|
|
" Author: Jan Larres <jan@majutsushi.net>
|
2011-01-11 17:36:49 +08:00
|
|
|
" Licence: Vim licence
|
2020-09-13 15:07:22 +08:00
|
|
|
" Website: https://preservim.github.io/tagbar
|
2017-01-09 12:26:17 +08:00
|
|
|
" Version: 2.7
|
2011-01-11 17:36:49 +08:00
|
|
|
" Note: This plugin was heavily inspired by the 'Taglist' plugin by
|
2011-02-13 14:20:15 +08:00
|
|
|
" Yegappan Lakshmanan and uses a small amount of code from it.
|
2011-02-14 17:02:44 +08:00
|
|
|
"
|
|
|
|
" Original taglist copyright notice:
|
|
|
|
" Permission is hereby granted to use and distribute this code,
|
|
|
|
" with or without modifications, provided that this copyright
|
|
|
|
" notice is copied with it. Like anything else that's free,
|
|
|
|
" taglist.vim is provided *as is* and comes with no warranty of
|
|
|
|
" any kind, either expressed or implied. In no event will the
|
|
|
|
" copyright holder be liable for any damamges resulting from the
|
|
|
|
" use of this software.
|
2011-01-11 17:36:49 +08:00
|
|
|
" ============================================================================
|
|
|
|
|
2011-07-15 13:34:47 +08:00
|
|
|
scriptencoding utf-8
|
2011-06-18 14:46:04 +08:00
|
|
|
|
2019-10-22 22:08:25 +08:00
|
|
|
if &compatible || exists('g:loaded_tagbar')
|
2011-01-11 17:36:49 +08:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2011-07-03 17:14:56 +08:00
|
|
|
" Basic init {{{1
|
|
|
|
|
2011-11-26 12:45:08 +08:00
|
|
|
if v:version < 700
|
|
|
|
echohl WarningMsg
|
|
|
|
echomsg 'Tagbar: Vim version is too old, Tagbar requires at least 7.0'
|
|
|
|
echohl None
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
if v:version == 700 && !has('patch167')
|
|
|
|
echohl WarningMsg
|
|
|
|
echomsg 'Tagbar: Vim versions lower than 7.0.167 have a bug'
|
|
|
|
\ 'that prevents this version of Tagbar from working.'
|
|
|
|
\ 'Please use the alternate version posted on the website.'
|
|
|
|
echohl None
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2013-08-22 09:16:46 +08:00
|
|
|
function! s:init_var(var, value) abort
|
|
|
|
if !exists('g:tagbar_' . a:var)
|
2013-08-22 13:38:31 +08:00
|
|
|
execute 'let g:tagbar_' . a:var . ' = ' . string(a:value)
|
2013-08-22 09:16:46 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2014-12-10 11:19:14 +08:00
|
|
|
function! s:setup_options() abort
|
2020-07-30 02:18:17 +08:00
|
|
|
if exists('g:tagbar_position')
|
2020-09-01 21:59:16 +08:00
|
|
|
" Map older deprecated values to correct values
|
|
|
|
if g:tagbar_position ==# 'top'
|
|
|
|
let g:tagbar_position = 'leftabove'
|
|
|
|
elseif g:tagbar_position ==# 'bottom'
|
|
|
|
let g:tagbar_position = 'rightbelow'
|
|
|
|
elseif g:tagbar_position ==# 'left'
|
|
|
|
let g:tagbar_position = 'topleft vertical'
|
|
|
|
elseif g:tagbar_position ==# 'right'
|
|
|
|
let g:tagbar_position = 'botright vertical'
|
|
|
|
endif
|
|
|
|
if g:tagbar_position !~# 'vertical'
|
2020-07-30 02:18:17 +08:00
|
|
|
let previewwin_pos = 'rightbelow vertical'
|
2020-09-01 21:59:16 +08:00
|
|
|
else
|
|
|
|
let previewwin_pos = 'topleft'
|
2020-07-30 02:18:17 +08:00
|
|
|
endif
|
|
|
|
let default_pos = g:tagbar_position
|
2014-12-10 11:19:14 +08:00
|
|
|
else
|
2020-07-30 02:18:17 +08:00
|
|
|
if exists('g:tagbar_vertical') && g:tagbar_vertical > 0
|
|
|
|
let previewwin_pos = 'rightbelow vertical'
|
|
|
|
if exists('g:tagbar_left') && g:tagbar_left
|
2020-09-01 21:59:16 +08:00
|
|
|
let default_pos = 'leftabove'
|
2020-07-30 02:18:17 +08:00
|
|
|
else
|
2020-09-01 21:59:16 +08:00
|
|
|
let default_pos = 'rightbelow'
|
2020-07-30 02:18:17 +08:00
|
|
|
endif
|
|
|
|
let g:tagbar_height = g:tagbar_vertical
|
|
|
|
elseif exists('g:tagbar_left') && g:tagbar_left
|
|
|
|
let previewwin_pos = 'topleft'
|
2020-09-01 21:59:16 +08:00
|
|
|
let default_pos = 'topleft vertical'
|
2020-07-30 02:18:17 +08:00
|
|
|
else
|
|
|
|
let previewwin_pos = 'topleft'
|
2020-09-01 21:59:16 +08:00
|
|
|
let default_pos = 'botright vertical'
|
2020-07-30 02:18:17 +08:00
|
|
|
endif
|
2014-12-10 11:19:14 +08:00
|
|
|
endif
|
|
|
|
let options = [
|
|
|
|
\ ['autoclose', 0],
|
|
|
|
\ ['autofocus', 0],
|
|
|
|
\ ['autopreview', 0],
|
|
|
|
\ ['autoshowtag', 0],
|
2016-08-28 06:14:10 +08:00
|
|
|
\ ['case_insensitive', 0],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ['compact', 0],
|
|
|
|
\ ['expand', 0],
|
|
|
|
\ ['foldlevel', 99],
|
|
|
|
\ ['hide_nonpublic', 0],
|
2020-07-30 02:18:17 +08:00
|
|
|
\ ['height', 10],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ['indent', 2],
|
|
|
|
\ ['left', 0],
|
2020-09-01 21:59:16 +08:00
|
|
|
\ ['position', default_pos],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ['previewwin_pos', previewwin_pos],
|
2020-01-03 14:57:46 +08:00
|
|
|
\ ['show_balloon', 1],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ['show_visibility', 1],
|
|
|
|
\ ['show_linenumbers', 0],
|
|
|
|
\ ['singleclick', 0],
|
|
|
|
\ ['sort', 1],
|
|
|
|
\ ['systemenc', &encoding],
|
|
|
|
\ ['vertical', 0],
|
|
|
|
\ ['width', 40],
|
|
|
|
\ ['zoomwidth', 1],
|
2016-02-18 17:01:35 +08:00
|
|
|
\ ['silent', 0],
|
2020-05-30 02:02:31 +08:00
|
|
|
\ ['use_cache', 1],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ]
|
2013-08-22 09:16:46 +08:00
|
|
|
|
2014-12-10 11:19:14 +08:00
|
|
|
for [opt, val] in options
|
|
|
|
call s:init_var(opt, val)
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
call s:setup_options()
|
2011-07-03 17:14:56 +08:00
|
|
|
|
2011-12-22 13:06:48 +08:00
|
|
|
if !exists('g:tagbar_iconchars')
|
2019-10-22 22:08:25 +08:00
|
|
|
if has('multi_byte') && has('unix') && &encoding ==# 'utf-8' &&
|
2020-01-02 13:01:13 +08:00
|
|
|
\ (!exists('+termencoding') || empty(&termencoding) || &termencoding ==# 'utf-8')
|
2011-12-22 13:06:48 +08:00
|
|
|
let g:tagbar_iconchars = ['▶', '▼']
|
|
|
|
else
|
|
|
|
let g:tagbar_iconchars = ['+', '-']
|
|
|
|
endif
|
2011-07-03 17:14:56 +08:00
|
|
|
endif
|
|
|
|
|
2014-12-10 11:19:14 +08:00
|
|
|
function! s:setup_keymaps() abort
|
|
|
|
let keymaps = [
|
|
|
|
\ ['jump', '<CR>'],
|
|
|
|
\ ['preview', 'p'],
|
|
|
|
\ ['previewwin', 'P'],
|
|
|
|
\ ['nexttag', '<C-N>'],
|
|
|
|
\ ['prevtag', '<C-P>'],
|
|
|
|
\ ['showproto', '<Space>'],
|
|
|
|
\ ['hidenonpublic', 'v'],
|
|
|
|
\
|
|
|
|
\ ['openfold', ['+', '<kPlus>', 'zo']],
|
|
|
|
\ ['closefold', ['-', '<kMinus>', 'zc']],
|
|
|
|
\ ['togglefold', ['o', 'za']],
|
|
|
|
\ ['openallfolds', ['*', '<kMultiply>', 'zR']],
|
|
|
|
\ ['closeallfolds', ['=', 'zM']],
|
2017-07-26 22:18:18 +08:00
|
|
|
\ ['incrementfolds', ['zr']],
|
|
|
|
\ ['decrementfolds', ['zm']],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ['nextfold', 'zj'],
|
|
|
|
\ ['prevfold', 'zk'],
|
|
|
|
\
|
2016-08-28 06:14:10 +08:00
|
|
|
\ ['togglesort', 's'],
|
|
|
|
\ ['togglecaseinsensitive', 'i'],
|
|
|
|
\ ['toggleautoclose', 'c'],
|
2018-06-15 16:27:33 +08:00
|
|
|
\ ['togglepause', 't'],
|
2016-08-28 06:14:10 +08:00
|
|
|
\ ['zoomwin', 'x'],
|
|
|
|
\ ['close', 'q'],
|
|
|
|
\ ['help', ['<F1>', '?']],
|
2014-12-10 11:19:14 +08:00
|
|
|
\ ]
|
2013-08-22 13:38:31 +08:00
|
|
|
|
2014-12-10 11:19:14 +08:00
|
|
|
for [map, key] in keymaps
|
|
|
|
call s:init_var('map_' . map, key)
|
|
|
|
unlet key
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
call s:setup_keymaps()
|
2013-08-22 13:38:31 +08:00
|
|
|
|
2011-07-15 13:34:47 +08:00
|
|
|
augroup TagbarSession
|
|
|
|
autocmd!
|
|
|
|
autocmd SessionLoadPost * nested call tagbar#RestoreSession()
|
|
|
|
augroup END
|
2011-07-03 17:14:56 +08:00
|
|
|
|
2011-01-24 17:37:52 +08:00
|
|
|
" Commands {{{1
|
2013-06-25 14:12:25 +08:00
|
|
|
command! -nargs=0 Tagbar call tagbar#ToggleWindow()
|
2011-06-29 04:59:49 +08:00
|
|
|
command! -nargs=0 TagbarToggle call tagbar#ToggleWindow()
|
2011-11-23 14:56:31 +08:00
|
|
|
command! -nargs=? TagbarOpen call tagbar#OpenWindow(<f-args>)
|
2012-07-31 12:42:18 +08:00
|
|
|
command! -nargs=0 TagbarOpenAutoClose call tagbar#OpenWindow('fcj')
|
2011-06-29 04:59:49 +08:00
|
|
|
command! -nargs=0 TagbarClose call tagbar#CloseWindow()
|
2012-03-14 17:41:39 +08:00
|
|
|
command! -nargs=1 -bang TagbarSetFoldlevel call tagbar#SetFoldLevel(<args>, <bang>0)
|
2012-09-15 12:49:28 +08:00
|
|
|
command! -nargs=0 TagbarShowTag call tagbar#highlighttag(1, 1)
|
2012-09-15 13:03:38 +08:00
|
|
|
command! -nargs=? TagbarCurrentTag echo tagbar#currenttag('%s', 'No current tag', <f-args>)
|
2012-06-16 17:46:54 +08:00
|
|
|
command! -nargs=1 TagbarGetTypeConfig call tagbar#gettypeconfig(<f-args>)
|
2017-08-20 13:02:36 +08:00
|
|
|
command! -nargs=? TagbarDebug call tagbar#debug#start_debug(<f-args>)
|
|
|
|
command! -nargs=0 TagbarDebugEnd call tagbar#debug#stop_debug()
|
2013-11-06 17:33:27 +08:00
|
|
|
command! -nargs=0 TagbarTogglePause call tagbar#toggle_pause()
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-24 17:37:52 +08:00
|
|
|
" Modeline {{{1
|
2011-07-15 13:34:47 +08:00
|
|
|
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1
|