" ============================================================================ " File: tagbar.vim " Description: List the current file's tags in a sidebar, ordered by class etc " Maintainer: Jan Larres " Licence: Vim licence " Website: http://github.com/majutsushi/tagbar " Note: This plugin was heavily inspired by the 'Taglist' plugin by " Yegappan Lakshamanan and uses some small portions of code from " it. " ============================================================================ if &cp || exists('g:loaded_tagbar') finish endif if !exists('*system') echomsg 'Tagbar: No system() function available, skipping plugin' finish endif if !exists('g:tagbar_ctags_bin') if executable('ctags-exuberant') let g:tagbar_ctags_bin = 'ctags-exuberant' elseif executable('exctags') let g:tagbar_ctags_bin = 'exctags' elseif executable('ctags') let g:tagbar_ctags_bin = 'ctags' elseif executable('ctags.exe') let g:tagbar_ctags_bin = 'ctags.exe' elseif executable('tags') let g:tagbar_ctags_bin = 'tags' else echomsg 'Tagbar: Exuberant ctags not found, skipping plugin' finish endif endif let g:loaded_tagbar = 1 if !exists('g:tagbar_left') let g:tagbar_left = 0 endif if !exists('g:tagbar_width') let g:tagbar_width = 40 endif if !exists('g:tagbar_types') let g:tagbar_types = {} endif if !exists('g:tagbar_autoclose') let g:tagbar_autoclose = 0 endif if !exists('g:tagbar_sort') let g:tagbar_sort = 1 endif function! s:InitTypes() " Dictionary of the already processed files, indexed by file name with " complete path. " The entries are again dictionaries with the following fields: " - mtime: File modification time " - ftype: The vim file type " - tags: List of the tags that are present in the file, sorted " according to the value of 'g:tagbar_sort' " - fline: Dictionary of the tags, indexed by line number in the file " - tline: Dictionary of the tags, indexed by line number in the tagbar let s:known_files = {} let s:known_types = {} let type_cpp = {} let type_cpp.ctagstype = 'c++' let type_cpp.scopes = [ \ 'namespace', \ 'class', \ 'struct', \ 'enum', \ 'union' \ ] let type_cpp.sro = '::' let type_cpp.kinds = [ \ 'd:macros', \ 'n:namespaces', \ 'c:classes', \ 's:structs', \ 'g:enum', \ 'e:enumerators', \ 'u:unions', \ 't:typedefs', \ 'p:prototypes', \ 'f:functions', \ 'm:members', \ 'v:variables' \ ] let type_cpp.kind2scope = { \ 'n' : 'namespace', \ 'c' : 'class', \ 's' : 'struct', \ 'g' : 'enum', \ 'u' : 'union' \ } let type_cpp.scope2kind = { \ 'namespace' : 'n', \ 'class' : 'c', \ 'struct' : 's', \ 'enum' : 'g', \ 'union' : 'u' \ } let s:known_types.cpp = type_cpp let type_python = {} let type_python.ctagstype = 'python' let type_python.scopes = ['class', 'function'] let type_python.sro = '.' let type_python.kinds = [ \ 'i:imports', \ 'c:classes', \ 'f:functions', \ 'm:members', \ 'v:variables' \ ] let type_python.kind2scope = { \ 'c' : 'class', \ 'f' : 'function', \ 'm' : 'function' \ } let type_python.scope2kind = { \ 'class' : 'c', \ 'function' : 'f' \ } let s:known_types.python = type_python call extend(s:known_types, g:tagbar_types) " Create a dictionary of the kind order for fast " access in sorting functions for type in values(s:known_types) let i = 0 let type.kinddict = {} for kind in type.kinds let type.kinddict[kind[0]] = i let i += 1 endfor endfor endfunction call s:InitTypes() function! s:ToggleWindow() let tagbarwinnr = bufwinnr("__Tagbar__") if tagbarwinnr != -1 call s:CloseWindow() return endif call s:OpenWindow() endfunction function! s:OpenWindow() " If the tagbar window is already open jump to it let tagbarwinnr = bufwinnr('__Tagbar__') if tagbarwinnr != -1 && winnr() != tagbarwinnr execute tagbarwinnr . 'wincmd w' return endif let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical ' exe 'silent! keepalt ' . openpos . g:tagbar_width . 'split ' . '__Tagbar__' setlocal noreadonly " in case the "view" mode is used setlocal buftype=nofile setlocal bufhidden=hide setlocal noswapfile setlocal nobuflisted setlocal nomodifiable setlocal filetype=tagbar setlocal nolist setlocal nonumber setlocal nowrap setlocal winfixwidth if exists('+relativenumber') setlocal norelativenumber endif setlocal foldenable setlocal foldminlines=0 setlocal foldmethod=manual setlocal foldlevel=9999 setlocal foldcolumn=1 setlocal foldtext=v:folddashes.getline(v:foldstart) " Variable for saving the current file for functions that are called from " the tagbar window let s:current_file = '' " Script-local variable needed since compare functions can't " take extra arguments let s:compare_typeinfo = {} let s:is_maximized = 0 let s:short_help = 1 syntax match Comment '^" .*' " Comments syntax match Identifier '^[^: ]\+$' " Non-scoped kinds syntax match Title '[^:(* ]\+\ze\*\? :' " Scope names syntax match Type ': \zs.*' " Scope types syntax match SpecialKey '(.*)' " Signatures syntax match NonText '\*\ze :' " Pseudo-tag identifiers if has('balloon_eval') setlocal balloonexpr=TagbarBalloonExpr() set ballooneval endif let cpoptions_save = &cpoptions set cpoptions&vim nnoremap