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
|
2011-02-20 06:04:09 +08:00
|
|
|
" Website: http://majutsushi.github.com/tagbar/
|
2011-05-29 15:19:03 +08:00
|
|
|
" Version: 2.1
|
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
|
|
|
" ============================================================================
|
|
|
|
|
|
|
|
if &cp || exists('g:loaded_tagbar')
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2011-01-24 17:37:52 +08:00
|
|
|
" Initialization {{{1
|
2011-04-25 12:09:40 +08:00
|
|
|
|
|
|
|
" Basic init {{{2
|
2011-05-18 21:42:18 +08:00
|
|
|
|
|
|
|
if v:version < 700
|
|
|
|
echomsg 'Tagbar: Vim version is too old, Tagbar requires at least 7.0'
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2011-01-16 19:41:41 +08:00
|
|
|
if !exists('g:tagbar_ctags_bin')
|
|
|
|
if executable('ctags-exuberant')
|
|
|
|
let g:tagbar_ctags_bin = 'ctags-exuberant'
|
2011-05-07 14:06:29 +08:00
|
|
|
elseif executable('exuberant-ctags')
|
|
|
|
let g:tagbar_ctags_bin = 'exuberant-ctags'
|
2011-01-11 17:36:49 +08:00
|
|
|
elseif executable('exctags')
|
2011-01-16 19:41:41 +08:00
|
|
|
let g:tagbar_ctags_bin = 'exctags'
|
2011-01-11 17:36:49 +08:00
|
|
|
elseif executable('ctags')
|
2011-01-16 19:41:41 +08:00
|
|
|
let g:tagbar_ctags_bin = 'ctags'
|
2011-01-11 17:36:49 +08:00
|
|
|
elseif executable('ctags.exe')
|
2011-01-16 19:41:41 +08:00
|
|
|
let g:tagbar_ctags_bin = 'ctags.exe'
|
2011-01-11 17:36:49 +08:00
|
|
|
elseif executable('tags')
|
2011-01-16 19:41:41 +08:00
|
|
|
let g:tagbar_ctags_bin = 'tags'
|
2011-01-11 17:36:49 +08:00
|
|
|
else
|
|
|
|
echomsg 'Tagbar: Exuberant ctags not found, skipping plugin'
|
|
|
|
finish
|
|
|
|
endif
|
2011-03-28 07:34:41 +08:00
|
|
|
else
|
|
|
|
let g:tagbar_ctags_bin = expand(g:tagbar_ctags_bin)
|
|
|
|
if !executable(g:tagbar_ctags_bin)
|
|
|
|
echomsg 'Tagbar: Exuberant ctags not found in specified place,'
|
|
|
|
\ 'skipping plugin'
|
|
|
|
finish
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
endif
|
|
|
|
|
2011-05-07 14:13:00 +08:00
|
|
|
redir => s:ftype_out
|
|
|
|
silent filetype
|
|
|
|
redir END
|
|
|
|
if s:ftype_out !~# 'detection:ON'
|
|
|
|
echomsg 'Tagbar: Filetype detection is turned off, skipping plugin'
|
|
|
|
unlet s:ftype_out
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
unlet s:ftype_out
|
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
let g:loaded_tagbar = 1
|
|
|
|
|
|
|
|
if !exists('g:tagbar_left')
|
|
|
|
let g:tagbar_left = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:tagbar_width')
|
2011-01-14 18:12:26 +08:00
|
|
|
let g:tagbar_width = 40
|
2011-01-11 17:36:49 +08:00
|
|
|
endif
|
|
|
|
|
2011-01-12 18:30:38 +08:00
|
|
|
if !exists('g:tagbar_autoclose')
|
|
|
|
let g:tagbar_autoclose = 0
|
|
|
|
endif
|
|
|
|
|
2011-03-04 05:55:00 +08:00
|
|
|
if !exists('g:tagbar_autofocus')
|
|
|
|
let g:tagbar_autofocus = 0
|
|
|
|
endif
|
|
|
|
|
2011-01-17 12:08:10 +08:00
|
|
|
if !exists('g:tagbar_sort')
|
|
|
|
let g:tagbar_sort = 1
|
|
|
|
endif
|
|
|
|
|
2011-02-14 11:11:59 +08:00
|
|
|
if !exists('g:tagbar_compact')
|
|
|
|
let g:tagbar_compact = 0
|
|
|
|
endif
|
|
|
|
|
2011-02-26 15:51:15 +08:00
|
|
|
if !exists('g:tagbar_expand')
|
|
|
|
let g:tagbar_expand = 0
|
|
|
|
endif
|
|
|
|
|
2011-06-06 14:42:35 +08:00
|
|
|
if !exists('g:tagbar_singleclick')
|
|
|
|
let g:tagbar_singleclick = 0
|
|
|
|
endif
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
if !exists('g:tagbar_foldlevel')
|
|
|
|
let g:tagbar_foldlevel = 99
|
|
|
|
endif
|
|
|
|
|
2011-03-28 18:02:29 +08:00
|
|
|
if !exists('g:tagbar_usearrows')
|
|
|
|
let g:tagbar_usearrows = 0
|
|
|
|
endif
|
|
|
|
|
2011-04-24 18:53:07 +08:00
|
|
|
if !exists('g:tagbar_autoshowtag')
|
|
|
|
let g:tagbar_autoshowtag = 0
|
|
|
|
endif
|
2011-03-28 18:02:29 +08:00
|
|
|
|
2011-05-05 17:27:47 +08:00
|
|
|
if !exists('g:tagbar_systemenc')
|
|
|
|
let g:tagbar_systemenc = &encoding
|
|
|
|
endif
|
|
|
|
|
2011-03-28 21:16:48 +08:00
|
|
|
if has('multi_byte') && has('unix') && &encoding == 'utf-8' &&
|
|
|
|
\ (empty(&termencoding) || &termencoding == 'utf-8')
|
|
|
|
let s:icon_closed = '▶'
|
|
|
|
let s:icon_open = '▼'
|
|
|
|
elseif has('multi_byte') && (has('win32') || has('win64')) && g:tagbar_usearrows
|
|
|
|
let s:icon_closed = '▷'
|
|
|
|
let s:icon_open = '◢'
|
2011-03-27 20:29:25 +08:00
|
|
|
else
|
|
|
|
let s:icon_closed = '+'
|
|
|
|
let s:icon_open = '-'
|
|
|
|
endif
|
|
|
|
|
2011-02-19 12:32:49 +08:00
|
|
|
let s:type_init_done = 0
|
|
|
|
let s:autocommands_done = 0
|
2011-05-12 16:50:14 +08:00
|
|
|
let s:checked_ctags = 0
|
2011-02-26 15:51:15 +08:00
|
|
|
let s:window_expanded = 0
|
2011-01-23 11:47:44 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let s:access_symbols = {
|
|
|
|
\ 'public' : '+',
|
|
|
|
\ 'protected' : '#',
|
|
|
|
\ 'private' : '-'
|
|
|
|
\ }
|
|
|
|
|
2011-05-25 11:18:26 +08:00
|
|
|
autocmd SessionLoadPost * nested call s:RestoreSession()
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:InitTypes() {{{2
|
2011-01-12 17:48:04 +08:00
|
|
|
function! s:InitTypes()
|
|
|
|
let s:known_types = {}
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" Ant {{{3
|
2011-01-25 14:32:30 +08:00
|
|
|
let type_ant = {}
|
|
|
|
let type_ant.ctagstype = 'ant'
|
|
|
|
let type_ant.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'projects', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'targets', 'fold' : 0}
|
2011-01-25 14:32:30 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.ant = type_ant
|
2011-02-14 18:47:18 +08:00
|
|
|
" Asm {{{3
|
2011-01-25 15:12:57 +08:00
|
|
|
let type_asm = {}
|
|
|
|
let type_asm.ctagstype = 'asm'
|
|
|
|
let type_asm.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'macros', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'types', 'fold' : 0},
|
|
|
|
\ {'short' : 'd', 'long' : 'defines', 'fold' : 0},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0}
|
2011-01-25 15:12:57 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.asm = type_asm
|
2011-02-14 18:47:18 +08:00
|
|
|
" ASP {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_aspvbs = {}
|
|
|
|
let type_aspvbs.ctagstype = 'asp'
|
|
|
|
let type_aspvbs.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'constants', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.aspvbs = type_aspvbs
|
2011-02-14 18:47:18 +08:00
|
|
|
" Awk {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_awk = {}
|
|
|
|
let type_awk.ctagstype = 'awk'
|
|
|
|
let type_awk.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.awk = type_awk
|
2011-02-14 18:47:18 +08:00
|
|
|
" Basic {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_basic = {}
|
|
|
|
let type_basic.ctagstype = 'basic'
|
|
|
|
let type_basic.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enumerations', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'types', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.basic = type_basic
|
2011-02-14 18:47:18 +08:00
|
|
|
" BETA {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_beta = {}
|
|
|
|
let type_beta.ctagstype = 'beta'
|
|
|
|
let type_beta.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'fragments', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'slots', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'patterns', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.beta = type_beta
|
2011-02-14 18:47:18 +08:00
|
|
|
" C {{{3
|
2011-01-24 18:23:40 +08:00
|
|
|
let type_c = {}
|
|
|
|
let type_c.ctagstype = 'c'
|
|
|
|
let type_c.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'prototypes', 'fold' : 1},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'typedefs', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'structs', 'fold' : 0},
|
|
|
|
\ {'short' : 'u', 'long' : 'unions', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-01-24 18:23:40 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_c.sro = '::'
|
2011-01-24 18:23:40 +08:00
|
|
|
let type_c.kind2scope = {
|
|
|
|
\ 'g' : 'enum',
|
|
|
|
\ 's' : 'struct',
|
|
|
|
\ 'u' : 'union'
|
|
|
|
\ }
|
|
|
|
let type_c.scope2kind = {
|
|
|
|
\ 'enum' : 'g',
|
|
|
|
\ 'struct' : 's',
|
|
|
|
\ 'union' : 'u'
|
|
|
|
\ }
|
|
|
|
let s:known_types.c = type_c
|
2011-02-14 18:47:18 +08:00
|
|
|
" C++ {{{3
|
2011-01-12 17:48:04 +08:00
|
|
|
let type_cpp = {}
|
|
|
|
let type_cpp.ctagstype = 'c++'
|
|
|
|
let type_cpp.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'prototypes', 'fold' : 1},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'typedefs', 'fold' : 0},
|
|
|
|
\ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'structs', 'fold' : 0},
|
|
|
|
\ {'short' : 'u', 'long' : 'unions', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}
|
2011-01-14 18:12:26 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_cpp.sro = '::'
|
2011-01-16 12:46:14 +08:00
|
|
|
let type_cpp.kind2scope = {
|
2011-01-24 18:23:40 +08:00
|
|
|
\ 'g' : 'enum',
|
2011-01-16 12:46:14 +08:00
|
|
|
\ 'n' : 'namespace',
|
|
|
|
\ 'c' : 'class',
|
2011-01-20 20:38:14 +08:00
|
|
|
\ 's' : 'struct',
|
|
|
|
\ 'u' : 'union'
|
2011-01-16 12:46:14 +08:00
|
|
|
\ }
|
2011-01-17 17:58:31 +08:00
|
|
|
let type_cpp.scope2kind = {
|
2011-01-24 18:23:40 +08:00
|
|
|
\ 'enum' : 'g',
|
2011-01-17 17:58:31 +08:00
|
|
|
\ 'namespace' : 'n',
|
|
|
|
\ 'class' : 'c',
|
2011-01-20 20:38:14 +08:00
|
|
|
\ 'struct' : 's',
|
|
|
|
\ 'union' : 'u'
|
2011-01-17 17:58:31 +08:00
|
|
|
\ }
|
2011-01-12 17:48:04 +08:00
|
|
|
let s:known_types.cpp = type_cpp
|
2011-02-14 18:47:18 +08:00
|
|
|
" C# {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_cs = {}
|
|
|
|
let type_cs.ctagstype = 'c#'
|
|
|
|
let type_cs.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'fields', 'fold' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'typedefs', 'fold' : 0},
|
|
|
|
\ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0},
|
|
|
|
\ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'structs', 'fold' : 0},
|
|
|
|
\ {'short' : 'E', 'long' : 'events', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'properties', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_cs.sro = '.'
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_cs.kind2scope = {
|
|
|
|
\ 'n' : 'namespace',
|
|
|
|
\ 'i' : 'interface',
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 's' : 'struct',
|
|
|
|
\ 'g' : 'enum'
|
|
|
|
\ }
|
|
|
|
let type_cs.scope2kind = {
|
|
|
|
\ 'namespace' : 'n',
|
|
|
|
\ 'interface' : 'i',
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'struct' : 's',
|
|
|
|
\ 'enum' : 'g'
|
|
|
|
\ }
|
|
|
|
let s:known_types.cs = type_cs
|
2011-02-14 18:47:18 +08:00
|
|
|
" COBOL {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_cobol = {}
|
|
|
|
let type_cobol.ctagstype = 'cobol'
|
|
|
|
let type_cobol.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'data items', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'file descriptions', 'fold' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'group items', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'paragraphs', 'fold' : 0},
|
|
|
|
\ {'short' : 'P', 'long' : 'program ids', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'sections', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.cobol = type_cobol
|
2011-02-14 18:47:18 +08:00
|
|
|
" DOS Batch {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_dosbatch = {}
|
|
|
|
let type_dosbatch.ctagstype = 'dosbatch'
|
|
|
|
let type_dosbatch.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.dosbatch = type_dosbatch
|
2011-02-14 18:47:18 +08:00
|
|
|
" Eiffel {{{3
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_eiffel = {}
|
|
|
|
let type_eiffel.ctagstype = 'eiffel'
|
|
|
|
let type_eiffel.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'features', 'fold' : 0}
|
2011-01-26 14:17:09 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_eiffel.sro = '.' " Not sure, is nesting even possible?
|
2011-01-26 14:17:09 +08:00
|
|
|
let type_eiffel.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'f' : 'feature'
|
|
|
|
\ }
|
|
|
|
let type_eiffel.scope2kind = {
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'feature' : 'f'
|
|
|
|
\ }
|
|
|
|
let s:known_types.eiffel = type_eiffel
|
2011-02-14 18:47:18 +08:00
|
|
|
" Erlang {{{3
|
2011-02-04 13:29:34 +08:00
|
|
|
let type_erlang = {}
|
|
|
|
let type_erlang.ctagstype = 'erlang'
|
|
|
|
let type_erlang.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0},
|
|
|
|
\ {'short' : 'd', 'long' : 'macro definitions', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'r', 'long' : 'record definitions', 'fold' : 0}
|
2011-02-04 13:29:34 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_erlang.sro = '.' " Not sure, is nesting even possible?
|
2011-02-04 13:29:34 +08:00
|
|
|
let type_erlang.kind2scope = {
|
|
|
|
\ 'm' : 'module'
|
|
|
|
\ }
|
|
|
|
let type_erlang.scope2kind = {
|
|
|
|
\ 'module' : 'm'
|
|
|
|
\ }
|
|
|
|
let s:known_types.erlang = type_erlang
|
2011-02-14 18:47:18 +08:00
|
|
|
" Flex {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
" Vim doesn't support Flex out of the box, this is based on rough
|
|
|
|
" guesses and probably requires
|
|
|
|
" http://www.vim.org/scripts/script.php?script_id=2909
|
|
|
|
" Improvements welcome!
|
|
|
|
let type_mxml = {}
|
|
|
|
let type_mxml.ctagstype = 'flex'
|
|
|
|
let type_mxml.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'v', 'long' : 'global variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'properties', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'x', 'long' : 'mxtags', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_mxml.sro = '.'
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_mxml.kind2scope = {
|
|
|
|
\ 'c' : 'class'
|
|
|
|
\ }
|
|
|
|
let type_mxml.scope2kind = {
|
|
|
|
\ 'class' : 'c'
|
|
|
|
\ }
|
|
|
|
let s:known_types.mxml = type_mxml
|
2011-02-14 18:47:18 +08:00
|
|
|
" Fortran {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_fortran = {}
|
|
|
|
let type_fortran.ctagstype = 'fortran'
|
|
|
|
let type_fortran.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'programs', 'fold' : 0},
|
|
|
|
\ {'short' : 'k', 'long' : 'components', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'derived types and structures', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'common blocks', 'fold' : 0},
|
|
|
|
\ {'short' : 'b', 'long' : 'block data', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'entry points', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0},
|
|
|
|
\ {'short' : 'n', 'long' : 'namelists', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_fortran.sro = '.' " Not sure, is nesting even possible?
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_fortran.kind2scope = {
|
|
|
|
\ 'm' : 'module',
|
|
|
|
\ 'p' : 'program',
|
|
|
|
\ 'f' : 'function',
|
|
|
|
\ 's' : 'subroutine'
|
|
|
|
\ }
|
|
|
|
let type_fortran.scope2kind = {
|
|
|
|
\ 'module' : 'm',
|
|
|
|
\ 'program' : 'p',
|
|
|
|
\ 'function' : 'f',
|
|
|
|
\ 'subroutine' : 's'
|
|
|
|
\ }
|
|
|
|
let s:known_types.fortran = type_fortran
|
2011-02-14 18:47:18 +08:00
|
|
|
" HTML {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_html = {}
|
|
|
|
let type_html.ctagstype = 'html'
|
|
|
|
let type_html.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'JavaScript funtions', 'fold' : 0},
|
|
|
|
\ {'short' : 'a', 'long' : 'named anchors', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.html = type_html
|
2011-02-14 18:47:18 +08:00
|
|
|
" Java {{{3
|
2011-01-24 18:23:40 +08:00
|
|
|
let type_java = {}
|
|
|
|
let type_java.ctagstype = 'java'
|
|
|
|
let type_java.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'packages', 'fold' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'fields', 'fold' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enum types', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'enum constants', 'fold' : 0},
|
|
|
|
\ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0}
|
2011-01-24 18:23:40 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_java.sro = '.'
|
2011-01-24 18:23:40 +08:00
|
|
|
let type_java.kind2scope = {
|
|
|
|
\ 'g' : 'enum',
|
|
|
|
\ 'i' : 'interface',
|
|
|
|
\ 'c' : 'class'
|
|
|
|
\ }
|
|
|
|
let type_java.scope2kind = {
|
|
|
|
\ 'enum' : 'g',
|
|
|
|
\ 'interface' : 'i',
|
|
|
|
\ 'class' : 'c'
|
|
|
|
\ }
|
|
|
|
let s:known_types.java = type_java
|
2011-02-14 18:47:18 +08:00
|
|
|
" JavaScript {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
" JavaScript is weird -- it does have scopes, but ctags doesn't seem to
|
|
|
|
" properly generate the information for them, instead it simply uses the
|
|
|
|
" complete name. So ctags has to be fixed before I can do anything here.
|
2011-04-25 15:32:19 +08:00
|
|
|
" Alternatively jsctags/doctorjs will be used if available.
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_javascript = {}
|
|
|
|
let type_javascript.ctagstype = 'javascript'
|
2011-04-25 15:32:19 +08:00
|
|
|
if executable('jsctags')
|
|
|
|
let type_javascript.kinds = [
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
|
|
|
\ ]
|
|
|
|
let type_javascript.sro = '.'
|
|
|
|
let type_javascript.kind2scope = {
|
|
|
|
\ 'v' : 'namespace',
|
|
|
|
\ 'f' : 'namespace'
|
|
|
|
\ }
|
|
|
|
let type_javascript.scope2kind = {
|
|
|
|
\ 'namespace' : 'v'
|
|
|
|
\ }
|
|
|
|
let type_javascript.ctagsbin = 'jsctags'
|
|
|
|
let type_javascript.ctagsargs = '-f -'
|
|
|
|
else
|
|
|
|
let type_javascript.kinds = [
|
|
|
|
\ {'short' : 'v', 'long' : 'global variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'properties', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
|
|
|
\ ]
|
|
|
|
endif
|
2011-02-05 14:33:18 +08:00
|
|
|
let s:known_types.javascript = type_javascript
|
2011-02-14 18:47:18 +08:00
|
|
|
" Lisp {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_lisp = {}
|
|
|
|
let type_lisp.ctagstype = 'lisp'
|
|
|
|
let type_lisp.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.lisp = type_lisp
|
2011-02-14 18:47:18 +08:00
|
|
|
" Lua {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_lua = {}
|
|
|
|
let type_lua.ctagstype = 'lua'
|
|
|
|
let type_lua.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.lua = type_lua
|
2011-02-14 18:47:18 +08:00
|
|
|
" Make {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_make = {}
|
|
|
|
let type_make.ctagstype = 'make'
|
|
|
|
let type_make.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'macros', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.make = type_make
|
2011-02-14 18:47:18 +08:00
|
|
|
" Matlab {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_matlab = {}
|
|
|
|
let type_matlab.ctagstype = 'matlab'
|
|
|
|
let type_matlab.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.matlab = type_matlab
|
2011-02-14 18:47:18 +08:00
|
|
|
" Ocaml {{{3
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_ocaml = {}
|
|
|
|
let type_ocaml.ctagstype = 'ocaml'
|
|
|
|
let type_ocaml.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'M', 'long' : 'modules or functors', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'global variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'C', 'long' : 'constructors', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'exceptions', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'type names', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'r', 'long' : 'structure fields', 'fold' : 0}
|
2011-02-05 14:33:18 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_ocaml.sro = '.' " Not sure, is nesting even possible?
|
2011-02-05 14:33:18 +08:00
|
|
|
let type_ocaml.kind2scope = {
|
|
|
|
\ 'M' : 'Module',
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 't' : 'type'
|
|
|
|
\ }
|
|
|
|
let type_ocaml.scope2kind = {
|
|
|
|
\ 'Module' : 'M',
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'type' : 't'
|
|
|
|
\ }
|
|
|
|
let s:known_types.ocaml = type_ocaml
|
2011-02-14 18:47:18 +08:00
|
|
|
" Pascal {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_pascal = {}
|
|
|
|
let type_pascal.ctagstype = 'pascal'
|
|
|
|
let type_pascal.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.pascal = type_pascal
|
2011-02-14 18:47:18 +08:00
|
|
|
" Perl {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_perl = {}
|
|
|
|
let type_perl.ctagstype = 'perl'
|
|
|
|
let type_perl.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'packages', 'fold' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'formats', 'fold' : 0},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.perl = type_perl
|
2011-02-14 18:47:18 +08:00
|
|
|
" PHP {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_php = {}
|
|
|
|
let type_php.ctagstype = 'php'
|
|
|
|
let type_php.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'd', 'long' : 'constant definitions', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'j', 'long' : 'javascript functions', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.php = type_php
|
2011-02-14 18:47:18 +08:00
|
|
|
" Python {{{3
|
2011-01-14 18:12:26 +08:00
|
|
|
let type_python = {}
|
|
|
|
let type_python.ctagstype = 'python'
|
|
|
|
let type_python.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'i', 'long' : 'imports', 'fold' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}
|
2011-01-14 18:12:26 +08:00
|
|
|
\ ]
|
2011-03-26 22:32:31 +08:00
|
|
|
let type_python.sro = '.'
|
2011-01-16 12:46:14 +08:00
|
|
|
let type_python.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'f' : 'function',
|
|
|
|
\ 'm' : 'function'
|
2011-01-14 18:12:26 +08:00
|
|
|
\ }
|
2011-01-17 17:58:31 +08:00
|
|
|
let type_python.scope2kind = {
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'function' : 'f'
|
|
|
|
\ }
|
2011-01-14 18:12:26 +08:00
|
|
|
let s:known_types.python = type_python
|
2011-02-14 18:47:18 +08:00
|
|
|
" REXX {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_rexx = {}
|
|
|
|
let type_rexx.ctagstype = 'rexx'
|
|
|
|
let type_rexx.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.rexx = type_rexx
|
2011-02-14 18:47:18 +08:00
|
|
|
" Ruby {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_ruby = {}
|
|
|
|
let type_ruby.ctagstype = 'ruby'
|
|
|
|
let type_ruby.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'methods', 'fold' : 0},
|
|
|
|
\ {'short' : 'F', 'long' : 'singleton methods', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_ruby.sro = '.'
|
2011-02-28 13:08:31 +08:00
|
|
|
let type_ruby.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'm' : 'class'
|
2011-02-07 12:59:07 +08:00
|
|
|
\ }
|
|
|
|
let type_ruby.scope2kind = {
|
|
|
|
\ 'class' : 'c'
|
|
|
|
\ }
|
|
|
|
let s:known_types.ruby = type_ruby
|
2011-02-14 18:47:18 +08:00
|
|
|
" Scheme {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_scheme = {}
|
|
|
|
let type_scheme.ctagstype = 'scheme'
|
|
|
|
let type_scheme.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'sets', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.scheme = type_scheme
|
2011-02-14 18:47:18 +08:00
|
|
|
" Shell script {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_sh = {}
|
|
|
|
let type_sh.ctagstype = 'sh'
|
|
|
|
let type_sh.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.sh = type_sh
|
|
|
|
let s:known_types.csh = type_sh
|
|
|
|
let s:known_types.zsh = type_sh
|
2011-02-14 18:47:18 +08:00
|
|
|
" SLang {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_slang = {}
|
|
|
|
let type_slang.ctagstype = 'slang'
|
|
|
|
let type_slang.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.slang = type_slang
|
2011-02-14 18:47:18 +08:00
|
|
|
" SML {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_sml = {}
|
|
|
|
let type_sml.ctagstype = 'sml'
|
|
|
|
let type_sml.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'e', 'long' : 'exception declarations', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'function definitions', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'functor definitions', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'signature declarations', 'fold' : 0},
|
|
|
|
\ {'short' : 'r', 'long' : 'structure declarations', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'type definitions', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'value bindings', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.sml = type_sml
|
2011-02-14 18:47:18 +08:00
|
|
|
" SQL {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
" The SQL ctags parser seems to be buggy for me, so this just uses the
|
|
|
|
" normal kinds even though scopes should be available. Improvements
|
|
|
|
" welcome!
|
|
|
|
let type_sql = {}
|
|
|
|
let type_sql.ctagstype = 'sql'
|
|
|
|
let type_sql.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'P', 'long' : 'packages', 'fold' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'cursors', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'F', 'long' : 'record fields', 'fold' : 0},
|
|
|
|
\ {'short' : 'L', 'long' : 'block label', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'subtypes', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'tables', 'fold' : 0},
|
|
|
|
\ {'short' : 'T', 'long' : 'triggers', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'i', 'long' : 'indexes', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'events', 'fold' : 0},
|
|
|
|
\ {'short' : 'U', 'long' : 'publications', 'fold' : 0},
|
|
|
|
\ {'short' : 'R', 'long' : 'services', 'fold' : 0},
|
|
|
|
\ {'short' : 'D', 'long' : 'domains', 'fold' : 0},
|
|
|
|
\ {'short' : 'V', 'long' : 'views', 'fold' : 0},
|
|
|
|
\ {'short' : 'n', 'long' : 'synonyms', 'fold' : 0},
|
|
|
|
\ {'short' : 'x', 'long' : 'MobiLink Table Scripts', 'fold' : 0},
|
|
|
|
\ {'short' : 'y', 'long' : 'MobiLink Conn Scripts', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.sql = type_sql
|
2011-02-14 18:47:18 +08:00
|
|
|
" Tcl {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_tcl = {}
|
|
|
|
let type_tcl.ctagstype = 'tcl'
|
|
|
|
let type_tcl.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.tcl = type_tcl
|
2011-02-14 18:47:18 +08:00
|
|
|
" LaTeX {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_tex = {}
|
|
|
|
let type_tex.ctagstype = 'tex'
|
|
|
|
let type_tex.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'parts', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'chapters', 'fold' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'sections', 'fold' : 0},
|
|
|
|
\ {'short' : 'u', 'long' : 'subsections', 'fold' : 0},
|
|
|
|
\ {'short' : 'b', 'long' : 'subsubsections', 'fold' : 0},
|
|
|
|
\ {'short' : 'P', 'long' : 'paragraphs', 'fold' : 0},
|
|
|
|
\ {'short' : 'G', 'long' : 'subparagraphs', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.tex = type_tex
|
2011-02-14 18:47:18 +08:00
|
|
|
" Vera {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
" Why are variables 'virtual'?
|
|
|
|
let type_vera = {}
|
|
|
|
let type_vera.ctagstype = 'vera'
|
|
|
|
let type_vera.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0},
|
|
|
|
\ {'short' : 'T', 'long' : 'typedefs', 'fold' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'tasks', 'fold' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'programs', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
2011-03-06 14:52:54 +08:00
|
|
|
let type_vera.sro = '.' " Nesting doesn't seem to be possible
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_vera.kind2scope = {
|
|
|
|
\ 'g' : 'enum',
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'v' : 'virtual'
|
|
|
|
\ }
|
|
|
|
let type_vera.scope2kind = {
|
|
|
|
\ 'enum' : 'g',
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'virtual' : 'v'
|
|
|
|
\ }
|
|
|
|
let s:known_types.vera = type_vera
|
2011-02-14 18:47:18 +08:00
|
|
|
" Verilog {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_verilog = {}
|
|
|
|
let type_verilog.ctagstype = 'verilog'
|
|
|
|
let type_verilog.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'events', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0},
|
|
|
|
\ {'short' : 'n', 'long' : 'net data types', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'ports', 'fold' : 0},
|
|
|
|
\ {'short' : 'r', 'long' : 'register data types', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'tasks', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.verilog = type_verilog
|
2011-02-14 18:47:18 +08:00
|
|
|
" VHDL {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
" The VHDL ctags parser unfortunately doesn't generate proper scopes
|
|
|
|
let type_vhdl = {}
|
|
|
|
let type_vhdl.ctagstype = 'vhdl'
|
|
|
|
let type_vhdl.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'P', 'long' : 'packages', 'fold' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'types', 'fold' : 0},
|
|
|
|
\ {'short' : 'T', 'long' : 'subtypes', 'fold' : 0},
|
|
|
|
\ {'short' : 'r', 'long' : 'records', 'fold' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'entities', 'fold' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.vhdl = type_vhdl
|
2011-02-14 18:47:18 +08:00
|
|
|
" Vim {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_vim = {}
|
|
|
|
let type_vim.ctagstype = 'vim'
|
|
|
|
let type_vim.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0},
|
|
|
|
\ {'short' : 'a', 'long' : 'autocommand groups', 'fold' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'commands', 'fold' : 0},
|
2011-03-27 21:48:21 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'maps', 'fold' : 1}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.vim = type_vim
|
2011-02-14 18:47:18 +08:00
|
|
|
" YACC {{{3
|
2011-02-07 12:59:07 +08:00
|
|
|
let type_yacc = {}
|
|
|
|
let type_yacc.ctagstype = 'yacc'
|
|
|
|
let type_yacc.kinds = [
|
2011-03-26 22:32:31 +08:00
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0}
|
2011-02-07 12:59:07 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.yacc = type_yacc
|
2011-02-14 18:47:18 +08:00
|
|
|
" }}}3
|
2011-01-14 18:12:26 +08:00
|
|
|
|
2011-02-07 14:19:55 +08:00
|
|
|
let user_defs = s:GetUserTypeDefs()
|
|
|
|
for [key, value] in items(user_defs)
|
2011-02-14 17:02:44 +08:00
|
|
|
if !has_key(s:known_types, key) ||
|
|
|
|
\ (has_key(value, 'replace') && value.replace)
|
2011-02-07 14:19:55 +08:00
|
|
|
let s:known_types[key] = value
|
|
|
|
else
|
|
|
|
call extend(s:known_types[key], value)
|
|
|
|
endif
|
|
|
|
endfor
|
2011-01-17 12:08:10 +08:00
|
|
|
|
|
|
|
" 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
|
2011-03-26 22:32:31 +08:00
|
|
|
let type.kinddict[kind.short] = i
|
2011-01-17 12:08:10 +08:00
|
|
|
let i += 1
|
|
|
|
endfor
|
|
|
|
endfor
|
2011-01-12 17:48:04 +08:00
|
|
|
|
2011-01-23 11:47:44 +08:00
|
|
|
let s:type_init_done = 1
|
|
|
|
endfunction
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:GetUserTypeDefs() {{{2
|
2011-02-07 14:19:55 +08:00
|
|
|
function! s:GetUserTypeDefs()
|
|
|
|
redir => defs
|
2011-04-08 09:17:50 +08:00
|
|
|
silent execute 'let g:'
|
2011-02-07 14:19:55 +08:00
|
|
|
redir END
|
|
|
|
|
|
|
|
let deflist = split(defs, '\n')
|
|
|
|
call map(deflist, 'substitute(v:val, ''^\S\+\zs.*'', "", "")')
|
|
|
|
call filter(deflist, 'v:val =~ "^tagbar_type_"')
|
|
|
|
|
|
|
|
let defdict = {}
|
2011-02-19 12:12:47 +08:00
|
|
|
for defstr in deflist
|
|
|
|
let type = substitute(defstr, '^tagbar_type_', '', '')
|
|
|
|
execute 'let defdict["' . type . '"] = g:' . defstr
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" If the user only specified one of kind2scope and scope2kind use it to
|
|
|
|
" generate the other one
|
2011-03-26 22:32:31 +08:00
|
|
|
" Also, transform the 'kind' definitions into dictionary format
|
2011-02-19 12:12:47 +08:00
|
|
|
for def in values(defdict)
|
2011-03-26 22:32:31 +08:00
|
|
|
let kinds = def.kinds
|
|
|
|
let def.kinds = []
|
|
|
|
for kind in kinds
|
|
|
|
let kindlist = split(kind, ':')
|
|
|
|
let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]}
|
|
|
|
if len(kindlist) == 3
|
2011-03-28 12:08:14 +08:00
|
|
|
let kinddict.fold = kindlist[2]
|
2011-03-26 22:32:31 +08:00
|
|
|
else
|
2011-03-28 12:08:14 +08:00
|
|
|
let kinddict.fold = 0
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
call add(def.kinds, kinddict)
|
|
|
|
endfor
|
|
|
|
|
2011-02-19 12:12:47 +08:00
|
|
|
if has_key(def, 'kind2scope') && !has_key(def, 'scope2kind')
|
|
|
|
let def.scope2kind = {}
|
|
|
|
for [key, value] in items(def.kind2scope)
|
|
|
|
let def.scope2kind[value] = key
|
|
|
|
endfor
|
|
|
|
elseif has_key(def, 'scope2kind') && !has_key(def, 'kind2scope')
|
|
|
|
let def.kind2scope = {}
|
|
|
|
for [key, value] in items(def.scope2kind)
|
|
|
|
let def.kind2scope[value] = key
|
|
|
|
endfor
|
|
|
|
endif
|
2011-02-07 14:19:55 +08:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return defdict
|
|
|
|
endfunction
|
|
|
|
|
2011-05-25 11:18:26 +08:00
|
|
|
" s:RestoreSession() {{{2
|
|
|
|
" Properly restore Tagbar after a session got loaded
|
|
|
|
function! s:RestoreSession()
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr == -1
|
|
|
|
" Tagbar wasn't open in the saved session, nothing to do
|
|
|
|
return
|
|
|
|
else
|
|
|
|
let in_tagbar = 1
|
|
|
|
if winnr() != tagbarwinnr
|
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
let in_tagbar = 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !s:type_init_done
|
|
|
|
call s:InitTypes()
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !s:checked_ctags
|
|
|
|
if !s:CheckForExCtags()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:InitWindow(g:tagbar_autoclose)
|
|
|
|
|
|
|
|
" Leave the Tagbar window and come back so the update event gets triggered
|
|
|
|
execute 'wincmd p'
|
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
|
|
|
|
if !in_tagbar
|
|
|
|
execute 'wincmd p'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-19 12:32:49 +08:00
|
|
|
" s:MapKeys() {{{2
|
|
|
|
function! s:MapKeys()
|
|
|
|
nnoremap <script> <silent> <buffer> <2-LeftMouse>
|
2011-04-25 12:09:40 +08:00
|
|
|
\ :call <SID>JumpToTag(0)<CR>
|
2011-03-27 19:34:50 +08:00
|
|
|
nnoremap <script> <silent> <buffer> <LeftRelease>
|
2011-06-06 15:18:32 +08:00
|
|
|
\ <LeftRelease>:call <SID>CheckMouseClick()<CR>
|
|
|
|
|
|
|
|
inoremap <script> <silent> <buffer> <2-LeftMouse>
|
|
|
|
\ <C-o>:call <SID>JumpToTag(0)<CR>
|
|
|
|
inoremap <script> <silent> <buffer> <LeftRelease>
|
|
|
|
\ <LeftRelease><C-o>:call <SID>CheckMouseClick()<CR>
|
|
|
|
|
|
|
|
nnoremap <script> <silent> <buffer> <CR> :call <SID>JumpToTag(0)<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> p :call <SID>JumpToTag(1)<CR>
|
2011-02-19 12:32:49 +08:00
|
|
|
nnoremap <script> <silent> <buffer> <Space> :call <SID>ShowPrototype()<CR>
|
|
|
|
|
2011-03-27 14:47:56 +08:00
|
|
|
nnoremap <script> <silent> <buffer> + :call <SID>OpenFold()<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> <kPlus> :call <SID>OpenFold()<CR>
|
2011-03-30 11:35:56 +08:00
|
|
|
nnoremap <script> <silent> <buffer> zo :call <SID>OpenFold()<CR>
|
2011-03-27 14:47:56 +08:00
|
|
|
nnoremap <script> <silent> <buffer> - :call <SID>CloseFold()<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> <kMinus> :call <SID>CloseFold()<CR>
|
2011-03-30 11:35:56 +08:00
|
|
|
nnoremap <script> <silent> <buffer> zc :call <SID>CloseFold()<CR>
|
2011-04-07 21:00:12 +08:00
|
|
|
nnoremap <script> <silent> <buffer> o :call <SID>ToggleFold()<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> za :call <SID>ToggleFold()<CR>
|
2011-03-27 14:47:56 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
nnoremap <script> <silent> <buffer> * :call <SID>SetFoldLevel(99)<CR>
|
2011-03-27 14:47:56 +08:00
|
|
|
nnoremap <script> <silent> <buffer> <kMultiply>
|
2011-04-07 21:00:12 +08:00
|
|
|
\ :call <SID>SetFoldLevel(99)<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> zR :call <SID>SetFoldLevel(99)<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> = :call <SID>SetFoldLevel(0)<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> zM :call <SID>SetFoldLevel(0)<CR>
|
2011-02-19 12:32:49 +08:00
|
|
|
|
2011-04-24 09:58:06 +08:00
|
|
|
nnoremap <script> <silent> <buffer> <C-N>
|
|
|
|
\ :call <SID>GotoNextToplevelTag(1)<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> <C-P>
|
|
|
|
\ :call <SID>GotoNextToplevelTag(-1)<CR>
|
|
|
|
|
2011-02-19 12:32:49 +08:00
|
|
|
nnoremap <script> <silent> <buffer> s :call <SID>ToggleSort()<CR>
|
2011-04-07 21:00:12 +08:00
|
|
|
nnoremap <script> <silent> <buffer> x :call <SID>ZoomWindow()<CR>
|
2011-05-13 12:06:34 +08:00
|
|
|
nnoremap <script> <silent> <buffer> q :call <SID>CloseWindow()<CR>
|
2011-02-19 12:32:49 +08:00
|
|
|
nnoremap <script> <silent> <buffer> <F1> :call <SID>ToggleHelp()<CR>
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CreateAutocommands() {{{2
|
|
|
|
function! s:CreateAutocommands()
|
|
|
|
augroup TagbarAutoCmds
|
|
|
|
autocmd!
|
|
|
|
autocmd BufEnter __Tagbar__ nested call s:QuitIfOnlyWindow()
|
|
|
|
autocmd BufUnload __Tagbar__ call s:CleanUp()
|
|
|
|
autocmd CursorHold __Tagbar__ call s:ShowPrototype()
|
|
|
|
|
2011-03-28 21:18:38 +08:00
|
|
|
autocmd BufEnter,CursorHold * call
|
2011-04-24 16:15:02 +08:00
|
|
|
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'))
|
|
|
|
autocmd BufDelete * call
|
|
|
|
\ s:CleanupFileinfo(fnamemodify(expand('<afile>'), ':p'))
|
2011-02-19 12:32:49 +08:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
let s:autocommands_done = 1
|
|
|
|
endfunction
|
|
|
|
|
2011-05-12 16:50:14 +08:00
|
|
|
" s:CheckForExCtags() {{{2
|
|
|
|
" Test whether the ctags binary is actually Exuberant Ctags and not GNU ctags
|
|
|
|
" (or something else)
|
|
|
|
function! s:CheckForExCtags()
|
|
|
|
let ctags_cmd = s:EscapeCtagsCmd(g:tagbar_ctags_bin, '--version')
|
|
|
|
if ctags_cmd == ''
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let ctags_output = s:ExecuteCtags(ctags_cmd)
|
|
|
|
|
|
|
|
if v:shell_error || ctags_output !~# 'Exuberant Ctags'
|
|
|
|
echoerr 'Tagbar: Ctags doesn''t seem to be Exuberant Ctags!'
|
|
|
|
echomsg 'GNU ctags will NOT WORK.'
|
|
|
|
\ 'Please download Exuberant Ctags from ctags.sourceforge.net'
|
|
|
|
\ 'and install it in a directory in your $PATH'
|
|
|
|
\ 'or set g:tagbar_ctags_bin.'
|
|
|
|
echomsg 'Executed command: "' . ctags_cmd . '"'
|
|
|
|
if !empty(ctags_output)
|
|
|
|
echomsg 'Command output:'
|
|
|
|
for line in split(ctags_output, '\n')
|
|
|
|
echomsg line
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return 0
|
2011-05-23 18:43:47 +08:00
|
|
|
elseif !s:CheckExCtagsVersion(ctags_output)
|
|
|
|
echoerr 'Tagbar: Exuberant Ctags is too old!'
|
|
|
|
echomsg 'You need at least version 5.5 for Tagbar to work.'
|
|
|
|
\ 'Please download a newer version from ctags.sourceforge.net.'
|
|
|
|
echomsg 'Executed command: "' . ctags_cmd . '"'
|
|
|
|
if !empty(ctags_output)
|
|
|
|
echomsg 'Command output:'
|
|
|
|
for line in split(ctags_output, '\n')
|
|
|
|
echomsg line
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return 0
|
2011-05-12 16:50:14 +08:00
|
|
|
else
|
|
|
|
let s:checked_ctags = 1
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-05-23 18:43:47 +08:00
|
|
|
" s:CheckExCtagsVersion() {{{2
|
|
|
|
function! s:CheckExCtagsVersion(output)
|
|
|
|
let matchlist = matchlist(a:output, '\vExuberant Ctags (\d+)\.(\d+)')
|
|
|
|
let major = matchlist[1]
|
|
|
|
let minor = matchlist[2]
|
|
|
|
|
|
|
|
return major >= 6 || (major == 5 && minor >= 5)
|
|
|
|
endfunction
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
" Prototypes {{{1
|
|
|
|
" Base tag {{{2
|
|
|
|
let s:BaseTag = {}
|
|
|
|
|
|
|
|
" s:BaseTag._init() {{{3
|
|
|
|
function! s:BaseTag._init(name) dict
|
|
|
|
let self.name = a:name
|
|
|
|
let self.fields = {}
|
|
|
|
let self.fields.line = 0
|
|
|
|
let self.path = ''
|
|
|
|
let self.fullpath = a:name
|
|
|
|
let self.depth = 0
|
|
|
|
let self.parent = {}
|
|
|
|
let self.tline = -1
|
|
|
|
let self.fileinfo = {}
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isNormalTag() {{{3
|
|
|
|
function! s:BaseTag.isNormalTag() dict
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isPseudoTag() {{{3
|
|
|
|
function! s:BaseTag.isPseudoTag() dict
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isKindheader() {{{3
|
|
|
|
function! s:BaseTag.isKindheader() dict
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.getPrototype() {{{3
|
|
|
|
function! s:BaseTag.getPrototype() dict
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag._getPrefix() {{{3
|
2011-04-25 22:18:55 +08:00
|
|
|
function! s:BaseTag._getPrefix() dict
|
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
if has_key(self, 'children') && !empty(self.children)
|
2011-04-25 22:18:55 +08:00
|
|
|
if fileinfo.tagfolds[self.fields.kind][self.fullpath]
|
2011-04-07 21:00:12 +08:00
|
|
|
let prefix = s:icon_closed
|
|
|
|
else
|
|
|
|
let prefix = s:icon_open
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let prefix = ' '
|
|
|
|
endif
|
|
|
|
if has_key(self.fields, 'access')
|
|
|
|
let prefix .= get(s:access_symbols, self.fields.access, ' ')
|
|
|
|
else
|
|
|
|
let prefix .= ' '
|
|
|
|
endif
|
|
|
|
|
|
|
|
return prefix
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.initFoldState() {{{3
|
|
|
|
function! s:BaseTag.initFoldState() dict
|
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
|
|
|
|
if s:known_files.has(fileinfo.fpath) &&
|
|
|
|
\ has_key(fileinfo._tagfolds_old[self.fields.kind], self.fullpath)
|
|
|
|
" The file has been updated and the tag was there before, so copy its
|
|
|
|
" old fold state
|
|
|
|
let fileinfo.tagfolds[self.fields.kind][self.fullpath] =
|
|
|
|
\ fileinfo._tagfolds_old[self.fields.kind][self.fullpath]
|
|
|
|
elseif self.depth >= fileinfo.foldlevel
|
|
|
|
let fileinfo.tagfolds[self.fields.kind][self.fullpath] = 1
|
|
|
|
else
|
|
|
|
let fileinfo.tagfolds[self.fields.kind][self.fullpath] =
|
|
|
|
\ fileinfo.kindfolds[self.fields.kind]
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.getClosedParentTline() {{{3
|
|
|
|
function! s:BaseTag.getClosedParentTline() dict
|
|
|
|
let tagline = self.tline
|
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
|
|
|
|
let parent = self.parent
|
|
|
|
while !empty(parent)
|
|
|
|
if parent.isFolded()
|
|
|
|
let tagline = parent.tline
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
let parent = parent.parent
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
return tagline
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isFoldable() {{{3
|
|
|
|
function! s:BaseTag.isFoldable() dict
|
|
|
|
return has_key(self, 'children') && !empty(self.children)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isFolded() {{{3
|
|
|
|
function! s:BaseTag.isFolded() dict
|
|
|
|
return self.fileinfo.tagfolds[self.fields.kind][self.fullpath]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.openFold() {{{3
|
|
|
|
function! s:BaseTag.openFold() dict
|
|
|
|
if self.isFoldable()
|
|
|
|
let self.fileinfo.tagfolds[self.fields.kind][self.fullpath] = 0
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.closeFold() {{{3
|
|
|
|
function! s:BaseTag.closeFold() dict
|
|
|
|
let newline = line('.')
|
|
|
|
|
|
|
|
if !empty(self.parent) && self.parent.isKindheader()
|
|
|
|
" Tag is child of generic 'kind'
|
|
|
|
call self.parent.closeFold()
|
|
|
|
let newline = self.parent.tline
|
|
|
|
elseif self.isFoldable() && !self.isFolded()
|
|
|
|
" Tag is parent of a scope and is not folded
|
|
|
|
let self.fileinfo.tagfolds[self.fields.kind][self.fullpath] = 1
|
|
|
|
elseif !empty(self.parent)
|
|
|
|
" Tag is normal child, so close parent
|
|
|
|
let parent = self.parent
|
|
|
|
let self.fileinfo.tagfolds[parent.fields.kind][parent.fullpath] = 1
|
|
|
|
let newline = parent.tline
|
|
|
|
endif
|
|
|
|
|
|
|
|
return newline
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.setFolded() {{{3
|
|
|
|
function! s:BaseTag.setFolded(folded) dict
|
|
|
|
let self.fileinfo.tagfolds[self.fields.kind][self.fullpath] = a:folded
|
|
|
|
endfunction
|
|
|
|
|
2011-04-24 18:53:07 +08:00
|
|
|
" s:BaseTag.openParents() {{{3
|
|
|
|
function! s:BaseTag.openParents() dict
|
|
|
|
let parent = self.parent
|
|
|
|
|
|
|
|
while !empty(parent)
|
|
|
|
call parent.openFold()
|
|
|
|
let parent = parent.parent
|
|
|
|
endwhile
|
|
|
|
endfunction
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
" Normal tag {{{2
|
|
|
|
let s:NormalTag = copy(s:BaseTag)
|
|
|
|
|
|
|
|
" s:NormalTag.New() {{{3
|
|
|
|
function! s:NormalTag.New(name) dict
|
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
call newobj._init(a:name)
|
|
|
|
|
|
|
|
return newobj
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:NormalTag.isNormalTag() {{{3
|
|
|
|
function! s:NormalTag.isNormalTag() dict
|
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:NormalTag.str() {{{3
|
2011-04-25 22:18:55 +08:00
|
|
|
function! s:NormalTag.str() dict
|
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
let typeinfo = s:known_types[fileinfo.ftype]
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let suffix = get(self.fields, 'signature', '')
|
2011-04-25 15:32:19 +08:00
|
|
|
if has_key(self.fields, 'type')
|
|
|
|
let suffix .= ' : ' . self.fields.type
|
2011-04-25 22:18:55 +08:00
|
|
|
elseif has_key(typeinfo, 'kind2scope') &&
|
|
|
|
\ has_key(typeinfo.kind2scope, self.fields.kind)
|
|
|
|
let suffix .= ' : ' . typeinfo.kind2scope[self.fields.kind]
|
2011-04-07 21:00:12 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-25 22:18:55 +08:00
|
|
|
return self._getPrefix() . self.name . suffix . "\n"
|
2011-04-07 21:00:12 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:NormalTag.getPrototype() {{{3
|
|
|
|
function! s:NormalTag.getPrototype() dict
|
|
|
|
return self.prototype
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Pseudo tag {{{2
|
|
|
|
let s:PseudoTag = copy(s:BaseTag)
|
|
|
|
|
|
|
|
" s:PseudoTag.New() {{{3
|
|
|
|
function! s:PseudoTag.New(name) dict
|
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
call newobj._init(a:name)
|
|
|
|
|
|
|
|
return newobj
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:PseudoTag.isPseudoTag() {{{3
|
|
|
|
function! s:PseudoTag.isPseudoTag() dict
|
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:PseudoTag.str() {{{3
|
2011-04-25 22:18:55 +08:00
|
|
|
function! s:PseudoTag.str() dict
|
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
let typeinfo = s:known_types[fileinfo.ftype]
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let suffix = get(self.fields, 'signature', '')
|
2011-04-25 22:18:55 +08:00
|
|
|
if has_key(typeinfo.kind2scope, self.fields.kind)
|
|
|
|
let suffix .= ' : ' . typeinfo.kind2scope[self.fields.kind]
|
2011-04-07 21:00:12 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-25 22:18:55 +08:00
|
|
|
return self._getPrefix() . self.name . '*' . suffix
|
2011-04-07 21:00:12 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Kind header {{{2
|
|
|
|
let s:KindheaderTag = copy(s:BaseTag)
|
|
|
|
|
|
|
|
" s:KindheaderTag.New() {{{3
|
|
|
|
function! s:KindheaderTag.New(name) dict
|
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
call newobj._init(a:name)
|
|
|
|
|
|
|
|
return newobj
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.isKindheader() {{{3
|
|
|
|
function! s:KindheaderTag.isKindheader() dict
|
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.getPrototype() {{{3
|
|
|
|
function! s:KindheaderTag.getPrototype() dict
|
|
|
|
return self.name . ': ' .
|
|
|
|
\ self.numtags . ' ' . (self.numtags > 1 ? 'tags' : 'tag')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.isFoldable() {{{3
|
|
|
|
function! s:KindheaderTag.isFoldable() dict
|
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.isFolded() {{{3
|
|
|
|
function! s:KindheaderTag.isFolded() dict
|
|
|
|
return self.fileinfo.kindfolds[self.short]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.openFold() {{{3
|
|
|
|
function! s:KindheaderTag.openFold() dict
|
|
|
|
let self.fileinfo.kindfolds[self.short] = 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.closeFold() {{{3
|
|
|
|
function! s:KindheaderTag.closeFold() dict
|
|
|
|
let self.fileinfo.kindfolds[self.short] = 1
|
|
|
|
return line('.')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.toggleFold() {{{3
|
|
|
|
function! s:KindheaderTag.toggleFold() dict
|
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
|
|
|
|
let fileinfo.kindfolds[self.short] = !fileinfo.kindfolds[self.short]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" File info {{{2
|
|
|
|
let s:FileInfo = {}
|
|
|
|
|
|
|
|
" s:FileInfo.New() {{{3
|
|
|
|
function! s:FileInfo.New(fname, ftype) dict
|
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
" The complete file path
|
|
|
|
let newobj.fpath = a:fname
|
|
|
|
|
|
|
|
" File modification time
|
|
|
|
let newobj.mtime = getftime(a:fname)
|
|
|
|
|
|
|
|
" The vim file type
|
|
|
|
let newobj.ftype = a:ftype
|
|
|
|
|
|
|
|
" List of the tags that are present in the file, sorted according to the
|
|
|
|
" value of 'g:tagbar_sort'
|
|
|
|
let newobj.tags = []
|
|
|
|
|
|
|
|
" Dictionary of the tags, indexed by line number in the file
|
|
|
|
let newobj.fline = {}
|
|
|
|
|
|
|
|
" Dictionary of the tags, indexed by line number in the tagbar
|
|
|
|
let newobj.tline = {}
|
|
|
|
|
|
|
|
" Dictionary of the folding state of 'kind's, indexed by short name
|
|
|
|
let newobj.kindfolds = {}
|
|
|
|
let typeinfo = s:known_types[a:ftype]
|
|
|
|
" copy the default fold state from the type info
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
let newobj.kindfolds[kind.short] =
|
|
|
|
\ g:tagbar_foldlevel == 0 ? 1 : kind.fold
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" Dictionary of dictionaries of the folding state of individual tags,
|
|
|
|
" indexed by kind and full path
|
|
|
|
let newobj.tagfolds = {}
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
let newobj.tagfolds[kind.short] = {}
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" The current foldlevel of the file
|
|
|
|
let newobj.foldlevel = g:tagbar_foldlevel
|
|
|
|
|
|
|
|
return newobj
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.reset() {{{3
|
|
|
|
" Reset stuff that gets regenerated while processing a file and save the old
|
|
|
|
" tag folds
|
|
|
|
function! s:FileInfo.reset() dict
|
|
|
|
let self.mtime = getftime(self.fpath)
|
|
|
|
let self.tags = []
|
|
|
|
let self.fline = {}
|
|
|
|
let self.tline = {}
|
|
|
|
|
|
|
|
let self._tagfolds_old = self.tagfolds
|
|
|
|
let self.tagfolds = {}
|
2011-04-07 23:12:00 +08:00
|
|
|
|
|
|
|
let typeinfo = s:known_types[self.ftype]
|
2011-04-07 21:00:12 +08:00
|
|
|
for kind in typeinfo.kinds
|
|
|
|
let self.tagfolds[kind.short] = {}
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.clearOldFolds() {{{3
|
|
|
|
function! s:FileInfo.clearOldFolds() dict
|
|
|
|
if exists('self._tagfolds_old')
|
|
|
|
unlet self._tagfolds_old
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.sortTags() {{{3
|
|
|
|
function! s:FileInfo.sortTags() dict
|
|
|
|
if has_key(s:compare_typeinfo, 'sort')
|
|
|
|
if s:compare_typeinfo.sort
|
|
|
|
call s:SortTags(self.tags, 's:CompareByKind')
|
|
|
|
else
|
|
|
|
call s:SortTags(self.tags, 's:CompareByLine')
|
|
|
|
endif
|
|
|
|
elseif g:tagbar_sort
|
|
|
|
call s:SortTags(self.tags, 's:CompareByKind')
|
|
|
|
else
|
|
|
|
call s:SortTags(self.tags, 's:CompareByLine')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.openKindFold() {{{3
|
|
|
|
function! s:FileInfo.openKindFold(kind) dict
|
|
|
|
let self.kindfolds[a:kind.short] = 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.closeKindFold() {{{3
|
|
|
|
function! s:FileInfo.closeKindFold(kind) dict
|
|
|
|
let self.kindfolds[a:kind.short] = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Known files {{{2
|
|
|
|
let s:known_files = {
|
|
|
|
\ '_current' : {},
|
|
|
|
\ '_files' : {}
|
|
|
|
\ }
|
|
|
|
|
|
|
|
" s:known_files.getCurrent() {{{3
|
|
|
|
function! s:known_files.getCurrent() dict
|
|
|
|
return self._current
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.setCurrent() {{{3
|
|
|
|
function! s:known_files.setCurrent(fileinfo) dict
|
|
|
|
let self._current = a:fileinfo
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.get() {{{3
|
|
|
|
function! s:known_files.get(fname) dict
|
|
|
|
return get(self._files, a:fname, {})
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.put() {{{3
|
2011-04-24 16:15:02 +08:00
|
|
|
" Optional second argument is the filename
|
2011-04-07 21:00:12 +08:00
|
|
|
function! s:known_files.put(fileinfo, ...) dict
|
|
|
|
if a:0 == 1
|
|
|
|
let self._files[a:1] = a:fileinfo
|
|
|
|
else
|
|
|
|
let fname = a:fileinfo.fpath
|
|
|
|
let self._files[fname] = a:fileinfo
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.has() {{{3
|
|
|
|
function! s:known_files.has(fname) dict
|
|
|
|
return has_key(self._files, a:fname)
|
|
|
|
endfunction
|
|
|
|
|
2011-04-25 22:18:55 +08:00
|
|
|
" s:known_files.rm() {{{3
|
2011-04-24 16:15:02 +08:00
|
|
|
function! s:known_files.rm(fname) dict
|
|
|
|
if s:known_files.has(a:fname)
|
|
|
|
call remove(self._files, a:fname)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" Window management {{{1
|
|
|
|
" s:ToggleWindow() {{{2
|
2011-01-11 17:36:49 +08:00
|
|
|
function! s:ToggleWindow()
|
|
|
|
let tagbarwinnr = bufwinnr("__Tagbar__")
|
|
|
|
if tagbarwinnr != -1
|
|
|
|
call s:CloseWindow()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-02-14 18:32:57 +08:00
|
|
|
call s:OpenWindow(0)
|
2011-01-11 17:36:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:OpenWindow() {{{2
|
2011-02-14 18:32:57 +08:00
|
|
|
function! s:OpenWindow(autoclose)
|
2011-01-11 17:36:49 +08:00
|
|
|
" If the tagbar window is already open jump to it
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
2011-03-04 05:54:19 +08:00
|
|
|
if tagbarwinnr != -1
|
|
|
|
if winnr() != tagbarwinnr
|
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
endif
|
2011-02-19 12:39:35 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-05-25 11:18:26 +08:00
|
|
|
if !s:type_init_done
|
|
|
|
call s:InitTypes()
|
|
|
|
endif
|
|
|
|
|
2011-05-12 16:50:14 +08:00
|
|
|
if !s:checked_ctags
|
|
|
|
if !s:CheckForExCtags()
|
|
|
|
return
|
2011-05-07 14:02:03 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2011-02-26 15:51:15 +08:00
|
|
|
" Expand the Vim window to accomodate for the Tagbar window if requested
|
|
|
|
if g:tagbar_expand && !s:window_expanded && has('gui_running')
|
|
|
|
let &columns += g:tagbar_width + 1
|
|
|
|
let s:window_expanded = 1
|
|
|
|
endif
|
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
|
2011-04-08 09:17:50 +08:00
|
|
|
exe 'silent keepalt ' . openpos . g:tagbar_width . 'split ' . '__Tagbar__'
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-05-25 11:18:26 +08:00
|
|
|
call s:InitWindow(a:autoclose)
|
|
|
|
|
|
|
|
execute 'wincmd p'
|
|
|
|
|
|
|
|
" Jump back to the tagbar window if autoclose or autofocus is set. Can't
|
|
|
|
" just stay in it since it wouldn't trigger the update event
|
|
|
|
if g:tagbar_autoclose || a:autoclose || g:tagbar_autofocus
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:InitWindow() {{{2
|
|
|
|
function! s:InitWindow(autoclose)
|
2011-01-11 17:36:49 +08:00
|
|
|
setlocal noreadonly " in case the "view" mode is used
|
|
|
|
setlocal buftype=nofile
|
2011-01-23 11:40:14 +08:00
|
|
|
setlocal bufhidden=hide
|
2011-01-11 17:36:49 +08:00
|
|
|
setlocal noswapfile
|
|
|
|
setlocal nobuflisted
|
|
|
|
setlocal nomodifiable
|
|
|
|
setlocal filetype=tagbar
|
|
|
|
setlocal nolist
|
|
|
|
setlocal nonumber
|
|
|
|
setlocal nowrap
|
|
|
|
setlocal winfixwidth
|
2011-02-05 14:32:49 +08:00
|
|
|
setlocal textwidth=0
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-18 10:03:27 +08:00
|
|
|
if exists('+relativenumber')
|
|
|
|
setlocal norelativenumber
|
|
|
|
endif
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
setlocal nofoldenable
|
2011-05-15 14:25:45 +08:00
|
|
|
" Reset fold settings in case a plugin set them globally to something
|
|
|
|
" expensive. Apparently 'foldexpr' gets executed even if 'foldenable' is
|
|
|
|
" off, and then for every appended line (like with :put).
|
|
|
|
setlocal foldmethod&
|
|
|
|
setlocal foldexpr&
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-27 16:04:21 +08:00
|
|
|
setlocal statusline=%!TagbarGenerateStatusline()
|
|
|
|
|
2011-01-21 19:27:50 +08:00
|
|
|
" Script-local variable needed since compare functions can't
|
|
|
|
" take extra arguments
|
|
|
|
let s:compare_typeinfo = {}
|
|
|
|
|
2011-01-20 16:20:29 +08:00
|
|
|
let s:is_maximized = 0
|
2011-01-21 19:27:50 +08:00
|
|
|
let s:short_help = 1
|
2011-01-20 13:16:57 +08:00
|
|
|
|
2011-02-14 18:32:57 +08:00
|
|
|
let w:autoclose = a:autoclose
|
|
|
|
|
2011-01-20 16:03:56 +08:00
|
|
|
if has('balloon_eval')
|
|
|
|
setlocal balloonexpr=TagbarBalloonExpr()
|
|
|
|
set ballooneval
|
|
|
|
endif
|
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
let cpoptions_save = &cpoptions
|
|
|
|
set cpoptions&vim
|
|
|
|
|
2011-03-17 20:52:47 +08:00
|
|
|
if !hasmapto('JumpToTag', 'n')
|
2011-02-19 12:32:49 +08:00
|
|
|
call s:MapKeys()
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-02-19 12:32:49 +08:00
|
|
|
if !s:autocommands_done
|
|
|
|
call s:CreateAutocommands()
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
|
|
|
|
let &cpoptions = cpoptions_save
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:CloseWindow() {{{2
|
2011-01-11 17:36:49 +08:00
|
|
|
function! s:CloseWindow()
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-02-26 15:51:15 +08:00
|
|
|
let tagbarbufnr = winbufnr(tagbarwinnr)
|
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
if winnr() == tagbarwinnr
|
|
|
|
if winbufnr(2) != -1
|
|
|
|
" Other windows are open, only close the tagbar one
|
|
|
|
close
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
" Go to the tagbar window, close it and then come back to the
|
|
|
|
" original window
|
|
|
|
let curbufnr = bufnr('%')
|
2011-01-20 11:47:29 +08:00
|
|
|
execute tagbarwinnr . 'wincmd w'
|
2011-01-11 17:36:49 +08:00
|
|
|
close
|
|
|
|
" Need to jump back to the original window only if we are not
|
|
|
|
" already in that window
|
|
|
|
let winnum = bufwinnr(curbufnr)
|
|
|
|
if winnr() != winnum
|
|
|
|
exe winnum . 'wincmd w'
|
|
|
|
endif
|
|
|
|
endif
|
2011-02-26 15:51:15 +08:00
|
|
|
|
|
|
|
" If the Vim window has been expanded, and Tagbar is not open in any other
|
|
|
|
" tabpages, shrink the window again
|
|
|
|
if s:window_expanded
|
|
|
|
let tablist = []
|
|
|
|
for i in range(tabpagenr('$'))
|
|
|
|
call extend(tablist, tabpagebuflist(i + 1))
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if index(tablist, tagbarbufnr) == -1
|
|
|
|
let &columns -= g:tagbar_width + 1
|
|
|
|
let s:window_expanded = 0
|
|
|
|
endif
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:ZoomWindow() {{{2
|
2011-01-20 16:20:29 +08:00
|
|
|
function! s:ZoomWindow()
|
|
|
|
if s:is_maximized
|
|
|
|
execute 'vert resize ' . g:tagbar_width
|
|
|
|
let s:is_maximized = 0
|
|
|
|
else
|
|
|
|
vert resize
|
|
|
|
let s:is_maximized = 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" Tag processing {{{1
|
|
|
|
" s:ProcessFile() {{{2
|
2011-04-07 21:00:12 +08:00
|
|
|
" Execute ctags and put the information into a 'FileInfo' object
|
2011-01-11 17:36:49 +08:00
|
|
|
function! s:ProcessFile(fname, ftype)
|
2011-01-16 17:02:52 +08:00
|
|
|
if !s:IsValidFile(a:fname, a:ftype)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-05-09 19:40:07 +08:00
|
|
|
let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:ftype)
|
2011-01-12 17:48:04 +08:00
|
|
|
|
2011-05-08 19:08:15 +08:00
|
|
|
if ctags_output == -1
|
2011-04-07 21:00:12 +08:00
|
|
|
" put an empty entry into known_files so the error message is only
|
|
|
|
" shown once
|
|
|
|
call s:known_files.put({}, a:fname)
|
2011-01-11 17:36:49 +08:00
|
|
|
return
|
2011-05-08 19:08:15 +08:00
|
|
|
elseif ctags_output == ''
|
|
|
|
return
|
2011-01-11 17:36:49 +08:00
|
|
|
endif
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" If the file has only been updated preserve the fold states, otherwise
|
|
|
|
" create a new entry
|
2011-04-07 21:00:12 +08:00
|
|
|
if s:known_files.has(a:fname)
|
|
|
|
let fileinfo = s:known_files.get(a:fname)
|
|
|
|
call fileinfo.reset()
|
2011-03-26 22:32:31 +08:00
|
|
|
else
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:FileInfo.New(a:fname, a:ftype)
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-05-08 19:08:15 +08:00
|
|
|
let typeinfo = s:known_types[a:ftype]
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" Parse the ctags output lines
|
|
|
|
let rawtaglist = split(ctags_output, '\n\+')
|
2011-01-16 19:35:05 +08:00
|
|
|
for line in rawtaglist
|
2011-01-18 10:03:27 +08:00
|
|
|
let parts = split(line, ';"')
|
|
|
|
if len(parts) == 2 " Is a valid tag line
|
2011-03-26 22:32:31 +08:00
|
|
|
let taginfo = s:ParseTagline(parts[0], parts[1], typeinfo, fileinfo)
|
2011-01-20 11:51:33 +08:00
|
|
|
let fileinfo.fline[taginfo.fields.line] = taginfo
|
2011-01-18 10:03:27 +08:00
|
|
|
call add(fileinfo.tags, taginfo)
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
endfor
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" Process scoped tags
|
|
|
|
let processedtags = []
|
2011-03-06 14:52:54 +08:00
|
|
|
if has_key(typeinfo, 'kind2scope')
|
2011-01-23 10:09:08 +08:00
|
|
|
let scopedtags = []
|
2011-02-28 13:08:47 +08:00
|
|
|
let is_scoped = 'has_key(typeinfo.kind2scope, v:val.fields.kind) ||
|
|
|
|
\ has_key(v:val, "scope")'
|
|
|
|
let scopedtags += filter(copy(fileinfo.tags), is_scoped)
|
|
|
|
call filter(fileinfo.tags, '!(' . is_scoped . ')')
|
2011-01-16 19:35:05 +08:00
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
call s:AddScopedTags(scopedtags, processedtags, {}, 0,
|
|
|
|
\ typeinfo, fileinfo)
|
2011-01-17 17:58:31 +08:00
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
if !empty(scopedtags)
|
2011-02-14 17:02:44 +08:00
|
|
|
echoerr 'Tagbar: ''scopedtags'' not empty after processing,'
|
|
|
|
\ 'this should never happen!'
|
|
|
|
\ 'Please contact the script maintainer with an example.'
|
2011-02-13 14:20:15 +08:00
|
|
|
endif
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
" Create a placeholder tag for the 'kind' header for folding purposes
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
let curtags = filter(copy(fileinfo.tags),
|
|
|
|
\ 'v:val.fields.kind ==# kind.short')
|
|
|
|
|
|
|
|
if empty(curtags)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let kindtag = s:KindheaderTag.New(kind.long)
|
|
|
|
let kindtag.short = kind.short
|
|
|
|
let kindtag.numtags = len(curtags)
|
|
|
|
let kindtag.fileinfo = fileinfo
|
2011-03-26 22:32:31 +08:00
|
|
|
|
|
|
|
for tag in curtags
|
|
|
|
let tag.parent = kindtag
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if !empty(processedtags)
|
2011-01-21 15:11:15 +08:00
|
|
|
call extend(fileinfo.tags, processedtags)
|
2011-01-16 19:35:05 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
" Clear old folding information from previous file version
|
|
|
|
call fileinfo.clearOldFolds()
|
2011-01-19 12:36:10 +08:00
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" Sort the tags
|
|
|
|
let s:compare_typeinfo = typeinfo
|
2011-04-07 21:00:12 +08:00
|
|
|
call fileinfo.sortTags()
|
2011-01-17 12:08:10 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
call s:known_files.put(fileinfo)
|
2011-01-11 17:36:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-05-09 19:40:07 +08:00
|
|
|
" s:ExecuteCtagsOnFile() {{{2
|
|
|
|
function! s:ExecuteCtagsOnFile(fname, ftype)
|
2011-05-08 19:08:15 +08:00
|
|
|
let typeinfo = s:known_types[a:ftype]
|
|
|
|
|
|
|
|
if has_key(typeinfo, 'ctagsargs')
|
|
|
|
let ctags_args = ' ' . typeinfo.ctagsargs . ' '
|
|
|
|
else
|
|
|
|
let ctags_args = ' -f - '
|
|
|
|
let ctags_args .= ' --format=2 '
|
|
|
|
let ctags_args .= ' --excmd=pattern '
|
|
|
|
let ctags_args .= ' --fields=nksSa '
|
|
|
|
let ctags_args .= ' --extra= '
|
|
|
|
let ctags_args .= ' --sort=yes '
|
|
|
|
|
|
|
|
" Include extra type definitions
|
|
|
|
if has_key(typeinfo, 'deffile')
|
|
|
|
let ctags_args .= ' --options=' . typeinfo.deffile . ' '
|
|
|
|
endif
|
|
|
|
|
|
|
|
let ctags_type = typeinfo.ctagstype
|
|
|
|
|
|
|
|
let ctags_kinds = ''
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
let ctags_kinds .= kind.short
|
|
|
|
endfor
|
|
|
|
|
|
|
|
let ctags_args .= ' --language-force=' . ctags_type .
|
|
|
|
\ ' --' . ctags_type . '-kinds=' . ctags_kinds . ' '
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(typeinfo, 'ctagsbin')
|
|
|
|
let ctags_bin = expand(typeinfo.ctagsbin)
|
|
|
|
else
|
|
|
|
let ctags_bin = g:tagbar_ctags_bin
|
|
|
|
endif
|
|
|
|
|
|
|
|
let ctags_cmd = s:EscapeCtagsCmd(ctags_bin, ctags_args, a:fname)
|
|
|
|
if ctags_cmd == ''
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
2011-05-09 19:40:07 +08:00
|
|
|
let ctags_output = s:ExecuteCtags(ctags_cmd)
|
2011-05-08 19:08:15 +08:00
|
|
|
|
|
|
|
if v:shell_error || ctags_output =~ 'Warning: cannot open source file'
|
|
|
|
echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!'
|
|
|
|
echomsg 'Executed command: "' . ctags_cmd . '"'
|
|
|
|
if !empty(ctags_output)
|
|
|
|
echomsg 'Command output:'
|
|
|
|
for line in split(ctags_output, '\n')
|
|
|
|
echomsg line
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return -1
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ctags_output
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:ParseTagline() {{{2
|
2011-01-21 15:11:15 +08:00
|
|
|
" Structure of a tag line:
|
|
|
|
" tagname<TAB>filename<TAB>expattern;"fields
|
2011-01-14 18:12:26 +08:00
|
|
|
" fields: <TAB>name:value
|
|
|
|
" fields that are always present: kind, line
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:ParseTagline(part1, part2, typeinfo, fileinfo)
|
2011-04-07 21:00:12 +08:00
|
|
|
let basic_info = split(a:part1, '\t')
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let taginfo = s:NormalTag.New(basic_info[0])
|
|
|
|
let taginfo.file = basic_info[1]
|
2011-01-20 15:16:58 +08:00
|
|
|
|
2011-01-24 15:14:28 +08:00
|
|
|
" the pattern can contain tabs and thus may have been split up, so join
|
|
|
|
" the rest of the items together again
|
|
|
|
let pattern = join(basic_info[2:], "\t")
|
2011-01-20 15:16:58 +08:00
|
|
|
let start = 2 " skip the slash and the ^
|
|
|
|
let end = strlen(pattern) - 1
|
2011-04-26 21:01:27 +08:00
|
|
|
if pattern[end - 1] ==# '$'
|
2011-01-20 15:16:58 +08:00
|
|
|
let end -= 1
|
|
|
|
let dollar = '\$'
|
|
|
|
else
|
|
|
|
let dollar = ''
|
|
|
|
endif
|
|
|
|
let pattern = strpart(pattern, start, end - start)
|
2011-06-18 14:10:44 +08:00
|
|
|
let taginfo.pattern = '\V\^\C' . pattern . dollar
|
2011-01-20 15:16:58 +08:00
|
|
|
let prototype = substitute(pattern, '^[[:space:]]\+', '', '')
|
|
|
|
let prototype = substitute(prototype, '[[:space:]]\+$', '', '')
|
|
|
|
let taginfo.prototype = prototype
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-18 10:03:27 +08:00
|
|
|
let fields = split(a:part2, '\t')
|
2011-04-25 15:32:19 +08:00
|
|
|
let taginfo.fields.kind = remove(fields, 0)
|
2011-01-11 17:36:49 +08:00
|
|
|
for field in fields
|
2011-01-12 17:48:04 +08:00
|
|
|
" can't use split() since the value can contain ':'
|
2011-01-14 18:12:26 +08:00
|
|
|
let delimit = stridx(field, ':')
|
|
|
|
let key = strpart(field, 0, delimit)
|
|
|
|
let val = strpart(field, delimit + 1)
|
|
|
|
let taginfo.fields[key] = val
|
2011-01-11 17:36:49 +08:00
|
|
|
endfor
|
2011-04-25 15:32:19 +08:00
|
|
|
" Needed for jsctags
|
|
|
|
if has_key(taginfo.fields, 'lineno')
|
|
|
|
let taginfo.fields.line = taginfo.fields.lineno
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-24 14:48:58 +08:00
|
|
|
" Make some information easier accessible
|
2011-03-06 14:52:54 +08:00
|
|
|
if has_key(a:typeinfo, 'scope2kind')
|
|
|
|
for scope in keys(a:typeinfo.scope2kind)
|
2011-01-25 14:32:30 +08:00
|
|
|
if has_key(taginfo.fields, scope)
|
|
|
|
let taginfo.scope = scope
|
|
|
|
let taginfo.path = taginfo.fields[scope]
|
2011-01-24 14:48:58 +08:00
|
|
|
|
2011-01-25 14:32:30 +08:00
|
|
|
let taginfo.fullpath = taginfo.path . a:typeinfo.sro .
|
|
|
|
\ taginfo.name
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2011-02-07 12:58:33 +08:00
|
|
|
let taginfo.depth = len(split(taginfo.path, '\V' . a:typeinfo.sro))
|
2011-01-25 14:32:30 +08:00
|
|
|
endif
|
2011-01-22 21:22:20 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let taginfo.fileinfo = a:fileinfo
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" Needed for folding
|
2011-04-07 21:00:12 +08:00
|
|
|
call taginfo.initFoldState()
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
return taginfo
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:AddScopedTags() {{{2
|
2011-02-13 14:20:15 +08:00
|
|
|
" Recursively process tags. Unfortunately there is a problem: not all tags in
|
|
|
|
" a hierarchy are actually there. For example, in C++ a class can be defined
|
|
|
|
" in a header file and implemented in a .cpp file (so the class itself doesn't
|
|
|
|
" appear in the .cpp file and thus doesn't generate a tag). Another example
|
|
|
|
" are anonymous structures like namespaces, structs, enums, and unions, that
|
|
|
|
" also don't get a tag themselves. These tags are thus called 'pseudo-tags' in
|
|
|
|
" Tagbar. Properly parsing them is quite tricky, so try not to think about it
|
|
|
|
" too much.
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:AddScopedTags(tags, processedtags, parent, depth,
|
|
|
|
\ typeinfo, fileinfo)
|
2011-03-20 22:02:03 +08:00
|
|
|
if !empty(a:parent)
|
|
|
|
let curpath = a:parent.fullpath
|
|
|
|
let pscope = a:typeinfo.kind2scope[a:parent.fields.kind]
|
|
|
|
else
|
|
|
|
let curpath = ''
|
|
|
|
let pscope = ''
|
|
|
|
endif
|
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
let is_cur_tag = 'v:val.depth == a:depth'
|
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
if !empty(curpath)
|
2011-02-13 14:20:15 +08:00
|
|
|
" Check whether the tag is either a direct child at the current depth
|
|
|
|
" or at least a proper grandchild with pseudo-tags in between. If it
|
|
|
|
" is a direct child also check for matching scope.
|
|
|
|
let is_cur_tag .= ' &&
|
2011-04-26 21:01:27 +08:00
|
|
|
\ (v:val.path ==# curpath ||
|
2011-03-20 22:02:03 +08:00
|
|
|
\ match(v:val.path, ''\V\^\C'' . curpath . a:typeinfo.sro) == 0) &&
|
2011-04-26 21:01:27 +08:00
|
|
|
\ (v:val.path ==# curpath ? (v:val.scope ==# pscope) : 1)'
|
2011-01-21 15:11:15 +08:00
|
|
|
endif
|
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
let curtags = filter(copy(a:tags), is_cur_tag)
|
2011-01-21 15:11:15 +08:00
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
if !empty(curtags)
|
|
|
|
call filter(a:tags, '!(' . is_cur_tag . ')')
|
2011-01-22 21:22:20 +08:00
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
let realtags = []
|
2011-02-13 14:20:15 +08:00
|
|
|
let pseudotags = []
|
2011-01-19 12:19:15 +08:00
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
while !empty(curtags)
|
|
|
|
let tag = remove(curtags, 0)
|
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
if tag.path != curpath
|
2011-02-13 14:20:15 +08:00
|
|
|
" tag is child of a pseudo-tag, so create a new pseudo-tag and
|
|
|
|
" add all its children to it
|
2011-03-20 22:02:03 +08:00
|
|
|
let pseudotag = s:ProcessPseudoTag(curtags, tag, a:parent,
|
2011-03-26 22:32:31 +08:00
|
|
|
\ a:typeinfo, a:fileinfo)
|
2011-02-13 14:20:15 +08:00
|
|
|
|
|
|
|
call add(pseudotags, pseudotag)
|
2011-01-17 17:58:31 +08:00
|
|
|
else
|
2011-02-13 14:20:15 +08:00
|
|
|
call add(realtags, tag)
|
2011-01-17 17:58:31 +08:00
|
|
|
endif
|
2011-02-13 14:20:15 +08:00
|
|
|
endwhile
|
2011-01-17 17:58:31 +08:00
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
" Recursively add the children of the tags on the current level
|
|
|
|
for tag in realtags
|
2011-03-26 22:32:31 +08:00
|
|
|
let tag.parent = a:parent
|
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
if !has_key(a:typeinfo.kind2scope, tag.fields.kind)
|
2011-01-19 12:19:15 +08:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
if !has_key(tag, 'children')
|
|
|
|
let tag.children = []
|
2011-01-19 12:19:15 +08:00
|
|
|
endif
|
2011-02-13 14:20:15 +08:00
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
call s:AddScopedTags(a:tags, tag.children, tag, a:depth + 1,
|
2011-03-26 22:32:31 +08:00
|
|
|
\ a:typeinfo, a:fileinfo)
|
2011-01-17 17:58:31 +08:00
|
|
|
endfor
|
2011-02-13 14:20:15 +08:00
|
|
|
call extend(a:processedtags, realtags)
|
|
|
|
|
|
|
|
" Recursively add the children of the tags that are children of the
|
|
|
|
" pseudo-tags on the current level
|
|
|
|
for tag in pseudotags
|
2011-03-26 22:32:31 +08:00
|
|
|
call s:ProcessPseudoChildren(a:tags, tag, a:depth, a:typeinfo,
|
|
|
|
\ a:fileinfo)
|
2011-02-13 14:20:15 +08:00
|
|
|
endfor
|
|
|
|
call extend(a:processedtags, pseudotags)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Now we have to check if there are any pseudo-tags at the current level
|
|
|
|
" so we have to check for real tags at a lower level, i.e. grandchildren
|
|
|
|
let is_grandchild = 'v:val.depth > a:depth'
|
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
if !empty(curpath)
|
2011-02-13 14:20:15 +08:00
|
|
|
let is_grandchild .=
|
2011-03-20 22:02:03 +08:00
|
|
|
\ ' && match(v:val.path, ''\V\^\C'' . curpath . a:typeinfo.sro) == 0'
|
2011-01-19 12:19:15 +08:00
|
|
|
endif
|
2011-01-17 17:58:31 +08:00
|
|
|
|
2011-01-21 15:11:15 +08:00
|
|
|
let grandchildren = filter(copy(a:tags), is_grandchild)
|
|
|
|
|
|
|
|
if !empty(grandchildren)
|
2011-03-20 22:02:03 +08:00
|
|
|
call s:AddScopedTags(a:tags, a:processedtags, a:parent, a:depth + 1,
|
2011-03-26 22:32:31 +08:00
|
|
|
\ a:typeinfo, a:fileinfo)
|
2011-01-21 15:11:15 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:ProcessPseudoTag() {{{2
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:ProcessPseudoTag(curtags, tag, parent, typeinfo, fileinfo)
|
2011-03-20 22:02:03 +08:00
|
|
|
let curpath = !empty(a:parent) ? a:parent.fullpath : ''
|
|
|
|
|
|
|
|
let pseudoname = substitute(a:tag.path, curpath, '', '')
|
2011-02-13 14:20:15 +08:00
|
|
|
let pseudoname = substitute(pseudoname, '\V\^' . a:typeinfo.sro, '', '')
|
2011-03-26 22:32:31 +08:00
|
|
|
let pseudotag = s:CreatePseudoTag(pseudoname, a:parent, a:tag.scope,
|
|
|
|
\ a:typeinfo, a:fileinfo)
|
2011-02-13 14:20:15 +08:00
|
|
|
let pseudotag.children = [a:tag]
|
|
|
|
|
|
|
|
" get all the other (direct) children of the current pseudo-tag
|
2011-04-26 21:01:27 +08:00
|
|
|
let ispseudochild = 'v:val.path ==# a:tag.path && v:val.scope ==# a:tag.scope'
|
2011-02-13 14:20:15 +08:00
|
|
|
let pseudochildren = filter(copy(a:curtags), ispseudochild)
|
|
|
|
if !empty(pseudochildren)
|
|
|
|
call filter(a:curtags, '!(' . ispseudochild . ')')
|
|
|
|
call extend(pseudotag.children, pseudochildren)
|
2011-01-22 17:16:49 +08:00
|
|
|
endif
|
2011-02-13 14:20:15 +08:00
|
|
|
|
|
|
|
return pseudotag
|
2011-01-22 17:16:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:ProcessPseudoChildren() {{{2
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:ProcessPseudoChildren(tags, tag, depth, typeinfo, fileinfo)
|
2011-02-13 14:20:15 +08:00
|
|
|
for childtag in a:tag.children
|
2011-03-26 22:32:31 +08:00
|
|
|
let childtag.parent = a:tag
|
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
if !has_key(a:typeinfo.kind2scope, childtag.fields.kind)
|
|
|
|
continue
|
|
|
|
endif
|
2011-01-22 17:16:49 +08:00
|
|
|
|
2011-02-13 14:20:15 +08:00
|
|
|
if !has_key(childtag, 'children')
|
|
|
|
let childtag.children = []
|
2011-01-22 17:16:49 +08:00
|
|
|
endif
|
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
call s:AddScopedTags(a:tags, childtag.children, childtag, a:depth + 1,
|
2011-03-26 22:32:31 +08:00
|
|
|
\ a:typeinfo, a:fileinfo)
|
2011-02-13 14:20:15 +08:00
|
|
|
endfor
|
|
|
|
|
|
|
|
let is_grandchild = 'v:val.depth > a:depth &&
|
|
|
|
\ match(v:val.path, ''^\C'' . a:tag.fullpath) == 0'
|
|
|
|
let grandchildren = filter(copy(a:tags), is_grandchild)
|
|
|
|
if !empty(grandchildren)
|
2011-03-20 22:02:03 +08:00
|
|
|
call s:AddScopedTags(a:tags, a:tag.children, a:tag, a:depth + 1,
|
2011-03-26 22:32:31 +08:00
|
|
|
\ a:typeinfo, a:fileinfo)
|
2011-02-13 14:20:15 +08:00
|
|
|
endif
|
2011-01-22 17:16:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:CreatePseudoTag() {{{2
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:CreatePseudoTag(name, parent, scope, typeinfo, fileinfo)
|
2011-03-20 22:02:03 +08:00
|
|
|
if !empty(a:parent)
|
|
|
|
let curpath = a:parent.fullpath
|
|
|
|
let pscope = a:typeinfo.kind2scope[a:parent.fields.kind]
|
|
|
|
else
|
|
|
|
let curpath = ''
|
|
|
|
let pscope = ''
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let pseudotag = s:PseudoTag.New(a:name)
|
2011-01-22 17:16:49 +08:00
|
|
|
let pseudotag.fields.kind = a:typeinfo.scope2kind[a:scope]
|
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
let parentscope = substitute(curpath, a:name . '$', '', '')
|
2011-01-24 14:48:58 +08:00
|
|
|
let parentscope = substitute(parentscope,
|
|
|
|
\ '\V\^' . a:typeinfo.sro . '\$', '', '')
|
2011-01-22 21:22:20 +08:00
|
|
|
|
2011-03-20 22:02:03 +08:00
|
|
|
if pscope != ''
|
|
|
|
let pseudotag.fields[pscope] = parentscope
|
|
|
|
let pseudotag.scope = pscope
|
2011-01-24 14:48:58 +08:00
|
|
|
let pseudotag.path = parentscope
|
|
|
|
let pseudotag.fullpath =
|
|
|
|
\ pseudotag.path . a:typeinfo.sro . pseudotag.name
|
2011-01-22 17:16:49 +08:00
|
|
|
endif
|
2011-02-06 16:22:56 +08:00
|
|
|
let pseudotag.depth = len(split(pseudotag.path, '\V' . a:typeinfo.sro))
|
2011-01-22 17:16:49 +08:00
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
let pseudotag.parent = a:parent
|
2011-04-07 21:00:12 +08:00
|
|
|
|
|
|
|
let pseudotag.fileinfo = a:fileinfo
|
|
|
|
|
|
|
|
call pseudotag.initFoldState()
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-01-22 21:22:20 +08:00
|
|
|
return pseudotag
|
2011-01-17 17:58:31 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" Sorting {{{1
|
|
|
|
" s:SortTags() {{{2
|
2011-01-20 13:16:57 +08:00
|
|
|
function! s:SortTags(tags, comparemethod)
|
|
|
|
call sort(a:tags, a:comparemethod)
|
|
|
|
|
|
|
|
for tag in a:tags
|
|
|
|
if has_key(tag, 'children')
|
|
|
|
call s:SortTags(tag.children, a:comparemethod)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:CompareByKind() {{{2
|
2011-01-17 12:08:10 +08:00
|
|
|
function! s:CompareByKind(tag1, tag2)
|
|
|
|
let typeinfo = s:compare_typeinfo
|
|
|
|
|
2011-04-26 21:01:27 +08:00
|
|
|
if typeinfo.kinddict[a:tag1.fields.kind] <#
|
2011-01-17 12:08:10 +08:00
|
|
|
\ typeinfo.kinddict[a:tag2.fields.kind]
|
|
|
|
return -1
|
2011-04-26 21:01:27 +08:00
|
|
|
elseif typeinfo.kinddict[a:tag1.fields.kind] >#
|
2011-01-17 12:08:10 +08:00
|
|
|
\ typeinfo.kinddict[a:tag2.fields.kind]
|
|
|
|
return 1
|
|
|
|
else
|
2011-02-14 11:28:56 +08:00
|
|
|
" Ignore '~' prefix for C++ destructors to sort them directly under
|
|
|
|
" the constructors
|
2011-04-26 21:01:27 +08:00
|
|
|
if a:tag1.name[0] ==# '~'
|
2011-02-14 11:28:56 +08:00
|
|
|
let name1 = a:tag1.name[1:]
|
|
|
|
else
|
|
|
|
let name1 = a:tag1.name
|
|
|
|
endif
|
2011-04-26 21:01:27 +08:00
|
|
|
if a:tag2.name[0] ==# '~'
|
2011-02-14 11:28:56 +08:00
|
|
|
let name2 = a:tag2.name[1:]
|
|
|
|
else
|
|
|
|
let name2 = a:tag2.name
|
|
|
|
endif
|
|
|
|
|
2011-04-26 21:01:27 +08:00
|
|
|
if name1 <=# name2
|
2011-01-17 12:08:10 +08:00
|
|
|
return -1
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:CompareByLine() {{{2
|
2011-01-17 12:08:10 +08:00
|
|
|
function! s:CompareByLine(tag1, tag2)
|
|
|
|
return a:tag1.fields.line - a:tag2.fields.line
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:ToggleSort() {{{2
|
|
|
|
function! s:ToggleSort()
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
if empty(fileinfo)
|
2011-02-14 18:47:18 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
|
|
|
|
match none
|
|
|
|
|
|
|
|
let s:compare_typeinfo = s:known_types[fileinfo.ftype]
|
|
|
|
|
|
|
|
if has_key(s:compare_typeinfo, 'sort')
|
|
|
|
let s:compare_typeinfo.sort = !s:compare_typeinfo.sort
|
|
|
|
else
|
|
|
|
let g:tagbar_sort = !g:tagbar_sort
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
call fileinfo.sortTags()
|
2011-02-14 18:47:18 +08:00
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
call s:RenderContent()
|
2011-02-14 18:47:18 +08:00
|
|
|
|
|
|
|
execute curline
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Display {{{1
|
|
|
|
" s:RenderContent() {{{2
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:RenderContent(...)
|
|
|
|
if a:0 == 1
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = a:1
|
2011-03-26 22:32:31 +08:00
|
|
|
else
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
if empty(fileinfo)
|
2011-03-26 22:32:31 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
|
2011-01-20 13:16:57 +08:00
|
|
|
if &filetype == 'tagbar'
|
|
|
|
let in_tagbar = 1
|
|
|
|
else
|
|
|
|
let in_tagbar = 0
|
2011-02-19 12:50:29 +08:00
|
|
|
let prevwinnr = winnr()
|
2011-01-20 13:16:57 +08:00
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
if !empty(s:known_files.getCurrent()) &&
|
2011-04-26 21:01:27 +08:00
|
|
|
\ fileinfo.fpath ==# s:known_files.getCurrent().fpath
|
2011-03-21 20:36:28 +08:00
|
|
|
" We're redisplaying the same file, so save the view
|
|
|
|
let saveline = line('.')
|
|
|
|
let savecol = col('.')
|
|
|
|
let topline = line('w0')
|
|
|
|
endif
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
let lazyredraw_save = &lazyredraw
|
|
|
|
set lazyredraw
|
2011-05-15 14:25:03 +08:00
|
|
|
let eventignore_save = &eventignore
|
|
|
|
set eventignore=all
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-01-11 17:36:49 +08:00
|
|
|
setlocal modifiable
|
|
|
|
|
2011-04-08 09:17:50 +08:00
|
|
|
silent %delete _
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-21 19:27:50 +08:00
|
|
|
call s:PrintHelp()
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
let typeinfo = s:known_types[fileinfo.ftype]
|
2011-02-05 14:32:49 +08:00
|
|
|
|
2011-01-17 10:54:12 +08:00
|
|
|
" Print tags
|
2011-03-27 11:46:41 +08:00
|
|
|
call s:PrintKinds(typeinfo, fileinfo)
|
|
|
|
|
2011-04-07 23:15:52 +08:00
|
|
|
" Delete empty lines at the end of the buffer
|
|
|
|
for linenr in range(line('$'), 1, -1)
|
|
|
|
if getline(linenr) =~ '^$'
|
2011-04-08 08:53:50 +08:00
|
|
|
execute linenr . 'delete _'
|
2011-04-07 23:15:52 +08:00
|
|
|
else
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2011-03-27 11:46:41 +08:00
|
|
|
setlocal nomodifiable
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
if !empty(s:known_files.getCurrent()) &&
|
2011-04-26 21:01:27 +08:00
|
|
|
\ fileinfo.fpath ==# s:known_files.getCurrent().fpath
|
2011-03-27 11:46:41 +08:00
|
|
|
let scrolloff_save = &scrolloff
|
|
|
|
set scrolloff=0
|
|
|
|
|
|
|
|
call cursor(topline, 1)
|
|
|
|
normal! zt
|
|
|
|
call cursor(saveline, savecol)
|
|
|
|
|
|
|
|
let &scrolloff = scrolloff_save
|
|
|
|
else
|
|
|
|
" Make sure as much of the Tagbar content as possible is shown in the
|
|
|
|
" window by jumping to the top after drawing
|
|
|
|
execute 1
|
|
|
|
call winline()
|
|
|
|
endif
|
|
|
|
|
2011-05-15 14:25:03 +08:00
|
|
|
let &lazyredraw = lazyredraw_save
|
|
|
|
let &eventignore = eventignore_save
|
2011-03-27 11:46:41 +08:00
|
|
|
|
|
|
|
if !in_tagbar
|
|
|
|
execute prevwinnr . 'wincmd w'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:PrintKinds() {{{2
|
|
|
|
function! s:PrintKinds(typeinfo, fileinfo)
|
2011-04-25 15:32:19 +08:00
|
|
|
let first_tag = 1
|
2011-03-27 11:46:41 +08:00
|
|
|
|
|
|
|
for kind in a:typeinfo.kinds
|
|
|
|
let curtags = filter(copy(a:fileinfo.tags),
|
2011-03-26 22:32:31 +08:00
|
|
|
\ 'v:val.fields.kind ==# kind.short')
|
2011-01-12 17:48:04 +08:00
|
|
|
|
|
|
|
if empty(curtags)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2011-03-27 11:46:41 +08:00
|
|
|
if has_key(a:typeinfo, 'kind2scope') &&
|
|
|
|
\ has_key(a:typeinfo.kind2scope, kind.short)
|
2011-01-17 10:54:12 +08:00
|
|
|
" Scoped tags
|
|
|
|
for tag in curtags
|
2011-04-25 15:32:19 +08:00
|
|
|
if g:tagbar_compact && first_tag && s:short_help
|
2011-04-25 22:18:55 +08:00
|
|
|
silent 0put =tag.str()
|
2011-02-14 11:11:59 +08:00
|
|
|
else
|
2011-04-25 22:18:55 +08:00
|
|
|
silent put =tag.str()
|
2011-02-14 11:11:59 +08:00
|
|
|
endif
|
2011-01-12 17:48:04 +08:00
|
|
|
|
2011-01-20 11:51:33 +08:00
|
|
|
" Save the current tagbar line in the tag for easy
|
|
|
|
" highlighting access
|
2011-03-27 11:46:41 +08:00
|
|
|
let curline = line('.')
|
|
|
|
let tag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = tag
|
2011-01-20 11:51:33 +08:00
|
|
|
|
2011-04-12 19:36:48 +08:00
|
|
|
if tag.isFoldable() && !tag.isFolded()
|
2011-01-21 15:11:15 +08:00
|
|
|
for childtag in tag.children
|
2011-03-27 11:46:41 +08:00
|
|
|
call s:PrintTag(childtag, 1, a:fileinfo, a:typeinfo)
|
2011-01-21 15:11:15 +08:00
|
|
|
endfor
|
|
|
|
endif
|
2011-01-12 17:48:04 +08:00
|
|
|
|
2011-02-14 11:11:59 +08:00
|
|
|
if !g:tagbar_compact
|
2011-04-07 21:00:12 +08:00
|
|
|
silent put _
|
2011-02-14 11:11:59 +08:00
|
|
|
endif
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-04-25 15:32:19 +08:00
|
|
|
let first_tag = 0
|
2011-01-17 10:54:12 +08:00
|
|
|
endfor
|
|
|
|
else
|
|
|
|
" Non-scoped tags
|
2011-04-12 19:36:48 +08:00
|
|
|
let kindtag = curtags[0].parent
|
|
|
|
|
|
|
|
if kindtag.isFolded()
|
2011-03-27 20:29:25 +08:00
|
|
|
let foldmarker = s:icon_closed
|
2011-02-14 11:11:59 +08:00
|
|
|
else
|
2011-03-27 20:29:25 +08:00
|
|
|
let foldmarker = s:icon_open
|
2011-02-14 11:11:59 +08:00
|
|
|
endif
|
2011-01-17 10:54:12 +08:00
|
|
|
|
2011-04-25 15:32:19 +08:00
|
|
|
if g:tagbar_compact && first_tag && s:short_help
|
2011-04-07 21:00:12 +08:00
|
|
|
silent 0put =foldmarker . ' ' . kind.long
|
2011-03-26 22:32:31 +08:00
|
|
|
else
|
2011-04-07 21:00:12 +08:00
|
|
|
silent put =foldmarker . ' ' . kind.long
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
2011-01-20 11:51:33 +08:00
|
|
|
|
2011-03-27 11:46:41 +08:00
|
|
|
let curline = line('.')
|
|
|
|
let kindtag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = kindtag
|
2011-01-20 11:51:33 +08:00
|
|
|
|
2011-04-12 19:36:48 +08:00
|
|
|
if !kindtag.isFolded()
|
2011-03-26 22:32:31 +08:00
|
|
|
for tag in curtags
|
2011-04-25 22:18:55 +08:00
|
|
|
let str = tag.str()
|
2011-04-07 21:00:12 +08:00
|
|
|
silent put =' ' . str
|
2011-03-26 22:32:31 +08:00
|
|
|
|
|
|
|
" Save the current tagbar line in the tag for easy
|
|
|
|
" highlighting access
|
2011-03-27 11:46:41 +08:00
|
|
|
let curline = line('.')
|
|
|
|
let tag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = tag
|
|
|
|
let tag.depth = 1
|
2011-03-26 22:32:31 +08:00
|
|
|
endfor
|
|
|
|
endif
|
2011-01-17 10:54:12 +08:00
|
|
|
|
2011-02-14 11:11:59 +08:00
|
|
|
if !g:tagbar_compact
|
2011-04-07 21:00:12 +08:00
|
|
|
silent put _
|
2011-02-14 11:11:59 +08:00
|
|
|
endif
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-04-25 15:32:19 +08:00
|
|
|
let first_tag = 0
|
2011-01-17 10:54:12 +08:00
|
|
|
endif
|
2011-01-11 17:36:49 +08:00
|
|
|
endfor
|
2011-03-26 22:32:31 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:PrintTag() {{{2
|
2011-01-20 15:16:58 +08:00
|
|
|
function! s:PrintTag(tag, depth, fileinfo, typeinfo)
|
2011-01-16 12:46:14 +08:00
|
|
|
" Print tag indented according to depth
|
2011-04-25 22:18:55 +08:00
|
|
|
silent put =repeat(' ', a:depth * 2) . a:tag.str()
|
2011-01-16 12:46:14 +08:00
|
|
|
|
2011-01-20 11:51:33 +08:00
|
|
|
" Save the current tagbar line in the tag for easy
|
|
|
|
" highlighting access
|
2011-01-20 15:16:58 +08:00
|
|
|
let curline = line('.')
|
|
|
|
let a:tag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = a:tag
|
2011-01-20 11:51:33 +08:00
|
|
|
|
2011-01-16 12:46:14 +08:00
|
|
|
" Recursively print children
|
2011-04-12 19:36:48 +08:00
|
|
|
if a:tag.isFoldable() && !a:tag.isFolded()
|
2011-01-16 12:46:14 +08:00
|
|
|
for childtag in a:tag.children
|
2011-01-20 15:16:58 +08:00
|
|
|
call s:PrintTag(childtag, a:depth + 1, a:fileinfo, a:typeinfo)
|
2011-01-16 12:46:14 +08:00
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:PrintHelp() {{{2
|
|
|
|
function! s:PrintHelp()
|
|
|
|
if !g:tagbar_compact && s:short_help
|
2011-04-08 09:17:50 +08:00
|
|
|
silent 0put ='\" Press <F1> for help'
|
|
|
|
silent put _
|
2011-02-14 18:47:18 +08:00
|
|
|
elseif !s:short_help
|
2011-04-08 09:17:50 +08:00
|
|
|
silent 0put ='\" Tagbar keybindings'
|
|
|
|
silent put ='\"'
|
|
|
|
silent put ='\" --------- General ---------'
|
|
|
|
silent put ='\" <Enter> : Jump to tag definition'
|
|
|
|
silent put ='\" <Space> : Display tag prototype'
|
|
|
|
silent put ='\"'
|
|
|
|
silent put ='\" ---------- Folds ----------'
|
|
|
|
silent put ='\" +, zo : Open fold'
|
|
|
|
silent put ='\" -, zc : Close fold'
|
|
|
|
silent put ='\" o, za : Toggle fold'
|
|
|
|
silent put ='\" *, zR : Open all folds'
|
|
|
|
silent put ='\" =, zM : Close all folds'
|
|
|
|
silent put ='\"'
|
|
|
|
silent put ='\" ---------- Misc -----------'
|
|
|
|
silent put ='\" s : Toggle sort'
|
|
|
|
silent put ='\" x : Zoom window in/out'
|
|
|
|
silent put ='\" q : Close window'
|
|
|
|
silent put ='\" <F1> : Remove help'
|
|
|
|
silent put _
|
2011-02-14 18:47:18 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-03-27 11:46:41 +08:00
|
|
|
" s:RenderKeepView() {{{2
|
|
|
|
" The gist of this function was taken from NERDTree by Martin Grenfell.
|
|
|
|
function! s:RenderKeepView(...)
|
|
|
|
if a:0 == 1
|
|
|
|
let line = a:1
|
|
|
|
else
|
|
|
|
let line = line('.')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curcol = col('.')
|
|
|
|
let topline = line('w0')
|
|
|
|
|
|
|
|
call s:RenderContent()
|
|
|
|
|
|
|
|
let scrolloff_save = &scrolloff
|
|
|
|
set scrolloff=0
|
|
|
|
|
|
|
|
call cursor(topline, 1)
|
|
|
|
normal! zt
|
|
|
|
call cursor(line, curcol)
|
|
|
|
|
|
|
|
let &scrolloff = scrolloff_save
|
|
|
|
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" User actions {{{1
|
|
|
|
" s:HighlightTag() {{{2
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:HighlightTag()
|
2011-01-20 11:51:33 +08:00
|
|
|
let tagline = 0
|
|
|
|
|
2011-04-24 18:53:07 +08:00
|
|
|
let tag = s:GetNearbyTag()
|
|
|
|
if !empty(tag)
|
|
|
|
let tagline = tag.tline
|
|
|
|
endif
|
2011-01-20 11:51:33 +08:00
|
|
|
|
|
|
|
let eventignore_save = &eventignore
|
|
|
|
set eventignore=all
|
|
|
|
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
2011-02-19 12:50:29 +08:00
|
|
|
let prevwinnr = winnr()
|
2011-01-20 11:51:33 +08:00
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
|
|
|
|
match none
|
|
|
|
|
2011-03-02 18:31:58 +08:00
|
|
|
" No tag above cursor position so don't do anything
|
2011-01-20 11:51:33 +08:00
|
|
|
if tagline == 0
|
2011-02-19 12:50:29 +08:00
|
|
|
execute prevwinnr . 'wincmd w'
|
2011-01-20 11:51:33 +08:00
|
|
|
let &eventignore = eventignore_save
|
2011-03-11 14:29:27 +08:00
|
|
|
redraw
|
2011-01-20 11:51:33 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-24 18:53:07 +08:00
|
|
|
if g:tagbar_autoshowtag
|
|
|
|
call s:OpenParents(tag)
|
|
|
|
endif
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" Check whether the tag is inside a closed fold and highlight the parent
|
|
|
|
" instead in that case
|
2011-04-07 21:00:12 +08:00
|
|
|
let tagline = tag.getClosedParentTline()
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-01-20 11:51:33 +08:00
|
|
|
" Go to the line containing the tag
|
|
|
|
execute tagline
|
|
|
|
|
|
|
|
" Make sure the tag is visible in the window
|
|
|
|
call winline()
|
|
|
|
|
2011-03-27 20:29:25 +08:00
|
|
|
let foldpat = '[' . s:icon_open . s:icon_closed . ' ]'
|
|
|
|
let pattern = '/^\%' . tagline . 'l\s*' . foldpat . '[-+# ]\zs[^( ]\+\ze/'
|
2011-04-13 23:59:13 +08:00
|
|
|
execute 'match TagbarHighlight ' . pattern
|
2011-01-20 11:51:33 +08:00
|
|
|
|
2011-02-19 12:50:29 +08:00
|
|
|
execute prevwinnr . 'wincmd w'
|
2011-01-20 11:51:33 +08:00
|
|
|
|
|
|
|
let &eventignore = eventignore_save
|
2011-03-02 18:29:36 +08:00
|
|
|
|
2011-03-11 14:29:27 +08:00
|
|
|
redraw
|
2011-01-20 11:51:33 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:JumpToTag() {{{2
|
2011-04-25 12:09:40 +08:00
|
|
|
function! s:JumpToTag(stay_in_tagbar)
|
2011-03-26 22:32:31 +08:00
|
|
|
let taginfo = s:GetTagInfo(line('.'), 1)
|
2011-01-20 15:16:58 +08:00
|
|
|
|
2011-02-14 18:32:57 +08:00
|
|
|
let autoclose = w:autoclose
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
if empty(taginfo) || has_key(taginfo, 'numtags')
|
2011-01-20 15:16:58 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-25 12:09:40 +08:00
|
|
|
let tagbarwinnr = winnr()
|
2011-04-27 11:48:07 +08:00
|
|
|
|
|
|
|
" This elaborate construct will try to switch to the correct
|
|
|
|
" buffer/window; if the buffer isn't currently shown in a window it will
|
|
|
|
" open it in the first window with a non-special buffer in it
|
2011-01-20 15:16:58 +08:00
|
|
|
execute 'wincmd p'
|
2011-04-27 11:48:07 +08:00
|
|
|
let filebufnr = bufnr(taginfo.fileinfo.fpath)
|
|
|
|
if bufnr('%') != filebufnr
|
|
|
|
let filewinnr = bufwinnr(filebufnr)
|
|
|
|
if filewinnr != -1
|
|
|
|
execute filewinnr . 'wincmd w'
|
|
|
|
else
|
|
|
|
for i in range(1, winnr('$'))
|
|
|
|
execute i . 'wincmd w'
|
|
|
|
if &buftype == ''
|
|
|
|
execute 'buffer ' . filebufnr
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
" To make ctrl-w_p work we switch between the Tagbar window and the
|
|
|
|
" correct window once
|
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
execute 'wincmd p'
|
|
|
|
endif
|
2011-01-20 15:16:58 +08:00
|
|
|
|
2011-02-01 10:28:48 +08:00
|
|
|
" Mark current position so it can be jumped back to
|
|
|
|
mark '
|
|
|
|
|
2011-01-20 15:16:58 +08:00
|
|
|
" Jump to the line where the tag is defined. Don't use the search pattern
|
|
|
|
" since it doesn't take the scope into account and thus can fail if tags
|
|
|
|
" with the same name are defined in different scopes (e.g. classes)
|
|
|
|
execute taginfo.fields.line
|
|
|
|
|
2011-06-18 14:10:44 +08:00
|
|
|
" If the file has been changed but not saved, the tag may not be on the
|
|
|
|
" saved line anymore, so search for it in the vicinity of the saved line
|
|
|
|
if match(getline('.'), taginfo.pattern) == -1
|
|
|
|
let interval = 1
|
|
|
|
let forward = 1
|
|
|
|
while search(taginfo.pattern, 'W' . forward ? '' : 'b') == 0
|
|
|
|
if !forward
|
|
|
|
if interval > line('$')
|
|
|
|
break
|
|
|
|
else
|
|
|
|
let interval = interval * 2
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let forward = !forward
|
|
|
|
endwhile
|
|
|
|
endif
|
|
|
|
|
2011-01-20 15:16:58 +08:00
|
|
|
" Center the tag in the window
|
|
|
|
normal! z.
|
|
|
|
|
|
|
|
if foldclosed('.') != -1
|
|
|
|
.foldopen!
|
|
|
|
endif
|
|
|
|
|
2011-03-11 14:29:27 +08:00
|
|
|
redraw
|
2011-03-02 18:29:36 +08:00
|
|
|
|
2011-04-25 12:09:40 +08:00
|
|
|
if a:stay_in_tagbar
|
|
|
|
call s:HighlightTag()
|
|
|
|
execute tagbarwinnr . 'wincmd w'
|
|
|
|
elseif g:tagbar_autoclose || autoclose
|
2011-01-20 15:16:58 +08:00
|
|
|
call s:CloseWindow()
|
|
|
|
else
|
2011-03-26 22:32:31 +08:00
|
|
|
call s:HighlightTag()
|
2011-01-20 15:16:58 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:ShowPrototype() {{{2
|
2011-01-20 16:03:56 +08:00
|
|
|
function! s:ShowPrototype()
|
2011-03-26 22:32:31 +08:00
|
|
|
let taginfo = s:GetTagInfo(line('.'), 1)
|
2011-01-20 16:03:56 +08:00
|
|
|
|
|
|
|
if empty(taginfo)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
echo taginfo.getPrototype()
|
2011-03-26 22:32:31 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ToggleHelp() {{{2
|
|
|
|
function! s:ToggleHelp()
|
|
|
|
let s:short_help = !s:short_help
|
|
|
|
|
|
|
|
" Prevent highlighting from being off after adding/removing the help text
|
|
|
|
match none
|
|
|
|
|
|
|
|
call s:RenderContent()
|
|
|
|
|
|
|
|
execute 1
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
2011-04-24 09:58:06 +08:00
|
|
|
" s:GotoNextToplevelTag() {{{2
|
|
|
|
function! s:GotoNextToplevelTag(direction)
|
|
|
|
let curlinenr = line('.')
|
|
|
|
let newlinenr = line('.')
|
|
|
|
|
|
|
|
if a:direction == 1
|
|
|
|
let range = range(line('.') + 1, line('$'))
|
|
|
|
else
|
|
|
|
let range = range(line('.') - 1, 1, -1)
|
|
|
|
endif
|
|
|
|
|
|
|
|
for tmplinenr in range
|
|
|
|
let taginfo = s:GetTagInfo(tmplinenr, 0)
|
|
|
|
|
|
|
|
if empty(taginfo)
|
|
|
|
continue
|
|
|
|
elseif empty(taginfo.parent)
|
|
|
|
let newlinenr = tmplinenr
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if curlinenr != newlinenr
|
|
|
|
execute newlinenr
|
|
|
|
call winline()
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
" Folding {{{1
|
|
|
|
" s:OpenFold() {{{2
|
|
|
|
function! s:OpenFold()
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
if empty(fileinfo)
|
2011-03-26 22:32:31 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
|
|
|
|
let tag = s:GetTagInfo(curline, 0)
|
|
|
|
if empty(tag)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
call tag.openFold()
|
2011-03-26 22:32:31 +08:00
|
|
|
|
|
|
|
call s:RenderKeepView()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CloseFold() {{{2
|
|
|
|
function! s:CloseFold()
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
if empty(fileinfo)
|
2011-03-26 22:32:31 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
match none
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
|
|
|
|
let curtag = s:GetTagInfo(curline, 0)
|
|
|
|
if empty(curtag)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let newline = curtag.closeFold()
|
2011-03-26 22:32:31 +08:00
|
|
|
|
|
|
|
call s:RenderKeepView(newline)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ToggleFold() {{{2
|
|
|
|
function! s:ToggleFold()
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
if empty(fileinfo)
|
2011-03-26 22:32:31 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
match none
|
|
|
|
|
|
|
|
let curtag = s:GetTagInfo(line('.'), 0)
|
|
|
|
if empty(curtag)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let newline = line('.')
|
2011-03-26 22:32:31 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
if curtag.isKindheader()
|
|
|
|
call curtag.toggleFold()
|
|
|
|
elseif curtag.isFoldable()
|
|
|
|
if curtag.isFolded()
|
|
|
|
call curtag.openFold()
|
2011-03-26 22:32:31 +08:00
|
|
|
else
|
2011-04-07 21:00:12 +08:00
|
|
|
let newline = curtag.closeFold()
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
2011-04-07 21:00:12 +08:00
|
|
|
else
|
|
|
|
let newline = curtag.closeFold()
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
call s:RenderKeepView(newline)
|
2011-03-26 22:32:31 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:SetFoldLevel() {{{2
|
2011-04-07 21:00:12 +08:00
|
|
|
function! s:SetFoldLevel(level)
|
2011-03-26 22:32:31 +08:00
|
|
|
if a:level < 0
|
|
|
|
echoerr 'Foldlevel can''t be negative'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
if empty(fileinfo)
|
2011-03-26 22:32:31 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
call s:SetFoldLevelRecursive(fileinfo, fileinfo.tags, a:level)
|
2011-03-26 22:32:31 +08:00
|
|
|
|
|
|
|
let typeinfo = s:known_types[fileinfo.ftype]
|
|
|
|
|
|
|
|
" Apply foldlevel to 'kind's
|
2011-04-07 21:00:12 +08:00
|
|
|
if a:level == 0
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
call fileinfo.closeKindFold(kind)
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
call fileinfo.openKindFold(kind)
|
|
|
|
endfor
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
|
2011-03-27 14:47:56 +08:00
|
|
|
let fileinfo.foldlevel = a:level
|
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
call s:RenderContent()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:SetFoldLevelRecursive() {{{2
|
|
|
|
" Apply foldlevel to normal tags
|
2011-04-07 21:00:12 +08:00
|
|
|
function! s:SetFoldLevelRecursive(fileinfo, tags, level)
|
2011-03-26 22:32:31 +08:00
|
|
|
for tag in a:tags
|
2011-04-07 21:00:12 +08:00
|
|
|
if tag.depth >= a:level
|
|
|
|
call tag.setFolded(1)
|
|
|
|
else
|
|
|
|
call tag.setFolded(0)
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(tag, 'children')
|
2011-04-07 21:00:12 +08:00
|
|
|
call s:SetFoldLevelRecursive(a:fileinfo, tag.children, a:level)
|
2011-03-26 22:32:31 +08:00
|
|
|
endif
|
|
|
|
endfor
|
2011-01-20 16:03:56 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-04-24 18:53:07 +08:00
|
|
|
" s:OpenParents() {{{2
|
|
|
|
function! s:OpenParents(...)
|
|
|
|
let tagline = 0
|
|
|
|
|
|
|
|
if a:0 == 1
|
|
|
|
let tag = a:1
|
|
|
|
else
|
|
|
|
let tag = s:GetNearbyTag()
|
|
|
|
endif
|
|
|
|
|
|
|
|
call tag.openParents()
|
|
|
|
|
|
|
|
call s:RenderKeepView()
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" Helper functions {{{1
|
|
|
|
" s:CleanUp() {{{2
|
|
|
|
function! s:CleanUp()
|
2011-04-08 09:17:50 +08:00
|
|
|
silent autocmd! TagbarAutoCmds
|
2011-02-26 15:51:15 +08:00
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
unlet s:is_maximized
|
|
|
|
unlet s:compare_typeinfo
|
|
|
|
unlet s:short_help
|
|
|
|
endfunction
|
|
|
|
|
2011-04-24 16:15:02 +08:00
|
|
|
" s:CleanupFileinfo() {{{2
|
|
|
|
function! s:CleanupFileinfo(fname)
|
|
|
|
call s:known_files.rm(a:fname)
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:QuitIfOnlyWindow() {{{2
|
|
|
|
function! s:QuitIfOnlyWindow()
|
|
|
|
" Before quitting Vim, delete the tagbar buffer so that
|
|
|
|
" the '0 mark is correctly set to the previous buffer.
|
|
|
|
if winbufnr(2) == -1
|
|
|
|
" Check if there is more than one tab page
|
|
|
|
if tabpagenr('$') == 1
|
|
|
|
bdelete
|
|
|
|
quit
|
|
|
|
else
|
|
|
|
close
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:AutoUpdate() {{{2
|
|
|
|
function! s:AutoUpdate(fname)
|
2011-02-17 12:33:59 +08:00
|
|
|
" Don't do anything if tagbar is not open or if we're in the tagbar window
|
2011-02-14 18:47:18 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
2011-05-07 14:04:01 +08:00
|
|
|
if tagbarwinnr == -1 || &filetype == 'tagbar'
|
2011-02-14 18:47:18 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-05-06 23:46:56 +08:00
|
|
|
" Only consider the main filetype in cases like 'python.django'
|
2011-05-07 14:04:01 +08:00
|
|
|
let ftype = get(split(&filetype, '\.'), 0, '')
|
2011-05-06 23:46:56 +08:00
|
|
|
|
2011-02-17 12:33:59 +08:00
|
|
|
" Don't do anything if the file isn't supported
|
2011-05-06 23:46:56 +08:00
|
|
|
if !s:IsValidFile(a:fname, ftype)
|
2011-02-14 18:47:18 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-02-17 12:33:59 +08:00
|
|
|
" Process the file if it's unknown or the information is outdated
|
2011-04-07 21:00:12 +08:00
|
|
|
" Also test for entries that exist but are empty, which will be the case
|
|
|
|
" if there was an error during the ctags execution
|
|
|
|
if s:known_files.has(a:fname) && !empty(s:known_files.get(a:fname))
|
|
|
|
if s:known_files.get(a:fname).mtime != getftime(a:fname)
|
2011-04-07 22:42:08 +08:00
|
|
|
call s:ProcessFile(a:fname, ftype)
|
2011-02-14 18:47:18 +08:00
|
|
|
endif
|
2011-04-07 21:00:12 +08:00
|
|
|
elseif !s:known_files.has(a:fname)
|
2011-04-07 22:42:08 +08:00
|
|
|
call s:ProcessFile(a:fname, ftype)
|
2011-02-14 18:47:18 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.get(a:fname)
|
2011-02-14 18:47:18 +08:00
|
|
|
|
2011-02-17 12:33:59 +08:00
|
|
|
" If we don't have an entry for the file by now something must have gone
|
2011-04-07 21:00:12 +08:00
|
|
|
" wrong, so don't change the tagbar content
|
|
|
|
if empty(fileinfo)
|
2011-02-17 12:33:59 +08:00
|
|
|
return
|
2011-02-14 18:47:18 +08:00
|
|
|
endif
|
2011-02-17 12:33:59 +08:00
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
" Display the tagbar content
|
|
|
|
call s:RenderContent(fileinfo)
|
|
|
|
|
|
|
|
" Call setCurrent after rendering so RenderContent can check whether the
|
|
|
|
" same file is redisplayed
|
|
|
|
if !empty(fileinfo)
|
|
|
|
call s:known_files.setCurrent(fileinfo)
|
|
|
|
endif
|
2011-02-17 12:33:59 +08:00
|
|
|
|
2011-03-26 22:32:31 +08:00
|
|
|
call s:HighlightTag()
|
2011-02-14 18:47:18 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:IsValidFile() {{{2
|
|
|
|
function! s:IsValidFile(fname, ftype)
|
|
|
|
if a:fname == '' || a:ftype == ''
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !filereadable(a:fname)
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !has_key(s:known_types, a:ftype)
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
2011-05-07 14:02:03 +08:00
|
|
|
" s:EscapeCtagsCmd() {{{2
|
2011-05-09 19:40:07 +08:00
|
|
|
" Assemble the ctags command line in a way that all problematic characters are
|
|
|
|
" properly escaped and converted to the system's encoding
|
|
|
|
" Optional third parameter is a file name to run ctags on
|
2011-05-07 14:02:03 +08:00
|
|
|
function! s:EscapeCtagsCmd(ctags_bin, args, ...)
|
2011-05-09 19:40:07 +08:00
|
|
|
if exists('+shellslash')
|
|
|
|
let shellslash_save = &shellslash
|
|
|
|
set noshellslash
|
|
|
|
endif
|
|
|
|
|
2011-05-07 14:02:03 +08:00
|
|
|
if a:0 == 1
|
|
|
|
let fname = shellescape(a:1)
|
|
|
|
else
|
|
|
|
let fname = ''
|
|
|
|
endif
|
|
|
|
|
2011-05-09 19:40:07 +08:00
|
|
|
let ctags_cmd = shellescape(a:ctags_bin) . ' ' . a:args . ' ' . fname
|
2011-05-07 14:02:03 +08:00
|
|
|
|
2011-05-09 19:40:07 +08:00
|
|
|
if exists('+shellslash')
|
|
|
|
let &shellslash = shellslash_save
|
|
|
|
endif
|
2011-05-07 14:02:03 +08:00
|
|
|
|
|
|
|
" Needed for cases where 'encoding' is different from the system's
|
|
|
|
" encoding
|
|
|
|
if g:tagbar_systemenc != &encoding
|
|
|
|
let ctags_cmd = iconv(ctags_cmd, &encoding, g:tagbar_systemenc)
|
|
|
|
elseif $LANG != ''
|
|
|
|
let ctags_cmd = iconv(ctags_cmd, &encoding, $LANG)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if ctags_cmd == ''
|
|
|
|
echoerr 'Tagbar: Encoding conversion failed!'
|
|
|
|
\ 'Please make sure your system is set up correctly'
|
|
|
|
\ 'and that Vim is compiled with the "iconv" feature.'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ctags_cmd
|
|
|
|
endfunction
|
|
|
|
|
2011-05-09 19:40:07 +08:00
|
|
|
" s:ExecuteCtags() {{{2
|
|
|
|
" Execute ctags with necessary shell settings
|
|
|
|
" Partially based on the discussion at
|
|
|
|
" http://vim.1045645.n5.nabble.com/bad-default-shellxquote-in-Widows-td1208284.html
|
|
|
|
function! s:ExecuteCtags(ctags_cmd)
|
|
|
|
if exists('+shellslash')
|
|
|
|
let shellslash_save = &shellslash
|
|
|
|
set noshellslash
|
|
|
|
endif
|
|
|
|
|
|
|
|
if &shell =~ 'cmd\.exe'
|
|
|
|
let shellxquote_save = &shellxquote
|
|
|
|
set shellxquote=\"
|
|
|
|
let shellcmdflag_save = &shellcmdflag
|
|
|
|
set shellcmdflag=/s\ /c
|
|
|
|
endif
|
|
|
|
|
|
|
|
let ctags_output = system(a:ctags_cmd)
|
|
|
|
|
|
|
|
if &shell =~ 'cmd\.exe'
|
|
|
|
let &shellxquote = shellxquote_save
|
|
|
|
let &shellcmdflag = shellcmdflag_save
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('+shellslash')
|
|
|
|
let &shellslash = shellslash_save
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ctags_output
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" s:GetTagInfo() {{{2
|
2011-01-20 16:03:56 +08:00
|
|
|
" Return the info dictionary of the tag on the specified line. If the line
|
|
|
|
" does not contain a valid tag (for example because it is empty or only
|
|
|
|
" contains a pseudo-tag) return an empty dictionary.
|
2011-03-26 22:32:31 +08:00
|
|
|
function! s:GetTagInfo(linenr, ignorepseudo)
|
2011-04-07 21:00:12 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
|
|
|
|
if empty(fileinfo)
|
2011-01-20 16:03:56 +08:00
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Don't do anything in empty and comment lines
|
|
|
|
let curline = getline(a:linenr)
|
|
|
|
if curline =~ '^\s*$' || curline[0] == '"'
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Check if there is a tag on the current line
|
|
|
|
if !has_key(fileinfo.tline, a:linenr)
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
let taginfo = fileinfo.tline[a:linenr]
|
|
|
|
|
|
|
|
" Check if the current tag is not a pseudo-tag
|
2011-04-24 09:58:06 +08:00
|
|
|
if a:ignorepseudo && taginfo.isPseudoTag()
|
2011-01-20 16:03:56 +08:00
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
return taginfo
|
|
|
|
endfunction
|
|
|
|
|
2011-04-24 18:53:07 +08:00
|
|
|
" s:GetNearbyTag() {{{2
|
|
|
|
" Get the tag info for a file near the cursor in the current file
|
|
|
|
function! s:GetNearbyTag()
|
|
|
|
let fileinfo = s:known_files.getCurrent()
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
let tag = {}
|
|
|
|
|
|
|
|
" If a tag appears in a file more than once (for example namespaces in
|
|
|
|
" C++) only one of them has a 'tline' entry and can thus be highlighted.
|
|
|
|
" The only way to solve this would be to go over the whole tag list again,
|
|
|
|
" making everything slower. Since this should be a rare occurence and
|
|
|
|
" highlighting isn't /that/ important ignore it for now.
|
|
|
|
for line in range(curline, 1, -1)
|
|
|
|
if has_key(fileinfo.fline, line)
|
|
|
|
let tag = fileinfo.fline[line]
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return tag
|
|
|
|
endfunction
|
|
|
|
|
2011-03-27 19:34:50 +08:00
|
|
|
" s:CheckMouseClick() {{{2
|
|
|
|
function! s:CheckMouseClick()
|
2011-03-27 20:29:25 +08:00
|
|
|
let line = getline('.')
|
|
|
|
let curcol = col('.')
|
2011-03-27 19:34:50 +08:00
|
|
|
|
2011-03-27 20:29:25 +08:00
|
|
|
if (match(line, s:icon_open . '[-+ ]') + 1) == curcol
|
2011-03-27 19:34:50 +08:00
|
|
|
call s:CloseFold()
|
2011-03-27 20:29:25 +08:00
|
|
|
elseif (match(line, s:icon_closed . '[-+ ]') + 1) == curcol
|
2011-03-27 19:34:50 +08:00
|
|
|
call s:OpenFold()
|
2011-06-06 14:42:35 +08:00
|
|
|
elseif g:tagbar_singleclick
|
|
|
|
call s:JumpToTag(0)
|
2011-03-27 19:34:50 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" TagbarBalloonExpr() {{{2
|
|
|
|
function! TagbarBalloonExpr()
|
2011-03-26 22:32:31 +08:00
|
|
|
let taginfo = s:GetTagInfo(v:beval_lnum, 1)
|
2011-01-22 17:16:49 +08:00
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
if empty(taginfo)
|
|
|
|
return
|
2011-01-21 19:27:50 +08:00
|
|
|
endif
|
|
|
|
|
2011-04-07 21:00:12 +08:00
|
|
|
return taginfo.getPrototype()
|
2011-01-21 19:27:50 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-02-14 18:47:18 +08:00
|
|
|
" TagbarGenerateStatusline() {{{2
|
2011-01-27 16:04:21 +08:00
|
|
|
function! TagbarGenerateStatusline()
|
|
|
|
if g:tagbar_sort
|
|
|
|
let text = '[Name]'
|
|
|
|
else
|
|
|
|
let text = '[Order]'
|
|
|
|
endif
|
|
|
|
|
2011-04-08 23:33:59 +08:00
|
|
|
if !empty(s:known_files.getCurrent())
|
|
|
|
let filename = fnamemodify(s:known_files.getCurrent().fpath, ':t')
|
|
|
|
let text .= ' ' . filename
|
|
|
|
endif
|
2011-01-27 16:04:21 +08:00
|
|
|
|
|
|
|
return text
|
|
|
|
endfunction
|
|
|
|
|
2011-01-24 17:37:52 +08:00
|
|
|
" Commands {{{1
|
2011-02-14 18:32:57 +08:00
|
|
|
command! -nargs=0 TagbarToggle call s:ToggleWindow()
|
|
|
|
command! -nargs=0 TagbarOpen call s:OpenWindow(0)
|
|
|
|
command! -nargs=0 TagbarOpenAutoClose call s:OpenWindow(1)
|
|
|
|
command! -nargs=0 TagbarClose call s:CloseWindow()
|
2011-04-07 21:00:12 +08:00
|
|
|
command! -nargs=1 TagbarSetFoldlevel call s:SetFoldLevel(<args>)
|
2011-04-24 18:53:07 +08:00
|
|
|
command! -nargs=0 TagbarShowTag call s:OpenParents()
|
2011-01-11 17:36:49 +08:00
|
|
|
|
2011-01-24 17:37:52 +08:00
|
|
|
" Modeline {{{1
|
|
|
|
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1
|