2011-06-29 04:59:49 +08:00
|
|
|
" ============================================================================
|
|
|
|
" File: tagbar.vim
|
|
|
|
" Description: List the current file's tags in a sidebar, ordered by class etc
|
|
|
|
" Author: Jan Larres <jan@majutsushi.net>
|
|
|
|
" Licence: Vim licence
|
|
|
|
" Website: http://majutsushi.github.com/tagbar/
|
2014-01-23 18:17:00 +08:00
|
|
|
" Version: 2.6.1
|
2011-06-29 04:59:49 +08:00
|
|
|
" Note: This plugin was heavily inspired by the 'Taglist' plugin by
|
|
|
|
" Yegappan Lakshmanan and uses a small amount of code from it.
|
|
|
|
"
|
|
|
|
" 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-07-15 13:34:47 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Initialization {{{1
|
|
|
|
|
2012-06-19 12:49:55 +08:00
|
|
|
" If another plugin calls an autoloaded Tagbar function on startup before the
|
|
|
|
" plugin/tagbar.vim file got loaded, load it explicitly
|
|
|
|
if exists(':Tagbar') == 0
|
|
|
|
runtime plugin/tagbar.vim
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Basic init {{{2
|
|
|
|
|
2011-07-15 13:34:47 +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-12-22 13:06:48 +08:00
|
|
|
let s:icon_closed = g:tagbar_iconchars[0]
|
|
|
|
let s:icon_open = g:tagbar_iconchars[1]
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-07-30 07:38:46 +08:00
|
|
|
let s:type_init_done = 0
|
|
|
|
let s:autocommands_done = 0
|
|
|
|
let s:statusline_in_use = 0
|
|
|
|
|
2012-07-01 14:48:00 +08:00
|
|
|
" 0: not checked yet; 1: checked and found; 2: checked and not found
|
2012-02-12 13:36:45 +08:00
|
|
|
let s:checked_ctags = 0
|
|
|
|
let s:checked_ctags_types = 0
|
|
|
|
let s:ctags_types = {}
|
2012-09-04 20:29:28 +08:00
|
|
|
|
|
|
|
let s:new_window = 1
|
|
|
|
let s:is_maximized = 0
|
2013-05-20 11:18:57 +08:00
|
|
|
let s:winrestcmd = ''
|
2012-09-04 20:29:28 +08:00
|
|
|
let s:short_help = 1
|
2013-02-18 19:02:32 +08:00
|
|
|
let s:nearby_disabled = 0
|
2013-11-06 17:33:27 +08:00
|
|
|
let s:paused = 0
|
2013-11-29 13:40:09 +08:00
|
|
|
let s:pwin_by_tagbar = 0
|
2012-09-04 20:29:28 +08:00
|
|
|
|
2013-03-18 14:09:12 +08:00
|
|
|
let s:window_expanded = 0
|
2013-11-04 17:30:17 +08:00
|
|
|
let s:expand_bufnr = -1
|
2013-03-18 14:09:12 +08:00
|
|
|
let s:window_pos = {
|
|
|
|
\ 'pre' : { 'x' : 0, 'y' : 0 },
|
|
|
|
\ 'post' : { 'x' : 0, 'y' : 0 }
|
|
|
|
\}
|
2013-03-18 13:51:54 +08:00
|
|
|
|
2012-09-04 20:29:28 +08:00
|
|
|
" Script-local variable needed since compare functions can't
|
|
|
|
" take extra arguments
|
|
|
|
let s:compare_typeinfo = {}
|
2012-02-12 13:36:45 +08:00
|
|
|
|
2012-11-22 13:05:59 +08:00
|
|
|
let s:visibility_symbols = {
|
2011-06-29 04:59:49 +08:00
|
|
|
\ 'public' : '+',
|
|
|
|
\ 'protected' : '#',
|
|
|
|
\ 'private' : '-'
|
|
|
|
\ }
|
|
|
|
|
2011-07-15 13:34:47 +08:00
|
|
|
let g:loaded_tagbar = 1
|
|
|
|
|
2011-10-02 17:39:39 +08:00
|
|
|
let s:last_highlight_tline = 0
|
2011-12-12 14:47:43 +08:00
|
|
|
let s:debug = 0
|
|
|
|
let s:debug_file = ''
|
2011-10-02 17:39:39 +08:00
|
|
|
|
2014-10-27 17:35:19 +08:00
|
|
|
let s:warnings = {
|
|
|
|
\ 'type': [],
|
|
|
|
\ 'encoding': 0
|
|
|
|
\ }
|
|
|
|
|
2011-12-21 12:03:12 +08:00
|
|
|
" s:Init() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:Init(silent) abort
|
2012-07-01 14:48:00 +08:00
|
|
|
if s:checked_ctags == 2 && a:silent
|
|
|
|
return 0
|
|
|
|
elseif s:checked_ctags != 1
|
|
|
|
if !s:CheckForExCtags(a:silent)
|
2012-02-12 13:36:45 +08:00
|
|
|
return 0
|
2011-12-21 12:03:12 +08:00
|
|
|
endif
|
|
|
|
endif
|
2012-02-12 13:36:45 +08:00
|
|
|
|
|
|
|
if !s:checked_ctags_types
|
|
|
|
call s:GetSupportedFiletypes()
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !s:type_init_done
|
|
|
|
call s:InitTypes()
|
|
|
|
endif
|
|
|
|
|
2012-02-28 19:21:50 +08:00
|
|
|
if !s:autocommands_done
|
|
|
|
call s:CreateAutocommands()
|
2012-09-09 18:55:57 +08:00
|
|
|
call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 0)
|
2012-02-28 19:21:50 +08:00
|
|
|
endif
|
|
|
|
|
2012-02-12 13:36:45 +08:00
|
|
|
return 1
|
2011-12-21 12:03:12 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:InitTypes() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:InitTypes() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Initializing types')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let s:known_types = {}
|
|
|
|
|
|
|
|
" Ant {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_ant = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_ant.ctagstype = 'ant'
|
|
|
|
let type_ant.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'projects', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'targets', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.ant = type_ant
|
|
|
|
" Asm {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_asm = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_asm.ctagstype = 'asm'
|
|
|
|
let type_asm.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'macros', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'types', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'd', 'long' : 'defines', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.asm = type_asm
|
|
|
|
" ASP {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_aspvbs = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_aspvbs.ctagstype = 'asp'
|
|
|
|
let type_aspvbs.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'constants', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.aspvbs = type_aspvbs
|
|
|
|
" Awk {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_awk = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_awk.ctagstype = 'awk'
|
|
|
|
let type_awk.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.awk = type_awk
|
|
|
|
" Basic {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_basic = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_basic.ctagstype = 'basic'
|
|
|
|
let type_basic.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'g', 'long' : 'enumerations', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'types', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.basic = type_basic
|
|
|
|
" BETA {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_beta = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_beta.ctagstype = 'beta'
|
|
|
|
let type_beta.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'fragments', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'slots', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'patterns', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.beta = type_beta
|
|
|
|
" C {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_c = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_c.ctagstype = 'c'
|
|
|
|
let type_c.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'prototypes', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'typedefs', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'structs', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'u', 'long' : 'unions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_c.sro = '::'
|
|
|
|
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
|
|
|
|
" C++ {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_cpp = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_cpp.ctagstype = 'c++'
|
|
|
|
let type_cpp.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'prototypes', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'typedefs', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'structs', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'u', 'long' : 'unions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_cpp.sro = '::'
|
|
|
|
let type_cpp.kind2scope = {
|
|
|
|
\ 'g' : 'enum',
|
|
|
|
\ 'n' : 'namespace',
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 's' : 'struct',
|
|
|
|
\ 'u' : 'union'
|
|
|
|
\ }
|
|
|
|
let type_cpp.scope2kind = {
|
|
|
|
\ 'enum' : 'g',
|
|
|
|
\ 'namespace' : 'n',
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'struct' : 's',
|
|
|
|
\ 'union' : 'u'
|
|
|
|
\ }
|
|
|
|
let s:known_types.cpp = type_cpp
|
|
|
|
" C# {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_cs = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_cs.ctagstype = 'c#'
|
|
|
|
let type_cs.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'fields', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'typedefs', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'structs', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'E', 'long' : 'events', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'properties', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_cs.sro = '.'
|
|
|
|
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
|
|
|
|
" COBOL {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_cobol = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_cobol.ctagstype = 'cobol'
|
|
|
|
let type_cobol.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'data items', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'file descriptions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'g', 'long' : 'group items', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'paragraphs', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'P', 'long' : 'program ids', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'sections', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.cobol = type_cobol
|
|
|
|
" DOS Batch {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_dosbatch = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_dosbatch.ctagstype = 'dosbatch'
|
|
|
|
let type_dosbatch.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.dosbatch = type_dosbatch
|
|
|
|
" Eiffel {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_eiffel = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_eiffel.ctagstype = 'eiffel'
|
|
|
|
let type_eiffel.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'features', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_eiffel.sro = '.' " Not sure, is nesting even possible?
|
|
|
|
let type_eiffel.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'f' : 'feature'
|
|
|
|
\ }
|
|
|
|
let type_eiffel.scope2kind = {
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'feature' : 'f'
|
|
|
|
\ }
|
|
|
|
let s:known_types.eiffel = type_eiffel
|
|
|
|
" Erlang {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_erlang = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_erlang.ctagstype = 'erlang'
|
|
|
|
let type_erlang.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'd', 'long' : 'macro definitions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'r', 'long' : 'record definitions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_erlang.sro = '.' " Not sure, is nesting even possible?
|
|
|
|
let type_erlang.kind2scope = {
|
|
|
|
\ 'm' : 'module'
|
|
|
|
\ }
|
|
|
|
let type_erlang.scope2kind = {
|
|
|
|
\ 'module' : 'm'
|
|
|
|
\ }
|
|
|
|
let s:known_types.erlang = type_erlang
|
|
|
|
" Flex {{{3
|
|
|
|
" 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!
|
2012-06-24 14:57:50 +08:00
|
|
|
let type_as = s:TypeInfo.New()
|
|
|
|
let type_as.ctagstype = 'flex'
|
|
|
|
let type_as.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'v', 'long' : 'global variables', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'properties', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'x', 'long' : 'mxtags', 'fold' : 0, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
2012-06-24 14:57:50 +08:00
|
|
|
let type_as.sro = '.'
|
|
|
|
let type_as.kind2scope = {
|
2011-06-29 04:59:49 +08:00
|
|
|
\ 'c' : 'class'
|
|
|
|
\ }
|
2012-06-24 14:57:50 +08:00
|
|
|
let type_as.scope2kind = {
|
2011-06-29 04:59:49 +08:00
|
|
|
\ 'class' : 'c'
|
|
|
|
\ }
|
2012-06-24 14:57:50 +08:00
|
|
|
let s:known_types.mxml = type_as
|
|
|
|
let s:known_types.actionscript = type_as
|
2011-06-29 04:59:49 +08:00
|
|
|
" Fortran {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_fortran = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_fortran.ctagstype = 'fortran'
|
|
|
|
let type_fortran.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'programs', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'k', 'long' : 'components', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'derived types and structures', 'fold' : 0,
|
|
|
|
\ 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'common blocks', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'b', 'long' : 'block data', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'entry points', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'n', 'long' : 'namelists', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_fortran.sro = '.' " Not sure, is nesting even possible?
|
|
|
|
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
|
|
|
|
" HTML {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_html = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_html.ctagstype = 'html'
|
|
|
|
let type_html.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'JavaScript funtions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'a', 'long' : 'named anchors', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.html = type_html
|
|
|
|
" Java {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_java = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_java.ctagstype = 'java'
|
|
|
|
let type_java.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'packages', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'fields', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enum types', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'enum constants', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_java.sro = '.'
|
|
|
|
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
|
|
|
|
" JavaScript {{{3
|
2014-10-28 11:49:16 +08:00
|
|
|
" jsctags/doctorjs will be used if available.
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_javascript = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_javascript.ctagstype = 'javascript'
|
2011-12-21 15:33:31 +08:00
|
|
|
let jsctags = s:CheckFTCtags('jsctags', 'javascript')
|
|
|
|
if jsctags != ''
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_javascript.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_javascript.sro = '.'
|
|
|
|
let type_javascript.kind2scope = {
|
|
|
|
\ 'v' : 'namespace',
|
|
|
|
\ 'f' : 'namespace'
|
|
|
|
\ }
|
|
|
|
let type_javascript.scope2kind = {
|
|
|
|
\ 'namespace' : 'v'
|
|
|
|
\ }
|
2011-12-21 15:33:31 +08:00
|
|
|
let type_javascript.ctagsbin = jsctags
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_javascript.ctagsargs = '-f -'
|
|
|
|
else
|
|
|
|
let type_javascript.kinds = [
|
2014-10-28 11:49:16 +08:00
|
|
|
\ {'short': 'v', 'long': 'global variables', 'fold': 0, 'stl': 0},
|
|
|
|
\ {'short': 'c', 'long': 'classes', 'fold': 0, 'stl': 1},
|
|
|
|
\ {'short': 'p', 'long': 'properties', 'fold': 0, 'stl': 0},
|
|
|
|
\ {'short': 'm', 'long': 'methods', 'fold': 0, 'stl': 1},
|
|
|
|
\ {'short': 'f', 'long': 'functions', 'fold': 0, 'stl': 1},
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
2014-10-28 11:49:16 +08:00
|
|
|
let type_javascript.sro = '.'
|
|
|
|
let type_javascript.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'f' : 'function',
|
|
|
|
\ 'm' : 'method',
|
|
|
|
\ 'p' : 'property',
|
|
|
|
\ }
|
|
|
|
let type_javascript.scope2kind = {
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'function' : 'f',
|
|
|
|
\ }
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
let s:known_types.javascript = type_javascript
|
|
|
|
" Lisp {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_lisp = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_lisp.ctagstype = 'lisp'
|
|
|
|
let type_lisp.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.lisp = type_lisp
|
2012-08-31 18:42:25 +08:00
|
|
|
let s:known_types.clojure = type_lisp
|
2011-06-29 04:59:49 +08:00
|
|
|
" Lua {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_lua = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_lua.ctagstype = 'lua'
|
|
|
|
let type_lua.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.lua = type_lua
|
|
|
|
" Make {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_make = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_make.ctagstype = 'make'
|
|
|
|
let type_make.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'macros', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.make = type_make
|
|
|
|
" Matlab {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_matlab = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_matlab.ctagstype = 'matlab'
|
|
|
|
let type_matlab.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.matlab = type_matlab
|
|
|
|
" Ocaml {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_ocaml = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_ocaml.ctagstype = 'ocaml'
|
|
|
|
let type_ocaml.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'M', 'long' : 'modules or functors', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'global variables', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'C', 'long' : 'constructors', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'exceptions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'type names', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'r', 'long' : 'structure fields', 'fold' : 0, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_ocaml.sro = '.' " Not sure, is nesting even possible?
|
|
|
|
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
|
|
|
|
" Pascal {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_pascal = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_pascal.ctagstype = 'pascal'
|
|
|
|
let type_pascal.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.pascal = type_pascal
|
|
|
|
" Perl {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_perl = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_perl.ctagstype = 'perl'
|
|
|
|
let type_perl.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'packages', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'formats', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.perl = type_perl
|
|
|
|
" PHP {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_php = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_php.ctagstype = 'php'
|
|
|
|
let type_php.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'd', 'long' : 'constant definitions', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'j', 'long' : 'javascript functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.php = type_php
|
|
|
|
" Python {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_python = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_python.ctagstype = 'python'
|
|
|
|
let type_python.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'i', 'long' : 'imports', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_python.sro = '.'
|
|
|
|
let type_python.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'f' : 'function',
|
|
|
|
\ 'm' : 'function'
|
|
|
|
\ }
|
|
|
|
let type_python.scope2kind = {
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'function' : 'f'
|
|
|
|
\ }
|
|
|
|
let s:known_types.python = type_python
|
2013-11-22 09:55:50 +08:00
|
|
|
let s:known_types.pyrex = type_python
|
|
|
|
let s:known_types.cython = type_python
|
2011-06-29 04:59:49 +08:00
|
|
|
" REXX {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_rexx = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_rexx.ctagstype = 'rexx'
|
|
|
|
let type_rexx.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 's', 'long' : 'subroutines', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.rexx = type_rexx
|
|
|
|
" Ruby {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_ruby = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_ruby.ctagstype = 'ruby'
|
|
|
|
let type_ruby.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'methods', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'F', 'long' : 'singleton methods', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_ruby.sro = '.'
|
|
|
|
let type_ruby.kind2scope = {
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'm' : 'class'
|
|
|
|
\ }
|
|
|
|
let type_ruby.scope2kind = {
|
|
|
|
\ 'class' : 'c'
|
|
|
|
\ }
|
|
|
|
let s:known_types.ruby = type_ruby
|
|
|
|
" Scheme {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_scheme = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_scheme.ctagstype = 'scheme'
|
|
|
|
let type_scheme.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'sets', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.scheme = type_scheme
|
2013-04-04 14:06:42 +08:00
|
|
|
let s:known_types.racket = type_scheme
|
2011-06-29 04:59:49 +08:00
|
|
|
" Shell script {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_sh = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_sh.ctagstype = 'sh'
|
|
|
|
let type_sh.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.sh = type_sh
|
|
|
|
let s:known_types.csh = type_sh
|
|
|
|
let s:known_types.zsh = type_sh
|
|
|
|
" SLang {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_slang = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_slang.ctagstype = 'slang'
|
|
|
|
let type_slang.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.slang = type_slang
|
|
|
|
" SML {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_sml = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_sml.ctagstype = 'sml'
|
|
|
|
let type_sml.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'e', 'long' : 'exception declarations', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'function definitions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'functor definitions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'signature declarations', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'r', 'long' : 'structure declarations', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'type definitions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'value bindings', 'fold' : 0, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.sml = type_sml
|
|
|
|
" SQL {{{3
|
|
|
|
" 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!
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_sql = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_sql.ctagstype = 'sql'
|
|
|
|
let type_sql.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'P', 'long' : 'packages', 'fold' : 1, 'stl' : 1},
|
2012-06-24 14:57:50 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'prototypes', 'fold' : 0, 'stl' : 1},
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'cursors', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'F', 'long' : 'record fields', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'L', 'long' : 'block label', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'subtypes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'tables', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'T', 'long' : 'triggers', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'i', 'long' : 'indexes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'events', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'U', 'long' : 'publications', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'R', 'long' : 'services', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'D', 'long' : 'domains', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'V', 'long' : 'views', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'n', 'long' : 'synonyms', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'x', 'long' : 'MobiLink Table Scripts', 'fold' : 0, 'stl' : 1},
|
2012-06-24 14:57:50 +08:00
|
|
|
\ {'short' : 'y', 'long' : 'MobiLink Conn Scripts', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'z', 'long' : 'MobiLink Properties', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.sql = type_sql
|
|
|
|
" Tcl {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_tcl = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_tcl.ctagstype = 'tcl'
|
|
|
|
let type_tcl.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'methods', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.tcl = type_tcl
|
|
|
|
" LaTeX {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_tex = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_tex.ctagstype = 'tex'
|
|
|
|
let type_tex.kinds = [
|
2012-04-02 14:30:18 +08:00
|
|
|
\ {'short' : 'i', 'long' : 'includes', 'fold' : 1, 'stl' : 0},
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'p', 'long' : 'parts', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'chapters', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 's', 'long' : 'sections', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'u', 'long' : 'subsections', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'b', 'long' : 'subsubsections', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'P', 'long' : 'paragraphs', 'fold' : 0, 'stl' : 0},
|
2012-04-02 14:30:18 +08:00
|
|
|
\ {'short' : 'G', 'long' : 'subparagraphs', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 0}
|
|
|
|
\ ]
|
|
|
|
let type_tex.sro = '""'
|
|
|
|
let type_tex.kind2scope = {
|
|
|
|
\ 'p' : 'part',
|
|
|
|
\ 'c' : 'chapter',
|
|
|
|
\ 's' : 'section',
|
|
|
|
\ 'u' : 'subsection',
|
|
|
|
\ 'b' : 'subsubsection'
|
|
|
|
\ }
|
|
|
|
let type_tex.scope2kind = {
|
|
|
|
\ 'part' : 'p',
|
|
|
|
\ 'chapter' : 'c',
|
|
|
|
\ 'section' : 's',
|
|
|
|
\ 'subsection' : 'u',
|
|
|
|
\ 'subsubsection' : 'b'
|
|
|
|
\ }
|
|
|
|
let type_tex.sort = 0
|
2011-06-29 04:59:49 +08:00
|
|
|
let s:known_types.tex = type_tex
|
2012-02-12 13:37:05 +08:00
|
|
|
" Vala {{{3
|
|
|
|
" Vala is supported by the ctags fork provided by Anjuta, so only add the
|
|
|
|
" type if the fork is used to prevent error messages otherwise
|
|
|
|
if has_key(s:ctags_types, 'vala') || executable('anjuta-tags')
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_vala = s:TypeInfo.New()
|
2012-02-12 13:37:05 +08:00
|
|
|
let type_vala.ctagstype = 'vala'
|
|
|
|
let type_vala.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'e', 'long' : 'Enumerations', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'Enumeration values', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 's', 'long' : 'Structures', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'i', 'long' : 'Interfaces', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'd', 'long' : 'Delegates', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'Classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'Properties', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'Fields', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'Methods', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'E', 'long' : 'Error domains', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'r', 'long' : 'Error codes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'S', 'long' : 'Signals', 'fold' : 0, 'stl' : 1}
|
2012-02-12 13:37:05 +08:00
|
|
|
\ ]
|
|
|
|
let type_vala.sro = '.'
|
|
|
|
" 'enum' doesn't seem to be used as a scope, but it can't hurt to have
|
|
|
|
" it here
|
|
|
|
let type_vala.kind2scope = {
|
|
|
|
\ 's' : 'struct',
|
|
|
|
\ 'i' : 'interface',
|
|
|
|
\ 'c' : 'class',
|
|
|
|
\ 'e' : 'enum'
|
|
|
|
\ }
|
|
|
|
let type_vala.scope2kind = {
|
|
|
|
\ 'struct' : 's',
|
|
|
|
\ 'interface' : 'i',
|
|
|
|
\ 'class' : 'c',
|
|
|
|
\ 'enum' : 'e'
|
|
|
|
\ }
|
|
|
|
let s:known_types.vala = type_vala
|
|
|
|
endif
|
|
|
|
if !has_key(s:ctags_types, 'vala') && executable('anjuta-tags')
|
|
|
|
let s:known_types.vala.ctagsbin = 'anjuta-tags'
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
" Vera {{{3
|
|
|
|
" Why are variables 'virtual'?
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_vera = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_vera.ctagstype = 'vera'
|
|
|
|
let type_vera.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'd', 'long' : 'macros', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'g', 'long' : 'enums', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'T', 'long' : 'typedefs', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'classes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'members', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'tasks', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'p', 'long' : 'programs', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let type_vera.sro = '.' " Nesting doesn't seem to be possible
|
|
|
|
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
|
|
|
|
" Verilog {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_verilog = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_verilog.ctagstype = 'verilog'
|
|
|
|
let type_verilog.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'e', 'long' : 'events', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'm', 'long' : 'modules', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'n', 'long' : 'net data types', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'ports', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'r', 'long' : 'register data types', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 't', 'long' : 'tasks', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.verilog = type_verilog
|
|
|
|
" VHDL {{{3
|
|
|
|
" The VHDL ctags parser unfortunately doesn't generate proper scopes
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_vhdl = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_vhdl.ctagstype = 'vhdl'
|
|
|
|
let type_vhdl.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'P', 'long' : 'packages', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'c', 'long' : 'constants', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 't', 'long' : 'types', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'T', 'long' : 'subtypes', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'r', 'long' : 'records', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'e', 'long' : 'entities', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'p', 'long' : 'procedures', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.vhdl = type_vhdl
|
|
|
|
" Vim {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_vim = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_vim.ctagstype = 'vim'
|
|
|
|
let type_vim.kinds = [
|
2012-06-24 14:57:50 +08:00
|
|
|
\ {'short' : 'n', 'long' : 'vimball filenames', 'fold' : 0, 'stl' : 1},
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'v', 'long' : 'variables', 'fold' : 1, 'stl' : 0},
|
|
|
|
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1},
|
|
|
|
\ {'short' : 'a', 'long' : 'autocommand groups', 'fold' : 1, 'stl' : 1},
|
|
|
|
\ {'short' : 'c', 'long' : 'commands', 'fold' : 0, 'stl' : 0},
|
|
|
|
\ {'short' : 'm', 'long' : 'maps', 'fold' : 1, 'stl' : 0}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.vim = type_vim
|
|
|
|
" YACC {{{3
|
2012-03-14 17:22:44 +08:00
|
|
|
let type_yacc = s:TypeInfo.New()
|
2011-06-29 04:59:49 +08:00
|
|
|
let type_yacc.ctagstype = 'yacc'
|
|
|
|
let type_yacc.kinds = [
|
2012-03-04 15:52:15 +08:00
|
|
|
\ {'short' : 'l', 'long' : 'labels', 'fold' : 0, 'stl' : 1}
|
2011-06-29 04:59:49 +08:00
|
|
|
\ ]
|
|
|
|
let s:known_types.yacc = type_yacc
|
|
|
|
" }}}3
|
|
|
|
|
2014-10-27 17:35:19 +08:00
|
|
|
for [type, typeinfo] in items(s:known_types)
|
|
|
|
let typeinfo.ftype = type
|
|
|
|
endfor
|
|
|
|
|
2012-02-19 12:26:15 +08:00
|
|
|
call s:LoadUserTypeDefs()
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-04-23 14:16:10 +08:00
|
|
|
for typeinfo in values(s:known_types)
|
|
|
|
call typeinfo.createKinddict()
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
|
|
|
|
let s:type_init_done = 1
|
|
|
|
endfunction
|
|
|
|
|
2012-02-19 12:26:15 +08:00
|
|
|
" s:LoadUserTypeDefs() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:LoadUserTypeDefs(...) abort
|
2012-02-19 12:26:15 +08:00
|
|
|
if a:0 > 0
|
|
|
|
let type = a:1
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("Initializing user type '" . type . "'")
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-02-19 12:26:15 +08:00
|
|
|
let defdict = {}
|
|
|
|
let defdict[type] = g:tagbar_type_{type}
|
|
|
|
else
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Initializing user types')
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-03-08 13:06:51 +08:00
|
|
|
let defdict = tagbar#getusertypes()
|
2012-02-19 12:26:15 +08:00
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
let transformed = {}
|
|
|
|
for [type, def] in items(defdict)
|
|
|
|
let transformed[type] = s:TransformUserTypeDef(def)
|
2014-10-27 17:35:19 +08:00
|
|
|
let transformed[type].ftype = type
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
for [key, value] in items(transformed)
|
|
|
|
if !has_key(s:known_types, key) || get(value, 'replace', 0)
|
2012-03-14 17:22:44 +08:00
|
|
|
let s:known_types[key] = s:TypeInfo.New(value)
|
2012-02-19 12:26:15 +08:00
|
|
|
else
|
|
|
|
call extend(s:known_types[key], value)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if a:0 > 0
|
2013-04-26 15:33:00 +08:00
|
|
|
call s:known_types[type].createKinddict()
|
2012-02-19 12:26:15 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
" s:TransformUserTypeDef() {{{2
|
|
|
|
" Transform the user definitions into the internal format
|
|
|
|
function! s:TransformUserTypeDef(def) abort
|
|
|
|
let newdef = copy(a:def)
|
|
|
|
|
|
|
|
if has_key(a:def, 'kinds')
|
|
|
|
let newdef.kinds = []
|
|
|
|
let kinds = a:def.kinds
|
|
|
|
for kind in kinds
|
|
|
|
let kindlist = split(kind, ':')
|
|
|
|
let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]}
|
|
|
|
let kinddict.fold = get(kindlist, 2, 0)
|
|
|
|
let kinddict.stl = get(kindlist, 3, 1)
|
|
|
|
call add(newdef.kinds, kinddict)
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
" If the user only specified one of kind2scope and scope2kind then use it
|
|
|
|
" to generate the respective other
|
|
|
|
if has_key(a:def, 'kind2scope') && !has_key(a:def, 'scope2kind')
|
|
|
|
let newdef.scope2kind = {}
|
|
|
|
for [key, value] in items(a:def.kind2scope)
|
|
|
|
let newdef.scope2kind[value] = key
|
|
|
|
endfor
|
|
|
|
elseif has_key(a:def, 'scope2kind') && !has_key(a:def, 'kind2scope')
|
|
|
|
let newdef.kind2scope = {}
|
|
|
|
for [key, value] in items(a:def.scope2kind)
|
|
|
|
let newdef.kind2scope[value] = key
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
return newdef
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:RestoreSession() {{{2
|
|
|
|
" Properly restore Tagbar after a session got loaded
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:RestoreSession() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Restoring session')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2012-01-31 15:58:49 +08:00
|
|
|
let curfile = fnamemodify(bufname('%'), ':p')
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr)
|
2011-06-29 04:59:49 +08:00
|
|
|
let in_tagbar = 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2012-04-15 19:10:58 +08:00
|
|
|
let s:last_autofocus = 0
|
|
|
|
|
2012-07-01 14:48:00 +08:00
|
|
|
call s:Init(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
call s:InitWindow(g:tagbar_autoclose)
|
|
|
|
|
2012-07-22 17:49:17 +08:00
|
|
|
call s:AutoUpdate(curfile, 0)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if !in_tagbar
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win('p')
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:MapKeys() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:MapKeys() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Mapping keys')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
nnoremap <script> <silent> <buffer> <2-LeftMouse>
|
|
|
|
\ :call <SID>JumpToTag(0)<CR>
|
|
|
|
nnoremap <script> <silent> <buffer> <LeftRelease>
|
|
|
|
\ <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>
|
|
|
|
|
2013-08-22 13:38:31 +08:00
|
|
|
let maps = [
|
2014-02-05 13:08:04 +08:00
|
|
|
\ ['jump', 'JumpToTag(0)'],
|
|
|
|
\ ['preview', 'JumpToTag(1)'],
|
|
|
|
\ ['previewwin', 'ShowInPreviewWin()'],
|
|
|
|
\ ['nexttag', 'GotoNextToplevelTag(1)'],
|
|
|
|
\ ['prevtag', 'GotoNextToplevelTag(-1)'],
|
|
|
|
\ ['showproto', 'ShowPrototype(0)'],
|
|
|
|
\ ['hidenonpublic', 'ToggleHideNonPublicTags()'],
|
2013-08-22 13:38:31 +08:00
|
|
|
\
|
|
|
|
\ ['openfold', 'OpenFold()'],
|
|
|
|
\ ['closefold', 'CloseFold()'],
|
|
|
|
\ ['togglefold', 'ToggleFold()'],
|
|
|
|
\ ['openallfolds', 'SetFoldLevel(99, 1)'],
|
|
|
|
\ ['closeallfolds', 'SetFoldLevel(0, 1)'],
|
2014-11-09 12:33:42 +08:00
|
|
|
\ ['nextfold', 'GotoNextFold()'],
|
|
|
|
\ ['prevfold', 'GotoPrevFold()'],
|
2013-08-22 13:38:31 +08:00
|
|
|
\
|
2014-06-25 13:52:43 +08:00
|
|
|
\ ['togglesort', 'ToggleSort()'],
|
|
|
|
\ ['toggleautoclose', 'ToggleAutoclose()'],
|
|
|
|
\ ['zoomwin', 'ZoomWindow()'],
|
|
|
|
\ ['close', 'CloseWindow()'],
|
|
|
|
\ ['help', 'ToggleHelp()'],
|
2013-08-22 13:38:31 +08:00
|
|
|
\ ]
|
|
|
|
|
|
|
|
for [map, func] in maps
|
|
|
|
let def = get(g:, 'tagbar_map_' . map)
|
|
|
|
if type(def) == type("")
|
|
|
|
let keys = [def]
|
|
|
|
else
|
|
|
|
let keys = def
|
|
|
|
endif
|
|
|
|
for key in keys
|
|
|
|
execute 'nnoremap <script> <silent> <buffer> ' . key .
|
|
|
|
\ ' :call <SID>' . func . '<CR>'
|
|
|
|
endfor
|
|
|
|
unlet def
|
|
|
|
endfor
|
2014-04-05 14:08:54 +08:00
|
|
|
|
|
|
|
let b:tagbar_mapped_keys = 1
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CreateAutocommands() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CreateAutocommands() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Creating autocommands')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
augroup TagbarAutoCmds
|
|
|
|
autocmd!
|
2012-08-26 21:57:56 +08:00
|
|
|
autocmd CursorHold __Tagbar__ call s:ShowPrototype(1)
|
2012-03-26 14:42:12 +08:00
|
|
|
autocmd WinEnter __Tagbar__ call s:SetStatusLine('current')
|
|
|
|
autocmd WinLeave __Tagbar__ call s:SetStatusLine('noncurrent')
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-11-11 13:23:22 +08:00
|
|
|
if g:tagbar_autopreview
|
|
|
|
autocmd CursorMoved __Tagbar__ nested call s:ShowInPreviewWin()
|
|
|
|
endif
|
|
|
|
|
2013-11-30 14:28:18 +08:00
|
|
|
autocmd WinEnter * nested call s:QuitIfOnlyWindow()
|
2013-11-04 17:30:17 +08:00
|
|
|
autocmd WinEnter * if bufwinnr('__Tagbar__') == -1 |
|
|
|
|
\ call s:ShrinkIfExpanded() |
|
|
|
|
\ endif
|
|
|
|
|
2013-09-18 13:44:52 +08:00
|
|
|
autocmd BufWritePost * call
|
2012-07-22 17:49:17 +08:00
|
|
|
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'), 1)
|
2013-11-05 04:16:58 +08:00
|
|
|
" BufReadPost is needed for reloading the current buffer if the file
|
|
|
|
" was changed by an external command; see commit 17d199f
|
2013-09-18 13:44:52 +08:00
|
|
|
autocmd BufReadPost,BufEnter,CursorHold,FileType * call
|
2012-07-22 17:49:17 +08:00
|
|
|
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'), 0)
|
2014-04-03 20:08:12 +08:00
|
|
|
autocmd BufDelete,BufWipeout * call
|
|
|
|
\ s:known_files.rm(fnamemodify(expand('<afile>'), ':p'))
|
2012-02-23 15:42:35 +08:00
|
|
|
|
2013-11-04 17:51:38 +08:00
|
|
|
autocmd QuickFixCmdPre * let s:tagbar_qf_active = 1
|
2013-11-06 08:27:16 +08:00
|
|
|
autocmd QuickFixCmdPost * if exists('s:tagbar_qf_active') |
|
|
|
|
\ unlet s:tagbar_qf_active |
|
2013-11-06 09:11:16 +08:00
|
|
|
\ endif
|
2013-11-04 17:51:38 +08:00
|
|
|
|
2012-02-23 15:42:35 +08:00
|
|
|
autocmd VimEnter * call s:CorrectFocusOnStartup()
|
2011-06-29 04:59:49 +08:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
let s:autocommands_done = 1
|
2012-10-01 21:22:35 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:CheckForExCtags() {{{2
|
|
|
|
" Test whether the ctags binary is actually Exuberant Ctags and not GNU ctags
|
|
|
|
" (or something else)
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CheckForExCtags(silent) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Checking for Exuberant Ctags')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2012-07-01 15:21:44 +08:00
|
|
|
if !exists('g:tagbar_ctags_bin')
|
|
|
|
let ctagsbins = []
|
|
|
|
let ctagsbins += ['ctags-exuberant'] " Debian
|
|
|
|
let ctagsbins += ['exuberant-ctags']
|
|
|
|
let ctagsbins += ['exctags'] " FreeBSD, NetBSD
|
|
|
|
let ctagsbins += ['/usr/local/bin/ctags'] " Homebrew
|
|
|
|
let ctagsbins += ['/opt/local/bin/ctags'] " Macports
|
|
|
|
let ctagsbins += ['ectags'] " OpenBSD
|
|
|
|
let ctagsbins += ['ctags']
|
|
|
|
let ctagsbins += ['ctags.exe']
|
|
|
|
let ctagsbins += ['tags']
|
|
|
|
for ctags in ctagsbins
|
|
|
|
if executable(ctags)
|
|
|
|
let g:tagbar_ctags_bin = ctags
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
if !exists('g:tagbar_ctags_bin')
|
2013-08-23 14:02:24 +08:00
|
|
|
let errmsg = 'Tagbar: Exuberant ctags not found!'
|
|
|
|
let infomsg = 'Please download Exuberant Ctags from' .
|
|
|
|
\ ' ctags.sourceforge.net and install it in a' .
|
|
|
|
\ ' directory in your $PATH or set g:tagbar_ctags_bin.'
|
|
|
|
call s:CtagsErrMsg(errmsg, infomsg, a:silent)
|
2012-07-01 15:21:44 +08:00
|
|
|
let s:checked_ctags = 2
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
" reset 'wildignore' temporarily in case *.exe is included in it
|
|
|
|
let wildignore_save = &wildignore
|
|
|
|
set wildignore&
|
|
|
|
|
|
|
|
let g:tagbar_ctags_bin = expand(g:tagbar_ctags_bin)
|
|
|
|
|
|
|
|
let &wildignore = wildignore_save
|
|
|
|
|
|
|
|
if !executable(g:tagbar_ctags_bin)
|
2013-08-23 14:02:24 +08:00
|
|
|
let errmsg = "Tagbar: Exuberant ctags not found at " .
|
|
|
|
\ "'" . g:tagbar_ctags_bin . "'!"
|
|
|
|
let infomsg = 'Please check your g:tagbar_ctags_bin setting.'
|
|
|
|
call s:CtagsErrMsg(errmsg, infomsg, a:silent)
|
2012-07-01 15:21:44 +08:00
|
|
|
let s:checked_ctags = 2
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let ctags_cmd = s:EscapeCtagsCmd(g:tagbar_ctags_bin, '--version')
|
|
|
|
if ctags_cmd == ''
|
2012-07-01 14:48:00 +08:00
|
|
|
let s:checked_ctags = 2
|
|
|
|
return 0
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
let ctags_output = s:ExecuteCtags(ctags_cmd)
|
|
|
|
|
|
|
|
if v:shell_error || ctags_output !~# 'Exuberant Ctags'
|
2013-08-23 14:02:24 +08:00
|
|
|
let errmsg = 'Tagbar: Ctags doesn''t seem to be Exuberant Ctags!'
|
|
|
|
let infomsg = '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.'
|
|
|
|
call s:CtagsErrMsg(errmsg, infomsg, a:silent, ctags_cmd, ctags_output)
|
2012-07-01 14:48:00 +08:00
|
|
|
let s:checked_ctags = 2
|
2011-06-29 04:59:49 +08:00
|
|
|
return 0
|
|
|
|
elseif !s:CheckExCtagsVersion(ctags_output)
|
2013-08-23 14:02:24 +08:00
|
|
|
let errmsg = 'Tagbar: Exuberant Ctags is too old!'
|
|
|
|
let infomsg = 'You need at least version 5.5 for Tagbar to work.' .
|
|
|
|
\ ' Please download a newer version from ctags.sourceforge.net.'
|
|
|
|
call s:CtagsErrMsg(errmsg, infomsg, a:silent, ctags_cmd, ctags_output)
|
2012-07-01 14:48:00 +08:00
|
|
|
let s:checked_ctags = 2
|
2011-06-29 04:59:49 +08:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
let s:checked_ctags = 1
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-08-23 14:02:24 +08:00
|
|
|
" s:CtagsErrMsg() {{{2
|
|
|
|
function! s:CtagsErrMsg(errmsg, infomsg, silent, ...) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug(a:errmsg)
|
2013-08-23 14:02:24 +08:00
|
|
|
let ctags_cmd = a:0 > 0 ? a:1 : ''
|
|
|
|
let ctags_output = a:0 > 0 ? a:2 : ''
|
|
|
|
|
|
|
|
if ctags_output != ''
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("Command output:\n" . ctags_output)
|
2013-08-23 14:02:24 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !a:silent
|
2014-10-27 17:35:19 +08:00
|
|
|
call s:warning(a:errmsg)
|
2013-08-23 14:02:24 +08:00
|
|
|
echomsg a:infomsg
|
|
|
|
|
|
|
|
if ctags_cmd == ''
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
echomsg 'Executed command: "' . ctags_cmd . '"'
|
|
|
|
if ctags_output != ''
|
|
|
|
echomsg 'Command output:'
|
|
|
|
for line in split(ctags_output, '\n')
|
|
|
|
echomsg line
|
|
|
|
endfor
|
2013-08-24 13:40:12 +08:00
|
|
|
else
|
|
|
|
echomsg 'Command output is empty.'
|
2013-08-23 14:02:24 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:CheckExCtagsVersion() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CheckExCtagsVersion(output) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Checking Exuberant Ctags version')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-10-15 13:40:27 +08:00
|
|
|
if a:output =~ 'Exuberant Ctags Development'
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("Found development version, assuming compatibility")
|
2011-10-15 13:40:27 +08:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let matchlist = matchlist(a:output, '\vExuberant Ctags (\d+)\.(\d+)')
|
|
|
|
let major = matchlist[1]
|
|
|
|
let minor = matchlist[2]
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("Ctags version: major='" . major . "', minor='" . minor . "'")
|
2013-08-24 14:38:04 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
return major >= 6 || (major == 5 && minor >= 5)
|
|
|
|
endfunction
|
|
|
|
|
2011-12-21 15:33:31 +08:00
|
|
|
" s:CheckFTCtags() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CheckFTCtags(bin, ftype) abort
|
2011-12-21 15:33:31 +08:00
|
|
|
if executable(a:bin)
|
|
|
|
return a:bin
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('g:tagbar_type_' . a:ftype)
|
2014-12-10 10:34:14 +08:00
|
|
|
let userdef = g:tagbar_type_{a:ftype}
|
2011-12-21 15:33:31 +08:00
|
|
|
if has_key(userdef, 'ctagsbin')
|
|
|
|
return userdef.ctagsbin
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2012-02-12 13:36:45 +08:00
|
|
|
" s:GetSupportedFiletypes() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:GetSupportedFiletypes() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Getting filetypes sypported by Exuberant Ctags')
|
2012-02-12 13:36:45 +08:00
|
|
|
|
|
|
|
let ctags_cmd = s:EscapeCtagsCmd(g:tagbar_ctags_bin, '--list-languages')
|
|
|
|
if ctags_cmd == ''
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let ctags_output = s:ExecuteCtags(ctags_cmd)
|
|
|
|
|
|
|
|
if v:shell_error
|
|
|
|
" this shouldn't happen as potential problems would have already been
|
|
|
|
" caught by the previous ctags checking
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let types = split(ctags_output, '\n\+')
|
|
|
|
|
|
|
|
for type in types
|
|
|
|
let s:ctags_types[tolower(type)] = 1
|
|
|
|
endfor
|
|
|
|
|
|
|
|
let s:checked_ctags_types = 1
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Prototypes {{{1
|
|
|
|
" Base tag {{{2
|
|
|
|
let s:BaseTag = {}
|
|
|
|
|
2012-02-28 17:45:11 +08:00
|
|
|
" s:BaseTag.New() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.New(name) abort dict
|
2012-02-28 17:45:11 +08:00
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
call newobj._init(a:name)
|
|
|
|
|
|
|
|
return newobj
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:BaseTag._init() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag._init(name) abort dict
|
2012-03-16 18:51:35 +08:00
|
|
|
let self.name = a:name
|
|
|
|
let self.fields = {}
|
|
|
|
let self.fields.line = 0
|
|
|
|
let self.fields.column = 1
|
2012-08-26 21:57:56 +08:00
|
|
|
let self.prototype = ''
|
2012-03-16 18:51:35 +08:00
|
|
|
let self.path = ''
|
|
|
|
let self.fullpath = a:name
|
|
|
|
let self.depth = 0
|
|
|
|
let self.parent = {}
|
|
|
|
let self.tline = -1
|
|
|
|
let self.fileinfo = {}
|
2012-04-15 19:10:34 +08:00
|
|
|
let self.typeinfo = {}
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isNormalTag() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.isNormalTag() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isPseudoTag() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.isPseudoTag() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isKindheader() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.isKindheader() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.getPrototype() {{{3
|
2012-08-26 21:57:56 +08:00
|
|
|
function! s:BaseTag.getPrototype(short) abort dict
|
|
|
|
return self.prototype
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag._getPrefix() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag._getPrefix() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
|
|
|
|
if has_key(self, 'children') && !empty(self.children)
|
|
|
|
if fileinfo.tagfolds[self.fields.kind][self.fullpath]
|
|
|
|
let prefix = s:icon_closed
|
|
|
|
else
|
|
|
|
let prefix = s:icon_open
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let prefix = ' '
|
|
|
|
endif
|
2012-11-22 13:05:59 +08:00
|
|
|
" Visibility is called 'access' in the ctags output
|
2012-11-22 13:42:14 +08:00
|
|
|
if g:tagbar_show_visibility
|
|
|
|
if has_key(self.fields, 'access')
|
|
|
|
let prefix .= get(s:visibility_symbols, self.fields.access, ' ')
|
|
|
|
else
|
|
|
|
let prefix .= ' '
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
return prefix
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.initFoldState() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.initFoldState() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let fileinfo = self.fileinfo
|
|
|
|
|
|
|
|
if s:known_files.has(fileinfo.fpath) &&
|
2013-02-26 16:56:12 +08:00
|
|
|
\ has_key(fileinfo, '_tagfolds_old') &&
|
2011-06-29 04:59:49 +08:00
|
|
|
\ 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
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.getClosedParentTline() abort dict
|
2012-06-22 21:30:45 +08:00
|
|
|
let tagline = self.tline
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-06-22 21:30:45 +08:00
|
|
|
" Find the first closed parent, starting from the top of the hierarchy.
|
|
|
|
let parents = []
|
|
|
|
let curparent = self.parent
|
|
|
|
while !empty(curparent)
|
|
|
|
call add(parents, curparent)
|
|
|
|
let curparent = curparent.parent
|
|
|
|
endwhile
|
|
|
|
for parent in reverse(parents)
|
2011-06-29 04:59:49 +08:00
|
|
|
if parent.isFolded()
|
|
|
|
let tagline = parent.tline
|
|
|
|
break
|
|
|
|
endif
|
2012-06-22 21:30:45 +08:00
|
|
|
endfor
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
return tagline
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isFoldable() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.isFoldable() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return has_key(self, 'children') && !empty(self.children)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.isFolded() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.isFolded() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return self.fileinfo.tagfolds[self.fields.kind][self.fullpath]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.openFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.openFold() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
if self.isFoldable()
|
|
|
|
let self.fileinfo.tagfolds[self.fields.kind][self.fullpath] = 0
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.closeFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.closeFold() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
2011-11-24 14:22:31 +08:00
|
|
|
let newline = self.tline
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.setFolded(folded) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.fileinfo.tagfolds[self.fields.kind][self.fullpath] = a:folded
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:BaseTag.openParents() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:BaseTag.openParents() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let parent = self.parent
|
|
|
|
|
|
|
|
while !empty(parent)
|
|
|
|
call parent.openFold()
|
|
|
|
let parent = parent.parent
|
|
|
|
endwhile
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Normal tag {{{2
|
|
|
|
let s:NormalTag = copy(s:BaseTag)
|
|
|
|
|
|
|
|
" s:NormalTag.isNormalTag() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:NormalTag.isNormalTag() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
" s:NormalTag.strfmt() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:NormalTag.strfmt() abort dict
|
2012-04-15 19:10:34 +08:00
|
|
|
let typeinfo = self.typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
let suffix = get(self.fields, 'signature', '')
|
|
|
|
if has_key(self.fields, 'type')
|
|
|
|
let suffix .= ' : ' . self.fields.type
|
|
|
|
elseif has_key(typeinfo, 'kind2scope') &&
|
|
|
|
\ has_key(typeinfo.kind2scope, self.fields.kind)
|
|
|
|
let suffix .= ' : ' . typeinfo.kind2scope[self.fields.kind]
|
|
|
|
endif
|
|
|
|
|
|
|
|
return self._getPrefix() . self.name . suffix . "\n"
|
|
|
|
endfunction
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
" s:NormalTag.str() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:NormalTag.str(longsig, full) abort dict
|
2012-04-15 19:10:34 +08:00
|
|
|
if a:full && self.path != ''
|
|
|
|
let str = self.path . self.typeinfo.sro . self.name
|
|
|
|
else
|
|
|
|
let str = self.name
|
|
|
|
endif
|
2012-02-28 19:21:50 +08:00
|
|
|
|
|
|
|
if has_key(self.fields, 'signature')
|
|
|
|
if a:longsig
|
|
|
|
let str .= self.fields.signature
|
|
|
|
else
|
|
|
|
let str .= '()'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
return str
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:NormalTag.getPrototype() {{{3
|
2012-08-26 21:57:56 +08:00
|
|
|
function! s:NormalTag.getPrototype(short) abort dict
|
|
|
|
if self.prototype != ''
|
|
|
|
let prototype = self.prototype
|
|
|
|
else
|
|
|
|
let bufnr = self.fileinfo.bufnr
|
|
|
|
|
2014-10-14 06:19:08 +08:00
|
|
|
if self.fields.line == 0 || !bufloaded(bufnr)
|
|
|
|
" No linenumber available or buffer not loaded (probably due to
|
|
|
|
" 'nohidden'), try the pattern instead
|
2014-10-11 13:37:21 +08:00
|
|
|
return substitute(self.pattern, '^\\V\\^\\C\s*\(.*\)\\$$', '\1', '')
|
|
|
|
endif
|
|
|
|
|
2012-08-26 21:57:56 +08:00
|
|
|
let line = getbufline(bufnr, self.fields.line)[0]
|
|
|
|
let list = split(line, '\zs')
|
|
|
|
|
|
|
|
let start = index(list, '(')
|
|
|
|
if start == -1
|
|
|
|
return substitute(line, '^\s\+', '', '')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let opening = count(list, '(', 0, start)
|
|
|
|
let closing = count(list, ')', 0, start)
|
|
|
|
if closing >= opening
|
|
|
|
return substitute(line, '^\s\+', '', '')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let balance = opening - closing
|
|
|
|
|
|
|
|
let prototype = line
|
|
|
|
let curlinenr = self.fields.line + 1
|
|
|
|
while balance > 0
|
|
|
|
let curline = getbufline(bufnr, curlinenr)[0]
|
|
|
|
let curlist = split(curline, '\zs')
|
|
|
|
let balance += count(curlist, '(')
|
|
|
|
let balance -= count(curlist, ')')
|
|
|
|
let prototype .= "\n" . curline
|
|
|
|
let curlinenr += 1
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
let self.prototype = prototype
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:short
|
|
|
|
" join all lines and remove superfluous spaces
|
|
|
|
let prototype = substitute(prototype, '^\s\+', '', '')
|
|
|
|
let prototype = substitute(prototype, '\_s\+', ' ', 'g')
|
|
|
|
let prototype = substitute(prototype, '(\s\+', '(', 'g')
|
|
|
|
let prototype = substitute(prototype, '\s\+)', ')', 'g')
|
|
|
|
" Avoid hit-enter prompts
|
|
|
|
let maxlen = &columns - 12
|
|
|
|
if len(prototype) > maxlen
|
|
|
|
let prototype = prototype[:maxlen - 1 - 3]
|
|
|
|
let prototype .= '...'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
return prototype
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Pseudo tag {{{2
|
|
|
|
let s:PseudoTag = copy(s:BaseTag)
|
|
|
|
|
|
|
|
" s:PseudoTag.isPseudoTag() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:PseudoTag.isPseudoTag() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
" s:PseudoTag.strfmt() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:PseudoTag.strfmt() abort dict
|
2012-04-15 19:10:34 +08:00
|
|
|
let typeinfo = self.typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
let suffix = get(self.fields, 'signature', '')
|
|
|
|
if has_key(typeinfo.kind2scope, self.fields.kind)
|
|
|
|
let suffix .= ' : ' . typeinfo.kind2scope[self.fields.kind]
|
|
|
|
endif
|
|
|
|
|
|
|
|
return self._getPrefix() . self.name . '*' . suffix
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Kind header {{{2
|
|
|
|
let s:KindheaderTag = copy(s:BaseTag)
|
|
|
|
|
|
|
|
" s:KindheaderTag.isKindheader() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:KindheaderTag.isKindheader() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.getPrototype() {{{3
|
2012-08-26 21:57:56 +08:00
|
|
|
function! s:KindheaderTag.getPrototype(short) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return self.name . ': ' .
|
|
|
|
\ self.numtags . ' ' . (self.numtags > 1 ? 'tags' : 'tag')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.isFoldable() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:KindheaderTag.isFoldable() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.isFolded() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:KindheaderTag.isFolded() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return self.fileinfo.kindfolds[self.short]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.openFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:KindheaderTag.openFold() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.fileinfo.kindfolds[self.short] = 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.closeFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:KindheaderTag.closeFold() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.fileinfo.kindfolds[self.short] = 1
|
|
|
|
return line('.')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:KindheaderTag.toggleFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:KindheaderTag.toggleFold() abort dict
|
2013-12-09 11:30:38 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
let fileinfo.kindfolds[self.short] = !fileinfo.kindfolds[self.short]
|
|
|
|
endfunction
|
|
|
|
|
2012-03-14 17:22:44 +08:00
|
|
|
" Type info {{{2
|
|
|
|
let s:TypeInfo = {}
|
|
|
|
|
|
|
|
" s:TypeInfo.New() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:TypeInfo.New(...) abort dict
|
2012-03-14 17:22:44 +08:00
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
let newobj.kinddict = {}
|
|
|
|
|
|
|
|
if a:0 > 0
|
|
|
|
call extend(newobj, a:1)
|
|
|
|
endif
|
|
|
|
|
|
|
|
return newobj
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:TypeInfo.getKind() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:TypeInfo.getKind(kind) abort dict
|
2012-03-14 17:22:44 +08:00
|
|
|
let idx = self.kinddict[a:kind]
|
|
|
|
return self.kinds[idx]
|
|
|
|
endfunction
|
|
|
|
|
2013-04-23 14:16:10 +08:00
|
|
|
" s:TypeInfo.createKinddict() {{{3
|
|
|
|
" Create a dictionary of the kind order for fast access in sorting functions
|
|
|
|
function! s:TypeInfo.createKinddict() abort dict
|
|
|
|
let i = 0
|
|
|
|
for kind in self.kinds
|
|
|
|
let self.kinddict[kind.short] = i
|
|
|
|
let i += 1
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" File info {{{2
|
|
|
|
let s:FileInfo = {}
|
|
|
|
|
|
|
|
" s:FileInfo.New() {{{3
|
2013-04-23 14:07:29 +08:00
|
|
|
function! s:FileInfo.New(fname, ftype, typeinfo) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let newobj = copy(self)
|
|
|
|
|
|
|
|
" The complete file path
|
|
|
|
let newobj.fpath = a:fname
|
|
|
|
|
2012-07-22 17:49:17 +08:00
|
|
|
let newobj.bufnr = bufnr(a:fname)
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" 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 = {}
|
2013-04-23 14:07:29 +08:00
|
|
|
let newobj.typeinfo = a:typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
" copy the default fold state from the type info
|
2013-04-23 14:07:29 +08:00
|
|
|
for kind in a:typeinfo.kinds
|
2011-06-29 04:59:49 +08:00
|
|
|
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 = {}
|
2013-04-23 14:07:29 +08:00
|
|
|
for kind in a:typeinfo.kinds
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:FileInfo.reset() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.mtime = getftime(self.fpath)
|
|
|
|
let self.tags = []
|
|
|
|
let self.fline = {}
|
|
|
|
let self.tline = {}
|
|
|
|
|
|
|
|
let self._tagfolds_old = self.tagfolds
|
|
|
|
let self.tagfolds = {}
|
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
for kind in self.typeinfo.kinds
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.tagfolds[kind.short] = {}
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.clearOldFolds() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:FileInfo.clearOldFolds() abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
if exists('self._tagfolds_old')
|
|
|
|
unlet self._tagfolds_old
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.sortTags() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:FileInfo.sortTags() abort dict
|
2013-07-17 12:50:02 +08:00
|
|
|
if get(s:compare_typeinfo, 'sort', g:tagbar_sort)
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:SortTags(self.tags, 's:CompareByKind')
|
|
|
|
else
|
|
|
|
call s:SortTags(self.tags, 's:CompareByLine')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.openKindFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:FileInfo.openKindFold(kind) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.kindfolds[a:kind.short] = 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:FileInfo.closeKindFold() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:FileInfo.closeKindFold(kind) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self.kindfolds[a:kind.short] = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Known files {{{2
|
|
|
|
let s:known_files = {
|
|
|
|
\ '_current' : {},
|
2013-11-06 17:33:27 +08:00
|
|
|
\ '_paused' : {},
|
2011-06-29 04:59:49 +08:00
|
|
|
\ '_files' : {}
|
|
|
|
\ }
|
|
|
|
|
|
|
|
" s:known_files.getCurrent() {{{3
|
2013-11-06 17:33:27 +08:00
|
|
|
function! s:known_files.getCurrent(forcecurrent) abort dict
|
|
|
|
if !s:paused || a:forcecurrent
|
|
|
|
return self._current
|
|
|
|
else
|
|
|
|
return self._paused
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.setCurrent() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:known_files.setCurrent(fileinfo) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
let self._current = a:fileinfo
|
|
|
|
endfunction
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
" s:known_files.setPaused() {{{3
|
|
|
|
function! s:known_files.setPaused() abort dict
|
|
|
|
let self._paused = self._current
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:known_files.get() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:known_files.get(fname) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return get(self._files, a:fname, {})
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.put() {{{3
|
|
|
|
" Optional second argument is the filename
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:known_files.put(fileinfo, ...) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:known_files.has(fname) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
return has_key(self._files, a:fname)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:known_files.rm() {{{3
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:known_files.rm(fname) abort dict
|
2011-06-29 04:59:49 +08:00
|
|
|
if s:known_files.has(a:fname)
|
2014-04-03 20:08:12 +08:00
|
|
|
call s:debug('Removing fileinfo for [' . a:fname . ']')
|
2011-06-29 04:59:49 +08:00
|
|
|
call remove(self._files, a:fname)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Window management {{{1
|
|
|
|
" s:ToggleWindow() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ToggleWindow() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('ToggleWindow called')
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let tagbarwinnr = bufwinnr("__Tagbar__")
|
|
|
|
if tagbarwinnr != -1
|
|
|
|
call s:CloseWindow()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-12-21 14:28:34 +08:00
|
|
|
call s:OpenWindow('')
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('ToggleWindow finished')
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:OpenWindow() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:OpenWindow(flags) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("OpenWindow called with flags: '" . a:flags . "'")
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2011-11-23 14:56:31 +08:00
|
|
|
let autofocus = a:flags =~# 'f'
|
|
|
|
let jump = a:flags =~# 'j'
|
|
|
|
let autoclose = a:flags =~# 'c'
|
|
|
|
|
2012-01-31 15:58:49 +08:00
|
|
|
let curfile = fnamemodify(bufname('%'), ':p')
|
2012-04-22 00:28:28 +08:00
|
|
|
let curline = line('.')
|
2012-01-31 15:58:49 +08:00
|
|
|
|
2011-11-23 14:56:31 +08:00
|
|
|
" If the tagbar window is already open check jump flag
|
|
|
|
" Also set the autoclose flag if requested
|
2011-06-29 04:59:49 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr != -1
|
2011-11-23 14:56:31 +08:00
|
|
|
if winnr() != tagbarwinnr && jump
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr)
|
2013-06-25 12:32:33 +08:00
|
|
|
call s:HighlightTag(g:tagbar_autoshowtag != 2, 1, curline)
|
2011-11-23 14:56:31 +08:00
|
|
|
endif
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("OpenWindow finished, Tagbar already open")
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-02-23 15:42:35 +08:00
|
|
|
" This is only needed for the CorrectFocusOnStartup() function
|
|
|
|
let s:last_autofocus = autofocus
|
|
|
|
|
2012-07-01 14:48:00 +08:00
|
|
|
if !s:Init(0)
|
2012-02-12 13:36:45 +08:00
|
|
|
return 0
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Expand the Vim window to accomodate for the Tagbar window if requested
|
2013-03-18 14:09:12 +08:00
|
|
|
" and save the window positions to be able to restore them later.
|
2013-08-30 12:57:27 +08:00
|
|
|
if g:tagbar_expand >= 1 && !s:window_expanded &&
|
|
|
|
\ (has('gui_running') || g:tagbar_expand == 2)
|
2013-03-18 14:09:12 +08:00
|
|
|
let s:window_pos.pre.x = getwinposx()
|
|
|
|
let s:window_pos.pre.y = getwinposy()
|
2011-06-29 04:59:49 +08:00
|
|
|
let &columns += g:tagbar_width + 1
|
2013-03-18 14:09:12 +08:00
|
|
|
let s:window_pos.post.x = getwinposx()
|
|
|
|
let s:window_pos.post.y = getwinposy()
|
2011-06-29 04:59:49 +08:00
|
|
|
let s:window_expanded = 1
|
|
|
|
endif
|
|
|
|
|
2013-11-06 12:06:39 +08:00
|
|
|
let s:window_opening = 1
|
2014-11-08 16:30:17 +08:00
|
|
|
if g:tagbar_vertical == 0
|
|
|
|
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
|
|
|
|
let width = g:tagbar_width
|
|
|
|
else
|
|
|
|
let openpos = g:tagbar_left ? 'leftabove ' : 'rightbelow '
|
|
|
|
let width = g:tagbar_vertical
|
|
|
|
endif
|
|
|
|
exe 'silent keepalt ' . openpos . width . 'split ' . '__Tagbar__'
|
2013-11-06 12:06:39 +08:00
|
|
|
unlet s:window_opening
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2011-11-23 14:56:31 +08:00
|
|
|
call s:InitWindow(autoclose)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-03-23 14:46:14 +08:00
|
|
|
" If the current file exists, but is empty, it means that it had a
|
|
|
|
" processing error before opening the window, most likely due to a call to
|
|
|
|
" currenttag() in the statusline. Remove the entry so an error message
|
|
|
|
" will be shown if the processing still fails.
|
|
|
|
if empty(s:known_files.get(curfile))
|
|
|
|
call s:known_files.rm(curfile)
|
|
|
|
endif
|
|
|
|
|
2012-07-22 17:49:17 +08:00
|
|
|
call s:AutoUpdate(curfile, 0)
|
2013-06-25 12:32:33 +08:00
|
|
|
call s:HighlightTag(g:tagbar_autoshowtag != 2, 1, curline)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-01-31 15:58:49 +08:00
|
|
|
if !(g:tagbar_autoclose || autofocus || g:tagbar_autofocus)
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win('p')
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('OpenWindow finished')
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:InitWindow() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:InitWindow(autoclose) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('InitWindow called with autoclose: ' . a:autoclose)
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2012-06-23 12:39:07 +08:00
|
|
|
setlocal filetype=tagbar
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
setlocal noreadonly " in case the "view" mode is used
|
|
|
|
setlocal buftype=nofile
|
|
|
|
setlocal bufhidden=hide
|
|
|
|
setlocal noswapfile
|
|
|
|
setlocal nobuflisted
|
|
|
|
setlocal nomodifiable
|
|
|
|
setlocal nolist
|
|
|
|
setlocal nowrap
|
|
|
|
setlocal winfixwidth
|
|
|
|
setlocal textwidth=0
|
2012-06-23 12:39:07 +08:00
|
|
|
setlocal nospell
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-08-24 17:45:10 +08:00
|
|
|
if g:tagbar_show_linenumbers == 0
|
|
|
|
setlocal nonumber
|
|
|
|
if exists('+relativenumber')
|
|
|
|
setlocal norelativenumber
|
|
|
|
endif
|
|
|
|
elseif g:tagbar_show_linenumbers == 1
|
|
|
|
setlocal number
|
|
|
|
elseif g:tagbar_show_linenumbers == 2
|
|
|
|
setlocal relativenumber
|
|
|
|
else
|
|
|
|
set number<
|
|
|
|
if exists('+relativenumber')
|
|
|
|
set relativenumber<
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
setlocal nofoldenable
|
2011-10-22 21:23:58 +08:00
|
|
|
setlocal foldcolumn=0
|
2011-06-29 04:59:49 +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&
|
|
|
|
|
2014-06-25 13:52:43 +08:00
|
|
|
let w:autoclose = a:autoclose
|
|
|
|
|
2012-03-26 14:42:12 +08:00
|
|
|
call s:SetStatusLine('current')
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-09-04 20:29:28 +08:00
|
|
|
let s:new_window = 1
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if has('balloon_eval')
|
|
|
|
setlocal balloonexpr=TagbarBalloonExpr()
|
|
|
|
set ballooneval
|
|
|
|
endif
|
|
|
|
|
|
|
|
let cpoptions_save = &cpoptions
|
|
|
|
set cpoptions&vim
|
|
|
|
|
2014-04-05 14:08:54 +08:00
|
|
|
if !exists('b:tagbar_mapped_keys')
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:MapKeys()
|
|
|
|
endif
|
|
|
|
|
|
|
|
let &cpoptions = cpoptions_save
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2013-11-04 17:30:17 +08:00
|
|
|
if g:tagbar_expand
|
|
|
|
let s:expand_bufnr = bufnr('%')
|
|
|
|
endif
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('InitWindow finished')
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CloseWindow() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CloseWindow() abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('CloseWindow called')
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-11-22 11:43:06 +08:00
|
|
|
" Close the preview window if it was opened by us
|
2013-11-29 13:40:09 +08:00
|
|
|
if s:pwin_by_tagbar
|
2013-11-22 11:43:06 +08:00
|
|
|
pclose
|
2014-10-14 10:59:29 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
2013-11-22 11:43:06 +08:00
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
if winnr() == tagbarwinnr
|
|
|
|
if winbufnr(2) != -1
|
|
|
|
" Other windows are open, only close the tagbar one
|
2012-02-02 16:07:13 +08:00
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
let curfile = s:known_files.getCurrent(0)
|
2012-02-02 16:07:13 +08:00
|
|
|
|
2013-11-15 11:21:12 +08:00
|
|
|
close
|
2012-01-20 10:56:50 +08:00
|
|
|
|
|
|
|
" Try to jump to the correct window after closing
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win('p')
|
2012-02-02 16:07:13 +08:00
|
|
|
|
|
|
|
if !empty(curfile)
|
|
|
|
let filebufnr = bufnr(curfile.fpath)
|
|
|
|
|
|
|
|
if bufnr('%') != filebufnr
|
|
|
|
let filewinnr = bufwinnr(filebufnr)
|
|
|
|
if filewinnr != -1
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(filewinnr)
|
2012-02-02 16:07:13 +08:00
|
|
|
endif
|
2012-01-20 10:56:50 +08:00
|
|
|
endif
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
else
|
2013-03-24 09:16:56 +08:00
|
|
|
" Go to the tagbar window, close it and then come back to the original
|
|
|
|
" window. Save a win-local variable in the original window so we can
|
|
|
|
" jump back to it even if the window number changed.
|
2014-02-01 16:17:00 +08:00
|
|
|
call s:mark_window()
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr)
|
2011-06-29 04:59:49 +08:00
|
|
|
close
|
2013-03-24 09:16:56 +08:00
|
|
|
|
2014-02-01 16:17:00 +08:00
|
|
|
call s:goto_markedwin()
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2013-11-04 17:30:17 +08:00
|
|
|
call s:ShrinkIfExpanded()
|
2012-01-31 15:59:06 +08:00
|
|
|
|
2013-11-23 20:21:08 +08:00
|
|
|
" The window sizes may have changed due to the shrinking happening after
|
|
|
|
" the window closing, so equalize them again.
|
|
|
|
if &equalalways
|
|
|
|
wincmd =
|
|
|
|
endif
|
|
|
|
|
2013-07-30 07:38:46 +08:00
|
|
|
if s:autocommands_done && !s:statusline_in_use
|
|
|
|
autocmd! TagbarAutoCmds
|
|
|
|
let s:autocommands_done = 0
|
|
|
|
endif
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('CloseWindow finished')
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-11-04 17:30:17 +08:00
|
|
|
" s:ShrinkIfExpanded() {{{2
|
|
|
|
" If the Vim window has been expanded, and Tagbar is not open in any other
|
|
|
|
" tabpages, shrink the window again
|
|
|
|
function! s:ShrinkIfExpanded() abort
|
|
|
|
if !s:window_expanded || &filetype == 'tagbar' || s:expand_bufnr == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let tablist = []
|
|
|
|
for i in range(tabpagenr('$'))
|
|
|
|
call extend(tablist, tabpagebuflist(i + 1))
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if index(tablist, s:expand_bufnr) == -1
|
|
|
|
let &columns -= g:tagbar_width + 1
|
|
|
|
let s:window_expanded = 0
|
|
|
|
let s:expand_bufnr = -1
|
|
|
|
" Only restore window position if it is available and if the
|
|
|
|
" window hasn't been moved manually after the expanding
|
|
|
|
if getwinposx() != -1 &&
|
|
|
|
\ getwinposx() == s:window_pos.post.x &&
|
|
|
|
\ getwinposy() == s:window_pos.post.y
|
|
|
|
execute 'winpos ' . s:window_pos.pre.x .
|
|
|
|
\ ' ' . s:window_pos.pre.y
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:ZoomWindow() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ZoomWindow() abort
|
2011-06-29 04:59:49 +08:00
|
|
|
if s:is_maximized
|
2014-02-04 13:00:27 +08:00
|
|
|
execute 'vertical resize ' . g:tagbar_width
|
2013-05-20 11:18:57 +08:00
|
|
|
execute s:winrestcmd
|
2011-06-29 04:59:49 +08:00
|
|
|
let s:is_maximized = 0
|
|
|
|
else
|
2013-05-20 11:18:57 +08:00
|
|
|
let s:winrestcmd = winrestcmd()
|
2014-02-04 13:00:27 +08:00
|
|
|
if g:tagbar_zoomwidth == 1
|
|
|
|
vertical resize
|
|
|
|
elseif g:tagbar_zoomwidth == 0
|
|
|
|
let func = exists('*strdisplaywidth') ? 'strdisplaywidth' : 'strlen'
|
|
|
|
let maxline = max(map(getline(line('w0'), line('w$')),
|
|
|
|
\ func . '(v:val)'))
|
|
|
|
execute 'vertical resize ' . maxline
|
|
|
|
elseif g:tagbar_zoomwidth > 1
|
|
|
|
execute 'vertical resize ' . g:tagbar_zoomwidth
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
let s:is_maximized = 1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-02-23 15:42:35 +08:00
|
|
|
" s:CorrectFocusOnStartup() {{{2
|
|
|
|
" For whatever reason the focus will be on the Tagbar window if
|
|
|
|
" tagbar#autoopen is used with a FileType autocommand on startup and
|
|
|
|
" g:tagbar_left is set. This should work around it by jumping to the window of
|
|
|
|
" the current file after startup.
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CorrectFocusOnStartup() abort
|
2012-02-23 15:42:35 +08:00
|
|
|
if bufwinnr('__Tagbar__') != -1 && !g:tagbar_autofocus && !s:last_autofocus
|
2013-11-06 17:33:27 +08:00
|
|
|
let curfile = s:known_files.getCurrent(1)
|
2012-02-23 15:42:35 +08:00
|
|
|
if !empty(curfile) && curfile.fpath != fnamemodify(bufname('%'), ':p')
|
|
|
|
let winnr = bufwinnr(curfile.fpath)
|
|
|
|
if winnr != -1
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(winnr)
|
2012-02-23 15:42:35 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Tag processing {{{1
|
|
|
|
" s:ProcessFile() {{{2
|
|
|
|
" Execute ctags and put the information into a 'FileInfo' object
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ProcessFile(fname, ftype) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('ProcessFile called [' . a:fname . ']')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
if !s:IsValidFile(a:fname, a:ftype)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Not a valid file, returning')
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
let typeinfo = s:known_types[a:ftype]
|
|
|
|
|
2012-07-22 17:49:17 +08:00
|
|
|
" If the file has only been updated preserve the fold states, otherwise
|
|
|
|
" create a new entry
|
2014-11-02 12:44:25 +08:00
|
|
|
if s:known_files.has(a:fname) && !empty(s:known_files.get(a:fname)) &&
|
|
|
|
\ s:known_files.get(a:fname).ftype == a:ftype
|
2012-07-22 17:49:17 +08:00
|
|
|
let fileinfo = s:known_files.get(a:fname)
|
2013-04-23 14:07:29 +08:00
|
|
|
let typeinfo = fileinfo.typeinfo
|
2012-07-22 17:49:17 +08:00
|
|
|
call fileinfo.reset()
|
|
|
|
else
|
2013-05-06 14:49:19 +08:00
|
|
|
if exists('#TagbarProjects#User')
|
|
|
|
execute 'doautocmd <nomodeline> TagbarProjects User ' . a:fname
|
|
|
|
if exists('b:tagbar_type')
|
|
|
|
let typeinfo = extend(copy(typeinfo),
|
|
|
|
\ s:TransformUserTypeDef(b:tagbar_type))
|
|
|
|
call typeinfo.createKinddict()
|
|
|
|
endif
|
2013-04-23 14:07:29 +08:00
|
|
|
endif
|
|
|
|
let fileinfo = s:FileInfo.New(a:fname, a:ftype, typeinfo)
|
2012-07-22 17:49:17 +08:00
|
|
|
endif
|
|
|
|
|
2014-04-04 13:37:47 +08:00
|
|
|
call s:debug('typeinfo for file to process: ' . string(typeinfo))
|
|
|
|
|
2013-02-26 16:56:12 +08:00
|
|
|
" Use a temporary files for ctags processing instead of the original one.
|
|
|
|
" This allows using Tagbar for files accessed with netrw, and also doesn't
|
|
|
|
" slow down Tagbar for files that sit on slow network drives.
|
2012-07-22 17:49:17 +08:00
|
|
|
let tempfile = tempname()
|
2012-08-01 17:08:49 +08:00
|
|
|
let ext = fnamemodify(fileinfo.fpath, ':e')
|
|
|
|
if ext != ''
|
|
|
|
let tempfile .= '.' . ext
|
2012-07-31 12:50:55 +08:00
|
|
|
endif
|
2012-07-22 17:49:17 +08:00
|
|
|
|
|
|
|
call writefile(getbufline(fileinfo.bufnr, 1, '$'), tempfile)
|
|
|
|
let fileinfo.mtime = getftime(tempfile)
|
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
let ctags_output = s:ExecuteCtagsOnFile(tempfile, a:fname, typeinfo)
|
2012-07-22 17:49:17 +08:00
|
|
|
|
|
|
|
call delete(tempfile)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if ctags_output == -1
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Ctags error when processing file')
|
2012-07-22 17:49:17 +08:00
|
|
|
" Put an empty entry into known_files so the error message is only
|
2011-06-29 04:59:49 +08:00
|
|
|
" shown once
|
|
|
|
call s:known_files.put({}, a:fname)
|
|
|
|
return
|
|
|
|
elseif ctags_output == ''
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Ctags output empty')
|
2012-01-31 19:21:28 +08:00
|
|
|
" No need to go through the tag processing if there are no tags, and
|
2012-07-22 17:49:17 +08:00
|
|
|
" preserving the old fold state isn't necessary either
|
2013-04-23 14:07:29 +08:00
|
|
|
call s:known_files.put(s:FileInfo.New(a:fname, a:ftype,
|
|
|
|
\ s:known_types[a:ftype]), a:fname)
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Filetype tag kinds: ' . string(keys(typeinfo.kinddict)))
|
2013-02-04 10:10:06 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Parse the ctags output lines
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Parsing ctags output')
|
2011-06-29 04:59:49 +08:00
|
|
|
let rawtaglist = split(ctags_output, '\n\+')
|
|
|
|
for line in rawtaglist
|
2011-12-12 14:47:59 +08:00
|
|
|
" skip comments
|
|
|
|
if line =~# '^!_TAG_'
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let parts = split(line, ';"')
|
|
|
|
if len(parts) == 2 " Is a valid tag line
|
|
|
|
let taginfo = s:ParseTagline(parts[0], parts[1], typeinfo, fileinfo)
|
|
|
|
let fileinfo.fline[taginfo.fields.line] = taginfo
|
|
|
|
call add(fileinfo.tags, taginfo)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" Process scoped tags
|
|
|
|
let processedtags = []
|
|
|
|
if has_key(typeinfo, 'kind2scope')
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Processing scoped tags')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let scopedtags = []
|
|
|
|
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 . ')')
|
|
|
|
|
|
|
|
call s:AddScopedTags(scopedtags, processedtags, {}, 0,
|
2013-04-29 12:49:17 +08:00
|
|
|
\ typeinfo, fileinfo, line('$'))
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if !empty(scopedtags)
|
|
|
|
echoerr 'Tagbar: ''scopedtags'' not empty after processing,'
|
|
|
|
\ 'this should never happen!'
|
|
|
|
\ 'Please contact the script maintainer with an example.'
|
|
|
|
endif
|
|
|
|
endif
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Number of top-level tags: ' . len(processedtags))
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Create a placeholder tag for the 'kind' header for folding purposes
|
|
|
|
for kind in typeinfo.kinds
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let curtags = filter(copy(fileinfo.tags),
|
|
|
|
\ 'v:val.fields.kind ==# kind.short')
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Processing kind: ' . kind.short .
|
|
|
|
\ ', number of tags: ' . len(curtags))
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if empty(curtags)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
let kindtag = s:KindheaderTag.New(kind.long)
|
|
|
|
let kindtag.short = kind.short
|
|
|
|
let kindtag.numtags = len(curtags)
|
|
|
|
let kindtag.fileinfo = fileinfo
|
|
|
|
|
|
|
|
for tag in curtags
|
|
|
|
let tag.parent = kindtag
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if !empty(processedtags)
|
|
|
|
call extend(fileinfo.tags, processedtags)
|
|
|
|
endif
|
|
|
|
|
2011-12-12 14:47:43 +08:00
|
|
|
" Clear old folding information from previous file version to prevent leaks
|
2011-06-29 04:59:49 +08:00
|
|
|
call fileinfo.clearOldFolds()
|
|
|
|
|
|
|
|
" Sort the tags
|
|
|
|
let s:compare_typeinfo = typeinfo
|
|
|
|
call fileinfo.sortTags()
|
|
|
|
|
|
|
|
call s:known_files.put(fileinfo)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ExecuteCtagsOnFile() {{{2
|
2013-04-23 14:07:29 +08:00
|
|
|
function! s:ExecuteCtagsOnFile(fname, realfname, typeinfo) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('ExecuteCtagsOnFile called [' . a:fname . ']')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
if has_key(a:typeinfo, 'ctagsargs') && type(a:typeinfo.ctagsargs) == type('')
|
|
|
|
" if ctagsargs is a string, prepend and append space separators
|
|
|
|
let ctags_args = ' ' . a:typeinfo.ctagsargs . ' '
|
|
|
|
elseif has_key(a:typeinfo, 'ctagsargs') && type(a:typeinfo.ctagsargs) == type([])
|
|
|
|
let ctags_args = a:typeinfo.ctagsargs
|
|
|
|
" otherwise ctagsargs is not defined or not defined as a valid type
|
2011-06-29 04:59:49 +08:00
|
|
|
else
|
2013-04-03 05:57:30 +08:00
|
|
|
"Prefer constructing ctags_args as a list rather than a string
|
|
|
|
"See s:EscapeCtagsCmd() - It's a best practice to shellescape()
|
|
|
|
"each arg separately because in special cases where space is
|
|
|
|
"intended to be in an argument, spaces in a single ctag_args
|
|
|
|
"string would be ambiguous. Is the space an argument separator
|
|
|
|
"or to be included in the argument
|
|
|
|
let ctags_args = [ '-f',
|
|
|
|
\ '-',
|
|
|
|
\ '--format=2',
|
|
|
|
\ '--excmd=pattern',
|
|
|
|
\ '--fields=nksSa',
|
|
|
|
\ '--extra=',
|
2014-05-01 13:33:31 +08:00
|
|
|
\ '--sort=no',
|
|
|
|
\ '--append=no'
|
2013-04-03 05:57:30 +08:00
|
|
|
\ ]
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Include extra type definitions
|
2013-04-23 14:07:29 +08:00
|
|
|
if has_key(a:typeinfo, 'deffile')
|
2013-04-30 06:12:02 +08:00
|
|
|
let ctags_args += ['--options=' . expand(a:typeinfo.deffile)]
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2014-10-27 17:37:17 +08:00
|
|
|
" Third-party programs may not necessarily make use of this
|
|
|
|
if has_key(a:typeinfo, 'ctagstype')
|
|
|
|
let ctags_type = a:typeinfo.ctagstype
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2014-10-27 17:37:17 +08:00
|
|
|
let ctags_kinds = ''
|
|
|
|
for kind in a:typeinfo.kinds
|
|
|
|
let ctags_kinds .= kind.short
|
|
|
|
endfor
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2014-10-27 17:37:17 +08:00
|
|
|
let ctags_args += ['--language-force=' . ctags_type]
|
|
|
|
let ctags_args += ['--' . ctags_type . '-kinds=' . ctags_kinds]
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2013-04-23 14:07:29 +08:00
|
|
|
if has_key(a:typeinfo, 'ctagsbin')
|
2011-10-15 13:48:29 +08:00
|
|
|
" reset 'wildignore' temporarily in case *.exe is included in it
|
|
|
|
let wildignore_save = &wildignore
|
|
|
|
set wildignore&
|
2013-04-23 14:07:29 +08:00
|
|
|
let ctags_bin = expand(a:typeinfo.ctagsbin)
|
2011-10-15 13:48:29 +08:00
|
|
|
let &wildignore = wildignore_save
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
let ctags_output = s:ExecuteCtags(ctags_cmd)
|
|
|
|
|
|
|
|
if v:shell_error || ctags_output =~ 'Warning: cannot open source file'
|
2013-03-23 14:46:14 +08:00
|
|
|
" Only display an error message if the Tagbar window is open and we
|
|
|
|
" haven't seen the error before.
|
|
|
|
if bufwinnr("__Tagbar__") != -1 &&
|
|
|
|
\ (!s:known_files.has(a:realfname) ||
|
|
|
|
\ !empty(s:known_files.get(a:realfname)))
|
2014-10-27 17:35:19 +08:00
|
|
|
call s:warning('Tagbar: Could not execute ctags for ' . a:realfname . '!')
|
2013-02-26 16:56:12 +08:00
|
|
|
echomsg 'Executed command: "' . ctags_cmd . '"'
|
|
|
|
if !empty(ctags_output)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Command output:')
|
|
|
|
call s:debug(ctags_output)
|
2013-02-26 16:56:12 +08:00
|
|
|
echomsg 'Command output:'
|
|
|
|
for line in split(ctags_output, '\n')
|
|
|
|
echomsg line
|
|
|
|
endfor
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
return -1
|
|
|
|
endif
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Ctags executed successfully')
|
2011-06-29 04:59:49 +08:00
|
|
|
return ctags_output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ParseTagline() {{{2
|
|
|
|
" Structure of a tag line:
|
|
|
|
" tagname<TAB>filename<TAB>expattern;"fields
|
|
|
|
" fields: <TAB>name:value
|
|
|
|
" fields that are always present: kind, line
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ParseTagline(part1, part2, typeinfo, fileinfo) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let basic_info = split(a:part1, '\t')
|
|
|
|
|
|
|
|
let taginfo = s:NormalTag.New(basic_info[0])
|
|
|
|
let taginfo.file = basic_info[1]
|
|
|
|
|
|
|
|
" 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")
|
|
|
|
let start = 2 " skip the slash and the ^
|
|
|
|
let end = strlen(pattern) - 1
|
|
|
|
if pattern[end - 1] ==# '$'
|
|
|
|
let end -= 1
|
|
|
|
let dollar = '\$'
|
|
|
|
else
|
|
|
|
let dollar = ''
|
|
|
|
endif
|
2012-08-26 21:57:56 +08:00
|
|
|
let pattern = strpart(pattern, start, end - start)
|
|
|
|
let taginfo.pattern = '\V\^\C' . pattern . dollar
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-09-15 23:03:11 +08:00
|
|
|
" When splitting fields make sure not to create empty keys or values in
|
|
|
|
" case a value illegally contains tabs
|
|
|
|
let fields = split(a:part2, '^\t\|\t\ze\w\+:')
|
2011-06-29 04:59:49 +08:00
|
|
|
let taginfo.fields.kind = remove(fields, 0)
|
|
|
|
for field in fields
|
|
|
|
" can't use split() since the value can contain ':'
|
2012-03-16 18:51:35 +08:00
|
|
|
let delimit = stridx(field, ':')
|
2012-09-15 23:03:11 +08:00
|
|
|
let key = strpart(field, 0, delimit)
|
|
|
|
" Remove all tabs that may illegally be in the value
|
|
|
|
let val = substitute(strpart(field, delimit + 1), '\t', '', 'g')
|
2011-12-13 13:24:24 +08:00
|
|
|
if len(val) > 0
|
2013-04-29 12:49:17 +08:00
|
|
|
if key == 'line' || key == 'column'
|
|
|
|
let taginfo.fields[key] = str2nr(val)
|
|
|
|
else
|
|
|
|
let taginfo.fields[key] = val
|
|
|
|
endif
|
2011-12-13 13:24:24 +08:00
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
" Needed for jsctags
|
|
|
|
if has_key(taginfo.fields, 'lineno')
|
2013-04-29 12:49:17 +08:00
|
|
|
let taginfo.fields.line = str2nr(taginfo.fields.lineno)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
2013-09-19 08:36:41 +08:00
|
|
|
" Do some sanity checking in case ctags reports invalid line numbers
|
|
|
|
if taginfo.fields.line < 0
|
|
|
|
let taginfo.fields.line = 0
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Make some information easier accessible
|
|
|
|
if has_key(a:typeinfo, 'scope2kind')
|
|
|
|
for scope in keys(a:typeinfo.scope2kind)
|
|
|
|
if has_key(taginfo.fields, scope)
|
|
|
|
let taginfo.scope = scope
|
|
|
|
let taginfo.path = taginfo.fields[scope]
|
|
|
|
|
|
|
|
let taginfo.fullpath = taginfo.path . a:typeinfo.sro .
|
|
|
|
\ taginfo.name
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
let taginfo.depth = len(split(taginfo.path, '\V' . a:typeinfo.sro))
|
|
|
|
endif
|
|
|
|
|
|
|
|
let taginfo.fileinfo = a:fileinfo
|
2012-04-15 19:10:34 +08:00
|
|
|
let taginfo.typeinfo = a:typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Needed for folding
|
|
|
|
try
|
|
|
|
call taginfo.initFoldState()
|
|
|
|
catch /^Vim(\a\+):E716:/ " 'Key not present in Dictionary'
|
|
|
|
" The tag has a 'kind' that doesn't exist in the type definition
|
2014-10-27 17:35:19 +08:00
|
|
|
call s:debug('Warning: Unknown tag kind: ' . taginfo.fields.kind)
|
|
|
|
if index(s:warnings.type, a:typeinfo.ftype) == -1
|
|
|
|
call s:warning('Unknown tag kind encountered: ' .
|
|
|
|
\ '"' . taginfo.fields.kind . '".' .
|
|
|
|
\ ' Your ctags and Tagbar configurations are out of sync!' .
|
|
|
|
\ ' Please read '':help tagbar-extend''.')
|
|
|
|
call add(s:warnings.type, a:typeinfo.ftype)
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endtry
|
|
|
|
|
|
|
|
return taginfo
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:AddScopedTags() {{{2
|
|
|
|
" 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.
|
|
|
|
function! s:AddScopedTags(tags, processedtags, parent, depth,
|
2013-04-29 12:49:17 +08:00
|
|
|
\ typeinfo, fileinfo, maxline) abort
|
2011-06-29 04:59:49 +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
|
|
|
|
|
|
|
|
let is_cur_tag = 'v:val.depth == a:depth'
|
|
|
|
|
|
|
|
if !empty(curpath)
|
|
|
|
" 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 .= ' &&
|
|
|
|
\ (v:val.path ==# curpath ||
|
|
|
|
\ match(v:val.path, ''\V\^\C'' . curpath . a:typeinfo.sro) == 0) &&
|
2013-04-29 12:49:17 +08:00
|
|
|
\ (v:val.path ==# curpath ? (v:val.scope ==# pscope) : 1) &&
|
|
|
|
\ v:val.fields.line >= a:parent.fields.line &&
|
|
|
|
\ v:val.fields.line <= a:maxline'
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
let curtags = filter(copy(a:tags), is_cur_tag)
|
|
|
|
|
|
|
|
if !empty(curtags)
|
|
|
|
call filter(a:tags, '!(' . is_cur_tag . ')')
|
|
|
|
|
|
|
|
let realtags = []
|
|
|
|
let pseudotags = []
|
|
|
|
|
|
|
|
while !empty(curtags)
|
|
|
|
let tag = remove(curtags, 0)
|
|
|
|
|
|
|
|
if tag.path != curpath
|
|
|
|
" tag is child of a pseudo-tag, so create a new pseudo-tag and
|
|
|
|
" add all its children to it
|
|
|
|
let pseudotag = s:ProcessPseudoTag(curtags, tag, a:parent,
|
|
|
|
\ a:typeinfo, a:fileinfo)
|
|
|
|
|
|
|
|
call add(pseudotags, pseudotag)
|
|
|
|
else
|
|
|
|
call add(realtags, tag)
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
" Recursively add the children of the tags on the current level
|
|
|
|
for tag in realtags
|
|
|
|
let tag.parent = a:parent
|
|
|
|
|
|
|
|
if !has_key(a:typeinfo.kind2scope, tag.fields.kind)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !has_key(tag, 'children')
|
|
|
|
let tag.children = []
|
|
|
|
endif
|
|
|
|
|
2013-04-29 12:49:17 +08:00
|
|
|
" Check for tags with the exact same name that may be created
|
|
|
|
" alternatively in a conditional (Issue #139). The only way to
|
|
|
|
" distinguish between them is by line number.
|
|
|
|
let twins = filter(copy(realtags),
|
2013-06-03 13:37:48 +08:00
|
|
|
\ "v:val.fullpath ==# '" .
|
|
|
|
\ substitute(tag.fullpath, "'", "''", 'g') . "'" .
|
2013-04-29 12:49:17 +08:00
|
|
|
\ " && v:val.fields.line != " . tag.fields.line)
|
|
|
|
let maxline = line('$')
|
|
|
|
for twin in twins
|
|
|
|
if twin.fields.line <= maxline &&
|
|
|
|
\ twin.fields.line > tag.fields.line
|
|
|
|
let maxline = twin.fields.line - 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:AddScopedTags(a:tags, tag.children, tag, a:depth + 1,
|
2013-04-29 12:49:17 +08:00
|
|
|
\ a:typeinfo, a:fileinfo, maxline)
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
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
|
|
|
|
call s:ProcessPseudoChildren(a:tags, tag, a:depth, a:typeinfo,
|
|
|
|
\ a:fileinfo)
|
|
|
|
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'
|
|
|
|
|
|
|
|
if !empty(curpath)
|
|
|
|
let is_grandchild .=
|
|
|
|
\ ' && match(v:val.path, ''\V\^\C'' . curpath . a:typeinfo.sro) == 0'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let grandchildren = filter(copy(a:tags), is_grandchild)
|
|
|
|
|
|
|
|
if !empty(grandchildren)
|
|
|
|
call s:AddScopedTags(a:tags, a:processedtags, a:parent, a:depth + 1,
|
2013-04-29 12:49:17 +08:00
|
|
|
\ a:typeinfo, a:fileinfo, a:maxline)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ProcessPseudoTag() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ProcessPseudoTag(curtags, tag, parent, typeinfo, fileinfo) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let curpath = !empty(a:parent) ? a:parent.fullpath : ''
|
|
|
|
|
|
|
|
let pseudoname = substitute(a:tag.path, curpath, '', '')
|
|
|
|
let pseudoname = substitute(pseudoname, '\V\^' . a:typeinfo.sro, '', '')
|
|
|
|
let pseudotag = s:CreatePseudoTag(pseudoname, a:parent, a:tag.scope,
|
|
|
|
\ a:typeinfo, a:fileinfo)
|
|
|
|
let pseudotag.children = [a:tag]
|
|
|
|
|
|
|
|
" get all the other (direct) children of the current pseudo-tag
|
|
|
|
let ispseudochild = 'v:val.path ==# a:tag.path && v:val.scope ==# a:tag.scope'
|
|
|
|
let pseudochildren = filter(copy(a:curtags), ispseudochild)
|
|
|
|
if !empty(pseudochildren)
|
|
|
|
call filter(a:curtags, '!(' . ispseudochild . ')')
|
|
|
|
call extend(pseudotag.children, pseudochildren)
|
|
|
|
endif
|
|
|
|
|
|
|
|
return pseudotag
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ProcessPseudoChildren() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ProcessPseudoChildren(tags, tag, depth, typeinfo, fileinfo) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
for childtag in a:tag.children
|
|
|
|
let childtag.parent = a:tag
|
|
|
|
|
|
|
|
if !has_key(a:typeinfo.kind2scope, childtag.fields.kind)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !has_key(childtag, 'children')
|
|
|
|
let childtag.children = []
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:AddScopedTags(a:tags, childtag.children, childtag, a:depth + 1,
|
2013-04-29 12:49:17 +08:00
|
|
|
\ a:typeinfo, a:fileinfo, line('$'))
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
|
2013-06-03 13:37:48 +08:00
|
|
|
let is_grandchild = 'v:val.depth > a:depth && ' .
|
|
|
|
\ 'match(v:val.path,' .
|
|
|
|
\ '''^\C'' . substitute(a:tag.fullpath, "''", "''''", "g")) == 0'
|
2011-06-29 04:59:49 +08:00
|
|
|
let grandchildren = filter(copy(a:tags), is_grandchild)
|
|
|
|
if !empty(grandchildren)
|
|
|
|
call s:AddScopedTags(a:tags, a:tag.children, a:tag, a:depth + 1,
|
2013-04-29 12:49:17 +08:00
|
|
|
\ a:typeinfo, a:fileinfo, line('$'))
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CreatePseudoTag() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CreatePseudoTag(name, parent, scope, typeinfo, fileinfo) abort
|
2011-06-29 04:59:49 +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
|
|
|
|
|
|
|
|
let pseudotag = s:PseudoTag.New(a:name)
|
|
|
|
let pseudotag.fields.kind = a:typeinfo.scope2kind[a:scope]
|
|
|
|
|
|
|
|
let parentscope = substitute(curpath, a:name . '$', '', '')
|
|
|
|
let parentscope = substitute(parentscope,
|
|
|
|
\ '\V\^' . a:typeinfo.sro . '\$', '', '')
|
|
|
|
|
|
|
|
if pscope != ''
|
|
|
|
let pseudotag.fields[pscope] = parentscope
|
|
|
|
let pseudotag.scope = pscope
|
|
|
|
let pseudotag.path = parentscope
|
|
|
|
let pseudotag.fullpath =
|
|
|
|
\ pseudotag.path . a:typeinfo.sro . pseudotag.name
|
|
|
|
endif
|
|
|
|
let pseudotag.depth = len(split(pseudotag.path, '\V' . a:typeinfo.sro))
|
|
|
|
|
|
|
|
let pseudotag.parent = a:parent
|
|
|
|
|
|
|
|
let pseudotag.fileinfo = a:fileinfo
|
2012-04-15 19:10:34 +08:00
|
|
|
let pseudotag.typeinfo = a:typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
call pseudotag.initFoldState()
|
|
|
|
|
|
|
|
return pseudotag
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Sorting {{{1
|
|
|
|
" s:SortTags() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:SortTags(tags, comparemethod) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
" s:CompareByKind() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CompareByKind(tag1, tag2) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let typeinfo = s:compare_typeinfo
|
|
|
|
|
|
|
|
if typeinfo.kinddict[a:tag1.fields.kind] <#
|
|
|
|
\ typeinfo.kinddict[a:tag2.fields.kind]
|
|
|
|
return -1
|
|
|
|
elseif typeinfo.kinddict[a:tag1.fields.kind] >#
|
|
|
|
\ typeinfo.kinddict[a:tag2.fields.kind]
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
" Ignore '~' prefix for C++ destructors to sort them directly under
|
|
|
|
" the constructors
|
|
|
|
if a:tag1.name[0] ==# '~'
|
|
|
|
let name1 = a:tag1.name[1:]
|
|
|
|
else
|
|
|
|
let name1 = a:tag1.name
|
|
|
|
endif
|
|
|
|
if a:tag2.name[0] ==# '~'
|
|
|
|
let name2 = a:tag2.name[1:]
|
|
|
|
else
|
|
|
|
let name2 = a:tag2.name
|
|
|
|
endif
|
|
|
|
|
|
|
|
if name1 <=# name2
|
|
|
|
return -1
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CompareByLine() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CompareByLine(tag1, tag2) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
return a:tag1.fields.line - a:tag2.fields.line
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ToggleSort() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ToggleSort() abort
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
if empty(fileinfo)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2014-03-21 20:09:30 +08:00
|
|
|
" Save the tag the cursor is currently on
|
2011-06-29 04:59:49 +08:00
|
|
|
let curline = line('.')
|
2014-03-21 20:09:30 +08:00
|
|
|
let taginfo = s:GetTagInfo(curline, 0)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
call fileinfo.sortTags()
|
|
|
|
|
|
|
|
call s:RenderContent()
|
2012-03-26 14:42:12 +08:00
|
|
|
call s:SetStatusLine('current')
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2014-03-21 20:09:30 +08:00
|
|
|
" If we were on a tag before sorting then jump to it, otherwise restore
|
|
|
|
" the cursor to the current line
|
|
|
|
if !empty(taginfo)
|
|
|
|
execute taginfo.tline
|
|
|
|
else
|
|
|
|
execute curline
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Display {{{1
|
|
|
|
" s:RenderContent() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:RenderContent(...) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('RenderContent called')
|
2012-02-28 19:21:50 +08:00
|
|
|
let s:new_window = 0
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
if a:0 == 1
|
|
|
|
let fileinfo = a:1
|
|
|
|
else
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
if empty(fileinfo)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Empty fileinfo, returning')
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
|
|
|
|
if &filetype == 'tagbar'
|
|
|
|
let in_tagbar = 1
|
|
|
|
else
|
|
|
|
let in_tagbar = 0
|
2013-02-06 12:07:27 +08:00
|
|
|
let prevwinnr = winnr()
|
2012-11-10 03:52:04 +08:00
|
|
|
|
|
|
|
" Get the previous window number, so that we can reproduce
|
|
|
|
" the window entering history later. Do not run autocmd on
|
|
|
|
" this command, make sure nothing is interfering.
|
2013-11-15 11:21:12 +08:00
|
|
|
" let pprevwinnr = winnr('#') " Messes up windows for some reason
|
|
|
|
call s:goto_win('p', 1)
|
2013-02-06 12:07:27 +08:00
|
|
|
let pprevwinnr = winnr()
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr, 1)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
if !empty(s:known_files.getCurrent(0)) &&
|
|
|
|
\ fileinfo.fpath ==# s:known_files.getCurrent(0).fpath
|
2011-06-29 04:59:49 +08:00
|
|
|
" We're redisplaying the same file, so save the view
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Redisplaying file [' . fileinfo.fpath . ']')
|
2011-06-29 04:59:49 +08:00
|
|
|
let saveline = line('.')
|
|
|
|
let savecol = col('.')
|
|
|
|
let topline = line('w0')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let lazyredraw_save = &lazyredraw
|
|
|
|
set lazyredraw
|
|
|
|
let eventignore_save = &eventignore
|
|
|
|
set eventignore=all
|
|
|
|
|
|
|
|
setlocal modifiable
|
|
|
|
|
|
|
|
silent %delete _
|
|
|
|
|
|
|
|
call s:PrintHelp()
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
let typeinfo = fileinfo.typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-08-24 13:57:33 +08:00
|
|
|
if !empty(fileinfo.tags)
|
|
|
|
" Print tags
|
|
|
|
call s:PrintKinds(typeinfo, fileinfo)
|
|
|
|
else
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('No tags found, skipping printing.')
|
2013-08-24 13:57:33 +08:00
|
|
|
if g:tagbar_compact && s:short_help
|
|
|
|
silent 0put ='\" No tags found.'
|
|
|
|
else
|
|
|
|
silent put ='\" No tags found.'
|
|
|
|
endif
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Delete empty lines at the end of the buffer
|
|
|
|
for linenr in range(line('$'), 1, -1)
|
|
|
|
if getline(linenr) =~ '^$'
|
|
|
|
execute 'silent ' . linenr . 'delete _'
|
|
|
|
else
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
setlocal nomodifiable
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
if !empty(s:known_files.getCurrent(0)) &&
|
|
|
|
\ fileinfo.fpath ==# s:known_files.getCurrent(0).fpath
|
2011-06-29 04:59:49 +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()
|
2011-10-02 17:39:39 +08:00
|
|
|
|
|
|
|
" Invalidate highlight cache from old file
|
|
|
|
let s:last_highlight_tline = 0
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
let &lazyredraw = lazyredraw_save
|
|
|
|
let &eventignore = eventignore_save
|
|
|
|
|
|
|
|
if !in_tagbar
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(pprevwinnr, 1)
|
|
|
|
call s:goto_win(prevwinnr, 1)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:PrintKinds() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:PrintKinds(typeinfo, fileinfo) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('PrintKinds called')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2014-02-05 10:30:19 +08:00
|
|
|
let is_first_tag = 1
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
for kind in a:typeinfo.kinds
|
|
|
|
let curtags = filter(copy(a:fileinfo.tags),
|
|
|
|
\ 'v:val.fields.kind ==# kind.short')
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Printing kind: ' . kind.short .
|
|
|
|
\ ', number of (top-level) tags: ' . len(curtags))
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if empty(curtags)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:typeinfo, 'kind2scope') &&
|
|
|
|
\ has_key(a:typeinfo.kind2scope, kind.short)
|
|
|
|
" Scoped tags
|
|
|
|
for tag in curtags
|
2014-02-05 10:30:19 +08:00
|
|
|
call s:PrintTag(tag, 0, is_first_tag, a:fileinfo, a:typeinfo)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if !g:tagbar_compact
|
|
|
|
silent put _
|
|
|
|
endif
|
|
|
|
|
2014-02-05 10:30:19 +08:00
|
|
|
let is_first_tag = 0
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
else
|
|
|
|
" Non-scoped tags
|
|
|
|
let kindtag = curtags[0].parent
|
|
|
|
|
|
|
|
if kindtag.isFolded()
|
|
|
|
let foldmarker = s:icon_closed
|
|
|
|
else
|
|
|
|
let foldmarker = s:icon_open
|
|
|
|
endif
|
|
|
|
|
2012-11-22 13:42:14 +08:00
|
|
|
let padding = g:tagbar_show_visibility ? ' ' : ''
|
2014-02-05 10:30:19 +08:00
|
|
|
if g:tagbar_compact && is_first_tag && s:short_help
|
2012-11-22 13:42:14 +08:00
|
|
|
silent 0put =foldmarker . padding . kind.long
|
2011-06-29 04:59:49 +08:00
|
|
|
else
|
2012-11-22 13:42:14 +08:00
|
|
|
silent put =foldmarker . padding . kind.long
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
let kindtag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = kindtag
|
|
|
|
|
|
|
|
if !kindtag.isFolded()
|
|
|
|
for tag in curtags
|
2012-04-15 19:10:34 +08:00
|
|
|
let str = tag.strfmt()
|
2012-10-01 17:59:53 +08:00
|
|
|
silent put =repeat(' ', g:tagbar_indent) . str
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Save the current tagbar line in the tag for easy
|
|
|
|
" highlighting access
|
|
|
|
let curline = line('.')
|
|
|
|
let tag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = tag
|
|
|
|
let tag.depth = 1
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !g:tagbar_compact
|
|
|
|
silent put _
|
|
|
|
endif
|
|
|
|
|
2014-02-05 10:30:19 +08:00
|
|
|
let is_first_tag = 0
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:PrintTag() {{{2
|
2014-02-05 10:30:19 +08:00
|
|
|
function! s:PrintTag(tag, depth, is_first, fileinfo, typeinfo) abort
|
2014-02-05 13:08:04 +08:00
|
|
|
if g:tagbar_hide_nonpublic &&
|
|
|
|
\ get(a:tag.fields, 'access', 'public') !=# 'public'
|
|
|
|
let a:tag.tline = -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Print tag indented according to depth
|
2014-02-05 13:08:04 +08:00
|
|
|
let tagstr = repeat(' ', a:depth * g:tagbar_indent) . a:tag.strfmt()
|
2014-02-05 10:30:19 +08:00
|
|
|
if a:is_first && g:tagbar_compact && s:short_help
|
2014-02-05 13:08:04 +08:00
|
|
|
silent 0put =tagstr
|
2014-02-05 10:30:19 +08:00
|
|
|
else
|
2014-02-05 13:08:04 +08:00
|
|
|
silent put =tagstr
|
2014-02-05 10:30:19 +08:00
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2014-02-05 13:08:04 +08:00
|
|
|
" Save the current tagbar line in the tag for easy highlighting access
|
2011-06-29 04:59:49 +08:00
|
|
|
let curline = line('.')
|
|
|
|
let a:tag.tline = curline
|
|
|
|
let a:fileinfo.tline[curline] = a:tag
|
|
|
|
|
|
|
|
" Recursively print children
|
|
|
|
if a:tag.isFoldable() && !a:tag.isFolded()
|
2011-11-24 14:22:31 +08:00
|
|
|
for ckind in a:typeinfo.kinds
|
2014-02-05 13:08:04 +08:00
|
|
|
let childfilter = 'v:val.fields.kind ==# ckind.short'
|
|
|
|
if g:tagbar_hide_nonpublic
|
|
|
|
let childfilter .=
|
|
|
|
\ ' && get(v:val.fields, "access", "public") ==# "public"'
|
|
|
|
endif
|
|
|
|
let childtags = filter(copy(a:tag.children), childfilter)
|
2011-11-24 14:22:31 +08:00
|
|
|
if len(childtags) > 0
|
2012-02-28 17:10:16 +08:00
|
|
|
" Print 'kind' header of following children, but only if they
|
|
|
|
" are not scope-defining tags (since those already have an
|
|
|
|
" identifier)
|
2011-11-24 14:22:31 +08:00
|
|
|
if !has_key(a:typeinfo.kind2scope, ckind.short)
|
2013-02-13 18:34:17 +08:00
|
|
|
let indent = (a:depth + 1) * g:tagbar_indent
|
2012-11-22 13:42:14 +08:00
|
|
|
let indent += g:tagbar_show_visibility
|
|
|
|
let indent += 1 " fold symbol
|
2013-02-13 18:34:17 +08:00
|
|
|
silent put =repeat(' ', indent) . '[' . ckind.long . ']'
|
2012-02-28 17:45:11 +08:00
|
|
|
" Add basic tag to allow folding when on the header line
|
|
|
|
let headertag = s:BaseTag.New(ckind.long)
|
|
|
|
let headertag.parent = a:tag
|
|
|
|
let headertag.fileinfo = a:tag.fileinfo
|
|
|
|
let a:fileinfo.tline[line('.')] = headertag
|
2011-11-24 14:22:31 +08:00
|
|
|
endif
|
|
|
|
for childtag in childtags
|
2014-02-05 10:30:19 +08:00
|
|
|
call s:PrintTag(childtag, a:depth + 1, 0,
|
2011-11-24 14:22:31 +08:00
|
|
|
\ a:fileinfo, a:typeinfo)
|
|
|
|
endfor
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:PrintHelp() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:PrintHelp() abort
|
2011-06-29 04:59:49 +08:00
|
|
|
if !g:tagbar_compact && s:short_help
|
2014-02-28 08:51:48 +08:00
|
|
|
silent 0put ='\" Press <F1> or ? for help'
|
2011-06-29 04:59:49 +08:00
|
|
|
silent put _
|
|
|
|
elseif !s:short_help
|
|
|
|
silent 0put ='\" Tagbar keybindings'
|
|
|
|
silent put ='\"'
|
|
|
|
silent put ='\" --------- General ---------'
|
2013-08-22 13:38:31 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('jump') . ': Jump to tag definition'
|
|
|
|
silent put ='\" ' . s:get_map_str('preview') . ': As above, but stay in'
|
|
|
|
silent put ='\" Tagbar window'
|
2013-11-10 19:53:45 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('previewwin') . ': Show tag in preview window'
|
2013-08-22 13:38:31 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('nexttag') . ': Go to next top-level tag'
|
|
|
|
silent put ='\" ' . s:get_map_str('prevtag') . ': Go to previous top-level tag'
|
|
|
|
silent put ='\" ' . s:get_map_str('showproto') . ': Display tag prototype'
|
2014-02-10 12:10:43 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('hidenonpublic') . ': Hide non-public tags'
|
2011-06-29 04:59:49 +08:00
|
|
|
silent put ='\"'
|
|
|
|
silent put ='\" ---------- Folds ----------'
|
2013-08-22 13:38:31 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('openfold') . ': Open fold'
|
|
|
|
silent put ='\" ' . s:get_map_str('closefold') . ': Close fold'
|
|
|
|
silent put ='\" ' . s:get_map_str('togglefold') . ': Toggle fold'
|
|
|
|
silent put ='\" ' . s:get_map_str('openallfolds') . ': Open all folds'
|
|
|
|
silent put ='\" ' . s:get_map_str('closeallfolds') . ': Close all folds'
|
2014-11-09 12:33:42 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('nextfold') . ': Go to next fold'
|
|
|
|
silent put ='\" ' . s:get_map_str('prevfold') . ': Go to previous fold'
|
2011-06-29 04:59:49 +08:00
|
|
|
silent put ='\"'
|
|
|
|
silent put ='\" ---------- Misc -----------'
|
2013-08-22 13:38:31 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('togglesort') . ': Toggle sort'
|
2014-06-25 13:58:36 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('toggleautoclose') . ': Toggle autoclose option'
|
2013-08-22 13:38:31 +08:00
|
|
|
silent put ='\" ' . s:get_map_str('zoomwin') . ': Zoom window in/out'
|
|
|
|
silent put ='\" ' . s:get_map_str('close') . ': Close window'
|
|
|
|
silent put ='\" ' . s:get_map_str('help') . ': Toggle help'
|
2011-06-29 04:59:49 +08:00
|
|
|
silent put _
|
|
|
|
endif
|
|
|
|
endfunction
|
2013-08-22 13:38:31 +08:00
|
|
|
function! s:get_map_str(map) abort
|
|
|
|
let def = get(g:, 'tagbar_map_' . a:map)
|
|
|
|
if type(def) == type("")
|
|
|
|
return def
|
|
|
|
else
|
|
|
|
return join(def, ', ')
|
|
|
|
endif
|
|
|
|
endfunction
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" s:RenderKeepView() {{{2
|
|
|
|
" The gist of this function was taken from NERDTree by Martin Grenfell.
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:RenderKeepView(...) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
" User actions {{{1
|
|
|
|
" s:HighlightTag() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:HighlightTag(openfolds, ...) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let tagline = 0
|
|
|
|
|
2012-09-15 12:49:28 +08:00
|
|
|
let force = a:0 > 0 ? a:1 : 0
|
|
|
|
|
|
|
|
if a:0 > 1
|
2013-11-06 17:33:27 +08:00
|
|
|
let tag = s:GetNearbyTag(1, 0, a:2)
|
2012-04-22 00:28:28 +08:00
|
|
|
else
|
2013-11-06 17:33:27 +08:00
|
|
|
let tag = s:GetNearbyTag(1, 0)
|
2012-04-22 00:28:28 +08:00
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
if !empty(tag)
|
|
|
|
let tagline = tag.tline
|
|
|
|
endif
|
|
|
|
|
2011-10-02 17:39:39 +08:00
|
|
|
" Don't highlight the tag again if it's the same one as last time.
|
|
|
|
" This prevents the Tagbar window from jumping back after scrolling with
|
|
|
|
" the mouse.
|
2012-09-15 12:49:28 +08:00
|
|
|
if !force && tagline == s:last_highlight_tline
|
2011-10-02 17:39:39 +08:00
|
|
|
return
|
|
|
|
else
|
|
|
|
let s:last_highlight_tline = tagline
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
2012-02-28 19:21:50 +08:00
|
|
|
if tagbarwinnr == -1
|
|
|
|
return
|
|
|
|
endif
|
2012-09-15 12:49:28 +08:00
|
|
|
let prevwinnr = winnr()
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
match none
|
|
|
|
|
|
|
|
" No tag above cursor position so don't do anything
|
|
|
|
if tagline == 0
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(prevwinnr)
|
2011-06-29 04:59:49 +08:00
|
|
|
redraw
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-06-25 12:32:33 +08:00
|
|
|
if g:tagbar_autoshowtag == 1 || a:openfolds
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:OpenParents(tag)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Check whether the tag is inside a closed fold and highlight the parent
|
|
|
|
" instead in that case
|
|
|
|
let tagline = tag.getClosedParentTline()
|
|
|
|
|
2013-09-19 08:36:41 +08:00
|
|
|
" Parent tag line number is invalid, better don't do anything
|
2014-02-05 13:08:04 +08:00
|
|
|
if tagline <= 0
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(prevwinnr)
|
2013-09-19 08:36:41 +08:00
|
|
|
redraw
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Go to the line containing the tag
|
|
|
|
execute tagline
|
|
|
|
|
|
|
|
" Make sure the tag is visible in the window
|
|
|
|
call winline()
|
|
|
|
|
|
|
|
let foldpat = '[' . s:icon_open . s:icon_closed . ' ]'
|
|
|
|
let pattern = '/^\%' . tagline . 'l\s*' . foldpat . '[-+# ]\zs[^( ]\+\ze/'
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("Highlight pattern: '" . pattern . "'")
|
2013-11-06 12:06:39 +08:00
|
|
|
if hlexists('TagbarHighlight') " Safeguard in case syntax highlighting is disabled
|
2013-11-02 16:51:15 +08:00
|
|
|
execute 'match TagbarHighlight ' . pattern
|
|
|
|
else
|
|
|
|
execute 'match Search ' . pattern
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-09-15 12:49:28 +08:00
|
|
|
if a:0 <= 1 " no line explicitly given, so assume we were in the file window
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(prevwinnr)
|
2012-04-22 00:28:28 +08:00
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:JumpToTag() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:JumpToTag(stay_in_tagbar) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let taginfo = s:GetTagInfo(line('.'), 1)
|
|
|
|
|
|
|
|
let autoclose = w:autoclose
|
|
|
|
|
2012-02-28 17:45:11 +08:00
|
|
|
if empty(taginfo) || !taginfo.isNormalTag()
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let tagbarwinnr = winnr()
|
|
|
|
|
2013-11-11 12:12:40 +08:00
|
|
|
call s:GotoFileWindow(taginfo.fileinfo)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Mark current position so it can be jumped back to
|
|
|
|
mark '
|
|
|
|
|
|
|
|
" 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
|
|
|
|
|
|
|
|
" 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-08-14 14:11:54 +08:00
|
|
|
" If the tag is on a different line after unsaved changes update the tag
|
|
|
|
" and file infos/objects
|
|
|
|
let curline = line('.')
|
|
|
|
if taginfo.fields.line != curline
|
|
|
|
let taginfo.fields.line = curline
|
|
|
|
let taginfo.fileinfo.fline[curline] = taginfo
|
|
|
|
endif
|
|
|
|
|
2012-03-14 18:10:31 +08:00
|
|
|
" Center the tag in the window and jump to the correct column if available
|
2011-06-29 04:59:49 +08:00
|
|
|
normal! z.
|
2012-03-16 18:51:35 +08:00
|
|
|
call cursor(taginfo.fields.line, taginfo.fields.column)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2013-11-29 22:18:39 +08:00
|
|
|
normal! zv
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if a:stay_in_tagbar
|
2012-05-12 16:07:04 +08:00
|
|
|
call s:HighlightTag(0)
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr)
|
2012-03-26 14:42:12 +08:00
|
|
|
redraw
|
2011-06-29 04:59:49 +08:00
|
|
|
elseif g:tagbar_autoclose || autoclose
|
2013-12-19 06:54:59 +08:00
|
|
|
" Also closes preview window
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:CloseWindow()
|
|
|
|
else
|
2013-12-19 06:54:59 +08:00
|
|
|
" Close the preview window if it was opened by us
|
|
|
|
if s:pwin_by_tagbar
|
|
|
|
pclose
|
|
|
|
endif
|
2012-05-12 16:07:04 +08:00
|
|
|
call s:HighlightTag(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-11-10 19:53:45 +08:00
|
|
|
" s:ShowInPreviewWin() {{{2
|
|
|
|
function! s:ShowInPreviewWin() abort
|
2014-10-14 10:59:29 +08:00
|
|
|
let pos = getpos('.')
|
|
|
|
let taginfo = s:GetTagInfo(pos[1], 1)
|
2013-11-10 19:53:45 +08:00
|
|
|
|
|
|
|
if empty(taginfo) || !taginfo.isNormalTag()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-11-30 14:28:18 +08:00
|
|
|
let pwin_open = 0
|
|
|
|
for win in range(1, winnr('$'))
|
|
|
|
if getwinvar(win, '&previewwindow')
|
|
|
|
let pwin_open = 1
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2014-11-08 16:30:17 +08:00
|
|
|
" We want the preview window to be relative to the file window in normal
|
|
|
|
" (horizontal) mode, and relative to the Tagbar window in vertical mode,
|
|
|
|
" to make the best use of space.
|
|
|
|
if g:tagbar_vertical == 0
|
|
|
|
call s:GotoFileWindow(taginfo.fileinfo, 1)
|
|
|
|
call s:mark_window()
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Open the preview window if it is not already open. This has to be done
|
|
|
|
" explicitly before the :psearch below to better control its positioning.
|
2013-11-30 14:28:18 +08:00
|
|
|
if !pwin_open
|
2014-10-14 10:59:29 +08:00
|
|
|
silent execute
|
2013-11-30 14:28:18 +08:00
|
|
|
\ g:tagbar_previewwin_pos . ' pedit ' . taginfo.fileinfo.fpath
|
2014-11-08 16:30:17 +08:00
|
|
|
if g:tagbar_vertical != 0
|
|
|
|
silent execute 'vertical resize ' . g:tagbar_width
|
|
|
|
endif
|
2013-11-30 14:28:18 +08:00
|
|
|
" Remember that the preview window was opened by Tagbar so we can
|
|
|
|
" safely close it by ourselves
|
|
|
|
let s:pwin_by_tagbar = 1
|
|
|
|
endif
|
|
|
|
|
2014-11-08 16:30:17 +08:00
|
|
|
if g:tagbar_vertical != 0
|
|
|
|
call s:GotoFileWindow(taginfo.fileinfo, 1)
|
|
|
|
call s:mark_window()
|
|
|
|
endif
|
|
|
|
|
2013-11-29 13:40:09 +08:00
|
|
|
" Use psearch instead of pedit since pedit essentially reloads the file
|
|
|
|
" and creates an empty undo entry. psearch has to be called from the file
|
|
|
|
" window, and since we only want matches in the current file we disable
|
|
|
|
" the 'include' option. Also start searching at the correct line number to
|
|
|
|
" find the correct tag in case of tags with the same name and to speed up
|
|
|
|
" the searching. Unfortunately the /\%l pattern doesn't seem to work with
|
|
|
|
" psearch.
|
|
|
|
let include_save = &include
|
|
|
|
set include=
|
2013-11-30 14:28:18 +08:00
|
|
|
silent! execute taginfo.fields.line . ',$psearch! /' . taginfo.pattern . '/'
|
2013-11-29 13:40:09 +08:00
|
|
|
let &include = include_save
|
|
|
|
|
|
|
|
call s:goto_win('P', 1)
|
2013-11-22 11:36:54 +08:00
|
|
|
normal! zv
|
2013-11-29 22:31:31 +08:00
|
|
|
normal! zz
|
2014-10-14 10:59:29 +08:00
|
|
|
call s:goto_markedwin(1)
|
2014-02-01 16:17:00 +08:00
|
|
|
call s:goto_tagbar(1)
|
2014-10-14 10:59:29 +08:00
|
|
|
call cursor(pos[1], pos[2])
|
2013-11-10 19:53:45 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:ShowPrototype() {{{2
|
2012-08-26 21:57:56 +08:00
|
|
|
function! s:ShowPrototype(short) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let taginfo = s:GetTagInfo(line('.'), 1)
|
|
|
|
|
|
|
|
if empty(taginfo)
|
2012-08-26 21:57:56 +08:00
|
|
|
return ''
|
2012-08-26 15:25:02 +08:00
|
|
|
endif
|
|
|
|
|
2012-08-26 21:57:56 +08:00
|
|
|
echo taginfo.getPrototype(a:short)
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ToggleHelp() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ToggleHelp() abort
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
" s:GotoNextToplevelTag() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:GotoNextToplevelTag(direction) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
" Folding {{{1
|
|
|
|
" s:OpenFold() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:OpenFold() abort
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
if empty(fileinfo)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
|
|
|
|
let tag = s:GetTagInfo(curline, 0)
|
|
|
|
if empty(tag)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call tag.openFold()
|
|
|
|
|
|
|
|
call s:RenderKeepView()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:CloseFold() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CloseFold() abort
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
if empty(fileinfo)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
match none
|
|
|
|
|
|
|
|
let curline = line('.')
|
|
|
|
|
|
|
|
let curtag = s:GetTagInfo(curline, 0)
|
|
|
|
if empty(curtag)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let newline = curtag.closeFold()
|
|
|
|
|
|
|
|
call s:RenderKeepView(newline)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:ToggleFold() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ToggleFold() abort
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
if empty(fileinfo)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
match none
|
|
|
|
|
|
|
|
let curtag = s:GetTagInfo(line('.'), 0)
|
|
|
|
if empty(curtag)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let newline = line('.')
|
|
|
|
|
|
|
|
if curtag.isKindheader()
|
|
|
|
call curtag.toggleFold()
|
|
|
|
elseif curtag.isFoldable()
|
|
|
|
if curtag.isFolded()
|
|
|
|
call curtag.openFold()
|
|
|
|
else
|
|
|
|
let newline = curtag.closeFold()
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let newline = curtag.closeFold()
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:RenderKeepView(newline)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:SetFoldLevel() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:SetFoldLevel(level, force) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
if a:level < 0
|
2014-10-27 17:35:19 +08:00
|
|
|
call s:warning('Foldlevel can''t be negative')
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
if empty(fileinfo)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:SetFoldLevelRecursive(fileinfo, fileinfo.tags, a:level)
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
let typeinfo = fileinfo.typeinfo
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Apply foldlevel to 'kind's
|
|
|
|
if a:level == 0
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
call fileinfo.closeKindFold(kind)
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
for kind in typeinfo.kinds
|
2012-03-14 17:41:39 +08:00
|
|
|
if a:force || !kind.fold
|
|
|
|
call fileinfo.openKindFold(kind)
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
|
|
|
let fileinfo.foldlevel = a:level
|
|
|
|
|
|
|
|
call s:RenderContent()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:SetFoldLevelRecursive() {{{2
|
|
|
|
" Apply foldlevel to normal tags
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:SetFoldLevelRecursive(fileinfo, tags, level) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
for tag in a:tags
|
|
|
|
if tag.depth >= a:level
|
|
|
|
call tag.setFolded(1)
|
|
|
|
else
|
|
|
|
call tag.setFolded(0)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(tag, 'children')
|
|
|
|
call s:SetFoldLevelRecursive(a:fileinfo, tag.children, a:level)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:OpenParents() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:OpenParents(...) abort
|
2011-06-29 04:59:49 +08:00
|
|
|
if a:0 == 1
|
|
|
|
let tag = a:1
|
|
|
|
else
|
2013-11-06 17:33:27 +08:00
|
|
|
let tag = s:GetNearbyTag(1, 0)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2012-09-15 12:49:28 +08:00
|
|
|
if !empty(tag)
|
|
|
|
call tag.openParents()
|
|
|
|
call s:RenderKeepView()
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2014-11-09 12:33:42 +08:00
|
|
|
" s:GotoNextFold() {{{2
|
|
|
|
function! s:GotoNextFold() abort
|
|
|
|
let curlinenr = line('.')
|
|
|
|
let newlinenr = line('.')
|
|
|
|
|
|
|
|
let range = range(line('.') + 1, line('$'))
|
|
|
|
|
|
|
|
for linenr in range
|
|
|
|
let taginfo = s:GetTagInfo(linenr, 0)
|
|
|
|
|
|
|
|
if empty(taginfo)
|
|
|
|
continue
|
|
|
|
elseif !empty(get(taginfo, 'children', [])) || taginfo.isKindheader()
|
|
|
|
let newlinenr = linenr
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if curlinenr != newlinenr
|
|
|
|
execute linenr
|
|
|
|
call winline()
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:GotoPrevFold() {{{2
|
|
|
|
function! s:GotoPrevFold() abort
|
|
|
|
let curlinenr = line('.')
|
|
|
|
let newlinenr = line('.')
|
|
|
|
let curtag = s:GetTagInfo(curlinenr, 0)
|
|
|
|
let curparent = get(curtag, 'parent', {})
|
|
|
|
|
|
|
|
let range = range(line('.') - 1, 1, -1)
|
|
|
|
|
|
|
|
for linenr in range
|
|
|
|
let taginfo = s:GetTagInfo(linenr, 0)
|
|
|
|
|
|
|
|
if empty(taginfo)
|
|
|
|
continue
|
2014-11-26 09:52:54 +08:00
|
|
|
" Check for the first tag that is either:
|
|
|
|
" - the last tag in an open fold, that is skip all tags that have the
|
|
|
|
" same parent as the current one, or
|
|
|
|
" - a closed parent fold.
|
|
|
|
elseif (!empty(taginfo.parent) && taginfo.parent != curparent &&
|
|
|
|
\ empty(get(taginfo, 'children', []))) ||
|
|
|
|
\ ((!empty(get(taginfo, 'children', [])) || taginfo.isKindheader()) &&
|
|
|
|
\ taginfo.isFolded())
|
2014-11-09 12:33:42 +08:00
|
|
|
let newlinenr = linenr
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if curlinenr != newlinenr
|
|
|
|
execute linenr
|
|
|
|
call winline()
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Helper functions {{{1
|
|
|
|
" s:AutoUpdate() {{{2
|
2012-07-22 17:49:17 +08:00
|
|
|
function! s:AutoUpdate(fname, force) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('AutoUpdate called [' . a:fname . ']')
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2013-11-04 17:51:38 +08:00
|
|
|
" This file is being loaded due to a quickfix command like vimgrep, so
|
|
|
|
" don't process it
|
|
|
|
if exists('s:tagbar_qf_active')
|
|
|
|
return
|
2013-11-06 12:06:39 +08:00
|
|
|
elseif exists('s:window_opening')
|
|
|
|
" This can happen if another plugin causes the active window to change
|
|
|
|
" with an autocmd during the initial Tagbar window creation. In that
|
|
|
|
" case InitWindow() hasn't had a chance to run yet and things can
|
|
|
|
" break. MiniBufExplorer does this, for example. Completely disabling
|
|
|
|
" autocmds at that point is also not ideal since for example
|
|
|
|
" statusline plugins won't be able to update.
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Still opening window, stopping processing')
|
2013-11-06 12:06:39 +08:00
|
|
|
return
|
2013-11-04 17:51:38 +08:00
|
|
|
endif
|
|
|
|
|
2012-01-31 15:58:49 +08:00
|
|
|
" Get the filetype of the file we're about to process
|
|
|
|
let bufnr = bufnr(a:fname)
|
|
|
|
let ftype = getbufvar(bufnr, '&filetype')
|
|
|
|
|
2012-02-28 19:21:50 +08:00
|
|
|
" Don't do anything if we're in the tagbar window
|
|
|
|
if ftype == 'tagbar'
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('In Tagbar window, stopping processing')
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Only consider the main filetype in cases like 'python.django'
|
2012-01-31 15:58:49 +08:00
|
|
|
let sftype = get(split(ftype, '\.'), 0, '')
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("Vim filetype: '" . ftype . "', " .
|
|
|
|
\ "sanitized filetype: '" . sftype . "'")
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Don't do anything if the file isn't supported
|
2012-01-31 15:58:49 +08:00
|
|
|
if !s:IsValidFile(a:fname, sftype)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Not a valid file, stopping processing')
|
2013-02-18 19:02:32 +08:00
|
|
|
let s:nearby_disabled = 1
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-02-28 17:46:04 +08:00
|
|
|
let updated = 0
|
|
|
|
|
2012-07-22 17:49:17 +08:00
|
|
|
" Process the file if it's unknown or the information is outdated.
|
|
|
|
" Testing the mtime of the file is necessary in case it got changed
|
|
|
|
" outside of Vim, for example by checking out a different version from a
|
|
|
|
" VCS.
|
2013-02-26 16:56:12 +08:00
|
|
|
if s:known_files.has(a:fname)
|
2012-07-22 17:49:17 +08:00
|
|
|
let curfile = s:known_files.get(a:fname)
|
|
|
|
" if a:force || getbufvar(curfile.bufnr, '&modified') ||
|
2014-11-02 12:44:25 +08:00
|
|
|
if a:force || empty(curfile) || curfile.ftype != sftype ||
|
2012-07-22 17:49:17 +08:00
|
|
|
\ (filereadable(a:fname) && getftime(a:fname) > curfile.mtime)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('File data outdated, updating [' . a:fname . ']')
|
2012-01-31 15:58:49 +08:00
|
|
|
call s:ProcessFile(a:fname, sftype)
|
2012-02-28 17:46:04 +08:00
|
|
|
let updated = 1
|
2012-07-22 17:49:17 +08:00
|
|
|
else
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('File data seems up to date [' . a:fname . ']')
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
elseif !s:known_files.has(a:fname)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('New file, processing [' . a:fname . ']')
|
2012-01-31 15:58:49 +08:00
|
|
|
call s:ProcessFile(a:fname, sftype)
|
2012-02-28 17:46:04 +08:00
|
|
|
let updated = 1
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
let fileinfo = s:known_files.get(a:fname)
|
|
|
|
|
|
|
|
" If we don't have an entry for the file by now something must have gone
|
|
|
|
" wrong, so don't change the tagbar content
|
|
|
|
if empty(fileinfo)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('fileinfo empty after processing [' . a:fname . ']')
|
2011-06-29 04:59:49 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2012-02-28 17:46:04 +08:00
|
|
|
" Display the tagbar content if the tags have been updated or a different
|
|
|
|
" file is being displayed
|
2013-11-06 17:33:27 +08:00
|
|
|
if bufwinnr('__Tagbar__') != -1 && !s:paused &&
|
2013-02-18 16:51:16 +08:00
|
|
|
\ (s:new_window || updated ||
|
2013-11-06 17:33:27 +08:00
|
|
|
\ (!empty(s:known_files.getCurrent(0)) &&
|
|
|
|
\ a:fname != s:known_files.getCurrent(0).fpath))
|
2012-02-28 17:46:04 +08:00
|
|
|
call s:RenderContent(fileinfo)
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
" Call setCurrent after rendering so RenderContent can check whether the
|
2012-07-22 17:49:17 +08:00
|
|
|
" same file is being redisplayed
|
2011-06-29 04:59:49 +08:00
|
|
|
if !empty(fileinfo)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Setting current file [' . a:fname . ']')
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:known_files.setCurrent(fileinfo)
|
2013-02-18 19:02:32 +08:00
|
|
|
let s:nearby_disabled = 0
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2012-05-12 16:07:04 +08:00
|
|
|
call s:HighlightTag(0)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('AutoUpdate finished successfully')
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
" s:CheckMouseClick() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:CheckMouseClick() abort
|
2012-02-27 21:34:01 +08:00
|
|
|
let line = getline('.')
|
|
|
|
let curcol = col('.')
|
2012-02-19 12:26:15 +08:00
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
if (match(line, s:icon_open . '[-+ ]') + 1) == curcol
|
|
|
|
call s:CloseFold()
|
|
|
|
elseif (match(line, s:icon_closed . '[-+ ]') + 1) == curcol
|
|
|
|
call s:OpenFold()
|
|
|
|
elseif g:tagbar_singleclick
|
|
|
|
call s:JumpToTag(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
2012-02-27 21:34:01 +08:00
|
|
|
endfunction
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
" s:DetectFiletype() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:DetectFiletype(bufnr) abort
|
2012-02-27 21:34:01 +08:00
|
|
|
" Filetype has already been detected for loaded buffers, but not
|
|
|
|
" necessarily for unloaded ones
|
|
|
|
let ftype = getbufvar(a:bufnr, '&filetype')
|
|
|
|
|
|
|
|
if bufloaded(a:bufnr)
|
|
|
|
return ftype
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
if ftype != ''
|
|
|
|
return ftype
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
" Unloaded buffer with non-detected filetype, need to detect filetype
|
|
|
|
" manually
|
|
|
|
let bufname = bufname(a:bufnr)
|
|
|
|
|
|
|
|
let eventignore_save = &eventignore
|
|
|
|
set eventignore=FileType
|
|
|
|
let filetype_save = &filetype
|
|
|
|
|
|
|
|
exe 'doautocmd filetypedetect BufRead ' . bufname
|
|
|
|
let ftype = &filetype
|
|
|
|
|
|
|
|
let &filetype = filetype_save
|
|
|
|
let &eventignore = eventignore_save
|
|
|
|
|
|
|
|
return ftype
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:EscapeCtagsCmd() {{{2
|
|
|
|
" 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
|
2013-04-03 05:57:30 +08:00
|
|
|
" Note: The second parameter (a:args) can be a list of args or
|
|
|
|
" a single string of the args.
|
|
|
|
" When a:args is a list, each argument in the list will be escaped for the
|
|
|
|
" current &shell type.
|
|
|
|
" When a:args is a string, all arguments should be escaped appropriately
|
|
|
|
" (if required). In most use cases no escaping is required so a string
|
|
|
|
" is acceptable. But in cases where arguments may need to be escaped
|
|
|
|
" differently for each &shell type, then pass a list of arguments.
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:EscapeCtagsCmd(ctags_bin, args, ...) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('EscapeCtagsCmd called')
|
|
|
|
call s:debug('ctags_bin: ' . a:ctags_bin)
|
2013-04-03 05:57:30 +08:00
|
|
|
if type(a:args)==type('')
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('ctags_args (is a string): ' . a:args)
|
2013-04-03 05:57:30 +08:00
|
|
|
elseif type(a:args)==type([])
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('ctags_args (is a list): ' . string(a:args))
|
2013-04-03 05:57:30 +08:00
|
|
|
endif
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
if exists('+shellslash')
|
|
|
|
let shellslash_save = &shellslash
|
|
|
|
set noshellslash
|
|
|
|
endif
|
|
|
|
|
2013-04-03 05:57:30 +08:00
|
|
|
"Set up 0th argument of ctags_cmd
|
|
|
|
"a:ctags_bin may have special characters that require escaping.
|
|
|
|
if &shell =~ 'cmd\.exe$' && a:ctags_bin !~ '\s'
|
|
|
|
"For windows cmd.exe, escaping the 0th argument can cause
|
|
|
|
"problems if it references a batch file and the batch file uses %~dp0.
|
|
|
|
"So for windows cmd.exe, only escape the 0th argument iff necessary.
|
|
|
|
"Only known necessary case is when ctags_bin executable filename has
|
|
|
|
"whitespace character(s).
|
|
|
|
|
|
|
|
" Example: If 0th argument is wrapped in double quotes AND it is not
|
|
|
|
" an absolute path to ctags_bin, but rather an executable in %PATH%,
|
|
|
|
" then %~dp0 resolves to the current working directory rather than
|
|
|
|
" the batch file's directory. Batch files like this generally exepect
|
|
|
|
" and depend on %~dp0 to resolve the batch file's directory.
|
|
|
|
" Note: Documentation such as `help cmd.exe` and
|
|
|
|
" http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
|
|
|
|
" suggest other special characters that require escaping for command
|
|
|
|
" line completion. But tagbar.vim does not use the command line
|
|
|
|
" completion feature of cmd.exe and testing shows that the only special
|
|
|
|
" character that needs to be escaped for tagbar.vim is <space> for
|
|
|
|
" windows cmd.exe.
|
|
|
|
let ctags_cmd = a:ctags_bin
|
2011-06-29 04:59:49 +08:00
|
|
|
else
|
2013-04-03 05:57:30 +08:00
|
|
|
let ctags_cmd = shellescape(a:ctags_bin)
|
|
|
|
endif
|
|
|
|
|
|
|
|
"Add additional arguments to ctags_cmd
|
|
|
|
if type(a:args)==type('')
|
|
|
|
"When a:args is a string, append the arguments
|
|
|
|
"Note: In this case, do not attempt to shell escape a:args string.
|
|
|
|
"This function expects the string to already be escaped properly for
|
|
|
|
"the shell type. Why not escape? Because it could be ambiguous about
|
|
|
|
"whether a space is an argument separator or included in the argument.
|
|
|
|
"Since escaping rules vary from shell to shell, it is better to pass a
|
|
|
|
"list of arguments to a:args. With a list, each argument is clearly
|
|
|
|
"separated, so shellescape() can calculate the appropriate escaping
|
|
|
|
"for each argument for the current &shell.
|
|
|
|
let ctags_cmd .= ' ' . a:args
|
|
|
|
elseif type(a:args)==type([])
|
|
|
|
"When a:args is a list, shellescape() each argument and append ctags_cmd
|
|
|
|
"Note: It's a better practice to shellescape() each argument separately so that
|
|
|
|
"spaces used as a separator between arguments can be distinguished with
|
|
|
|
"spaces used inside a single argument.
|
|
|
|
for arg in a:args
|
|
|
|
let ctags_cmd .= ' ' . shellescape(arg)
|
|
|
|
endfor
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2013-04-03 05:57:30 +08:00
|
|
|
"if a filename was specified, add filename as final argument to ctags_cmd.
|
|
|
|
if a:0 == 1
|
|
|
|
let ctags_cmd .= ' ' . shellescape(a:1)
|
2012-04-30 12:40:28 +08:00
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
if exists('+shellslash')
|
|
|
|
let &shellslash = shellslash_save
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Needed for cases where 'encoding' is different from the system's
|
|
|
|
" encoding
|
2012-07-21 16:59:23 +08:00
|
|
|
if has('multi_byte')
|
|
|
|
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
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Escaped ctags command: ' . ctags_cmd)
|
2011-12-12 14:47:43 +08:00
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
if ctags_cmd == ''
|
2014-10-27 17:35:19 +08:00
|
|
|
if !s:warnings.encoding
|
|
|
|
call s:warning('Tagbar: Ctags command encoding conversion failed!' .
|
|
|
|
\ ' Please read ":h g:tagbar_systemenc".')
|
|
|
|
let s:warnings.encoding = 1
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
return ctags_cmd
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" 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
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:ExecuteCtags(ctags_cmd) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Executing ctags command: ' . a:ctags_cmd)
|
2012-08-22 20:59:41 +08:00
|
|
|
|
2014-10-09 06:31:19 +08:00
|
|
|
if has('unix')
|
|
|
|
" Reset shell in case it is set to something incompatible like fish
|
|
|
|
let shell_save = &shell
|
|
|
|
set shell=sh
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
|
2013-08-20 22:44:22 +08:00
|
|
|
if s:debug
|
|
|
|
silent 5verbose let ctags_output = system(a:ctags_cmd)
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug(v:statusmsg)
|
2013-08-20 22:44:22 +08:00
|
|
|
redraw!
|
|
|
|
else
|
|
|
|
let ctags_output = system(a:ctags_cmd)
|
|
|
|
endif
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if &shell =~ 'cmd\.exe'
|
|
|
|
let &shellxquote = shellxquote_save
|
|
|
|
let &shellcmdflag = shellcmdflag_save
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('+shellslash')
|
|
|
|
let &shellslash = shellslash_save
|
|
|
|
endif
|
|
|
|
|
2014-10-09 06:31:19 +08:00
|
|
|
if has('unix')
|
|
|
|
let &shell = shell_save
|
|
|
|
endif
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
return ctags_output
|
|
|
|
endfunction
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
" s:GetNearbyTag() {{{2
|
|
|
|
" Get the tag info for a file near the cursor in the current file
|
2013-11-06 17:33:27 +08:00
|
|
|
function! s:GetNearbyTag(all, forcecurrent, ...) abort
|
2013-02-18 19:02:32 +08:00
|
|
|
if s:nearby_disabled
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(a:forcecurrent)
|
2012-02-28 19:21:50 +08:00
|
|
|
if empty(fileinfo)
|
2012-04-15 19:10:34 +08:00
|
|
|
return {}
|
2012-02-28 19:21:50 +08:00
|
|
|
endif
|
2012-02-27 21:34:01 +08:00
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
let typeinfo = fileinfo.typeinfo
|
2012-04-22 00:28:28 +08:00
|
|
|
if a:0 > 0
|
|
|
|
let curline = a:1
|
|
|
|
else
|
|
|
|
let curline = line('.')
|
|
|
|
endif
|
2012-02-27 21:34:01 +08:00
|
|
|
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)
|
2012-04-15 19:10:34 +08:00
|
|
|
let curtag = fileinfo.fline[line]
|
|
|
|
if a:all || typeinfo.getKind(curtag.fields.kind).stl
|
|
|
|
let tag = curtag
|
2012-03-04 15:52:15 +08:00
|
|
|
break
|
|
|
|
endif
|
2012-02-27 21:34:01 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return tag
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" s:GetTagInfo() {{{2
|
|
|
|
" 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.
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:GetTagInfo(linenr, ignorepseudo) abort
|
2013-11-06 17:33:27 +08:00
|
|
|
let fileinfo = s:known_files.getCurrent(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
|
|
|
|
if empty(fileinfo)
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Don't do anything in empty and comment lines
|
2012-08-26 21:57:56 +08:00
|
|
|
let curline = getbufline(bufnr('__Tagbar__'), a:linenr)[0]
|
2011-06-29 04:59:49 +08:00
|
|
|
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
|
|
|
|
if a:ignorepseudo && taginfo.isPseudoTag()
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
return taginfo
|
|
|
|
endfunction
|
|
|
|
|
2014-02-01 15:49:11 +08:00
|
|
|
" s:GetFileWinnr() {{{2
|
|
|
|
" Get the number of the window that has Tagbar's current file loaded into it,
|
|
|
|
" or 0 if no window has loaded it. It tries the previous window first, if that
|
|
|
|
" does not have the correct buffer loaded it will look for the first one with
|
|
|
|
" the correct buffer in it.
|
|
|
|
function! s:GetFileWinnr(fileinfo) abort
|
|
|
|
let filewinnr = 0
|
|
|
|
let prevwinnr = winnr("#")
|
|
|
|
|
|
|
|
if winbufnr(prevwinnr) == a:fileinfo.bufnr &&
|
|
|
|
\ !getwinvar(prevwinnr, '&previewwindow')
|
|
|
|
let filewinnr = prevwinnr
|
|
|
|
else
|
|
|
|
" Search for the first real window that has the correct buffer loaded
|
|
|
|
" in it. Similar to bufwinnr() but skips the previewwindow.
|
|
|
|
for i in range(1, winnr('$'))
|
|
|
|
call s:goto_win(i, 1)
|
|
|
|
if bufnr('%') == a:fileinfo.bufnr && !&previewwindow
|
|
|
|
let filewinnr = winnr()
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
call s:goto_tagbar(1)
|
|
|
|
endif
|
|
|
|
|
|
|
|
return filewinnr
|
|
|
|
endfunction
|
|
|
|
|
2013-11-11 12:12:40 +08:00
|
|
|
" s:GotoFileWindow() {{{2
|
|
|
|
" Try to switch to the window that has Tagbar's current file loaded in it, or
|
2014-02-01 15:49:11 +08:00
|
|
|
" open the file in an existing window otherwise.
|
2013-11-29 13:40:09 +08:00
|
|
|
function! s:GotoFileWindow(fileinfo, ...) abort
|
|
|
|
let noauto = a:0 > 0 ? a:1 : 0
|
|
|
|
|
2014-02-01 15:49:11 +08:00
|
|
|
let filewinnr = s:GetFileWinnr(a:fileinfo)
|
2013-03-24 09:16:56 +08:00
|
|
|
|
2014-02-01 15:49:11 +08:00
|
|
|
" If there is no window with the correct buffer loaded then load it
|
|
|
|
" into the first window that has a non-special buffer in it.
|
|
|
|
if filewinnr == 0
|
2013-11-11 12:12:40 +08:00
|
|
|
for i in range(1, winnr('$'))
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(i, 1)
|
2014-02-01 15:49:11 +08:00
|
|
|
if &buftype == '' && !&previewwindow
|
|
|
|
execute 'buffer ' . a:fileinfo.bufnr
|
2013-11-11 12:12:40 +08:00
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2014-02-01 15:49:11 +08:00
|
|
|
else
|
|
|
|
call s:goto_win(filewinnr, 1)
|
2013-03-24 09:16:56 +08:00
|
|
|
endif
|
|
|
|
|
2014-02-01 15:49:11 +08:00
|
|
|
" To make ctrl-w_p work we switch between the Tagbar window and the
|
|
|
|
" correct window once
|
|
|
|
call s:goto_tagbar(noauto)
|
|
|
|
call s:goto_win('p', noauto)
|
2013-03-24 09:16:56 +08:00
|
|
|
endfunction
|
|
|
|
|
2014-02-05 13:08:04 +08:00
|
|
|
" s:ToggleHideNonPublicTags() {{{2
|
|
|
|
function! s:ToggleHideNonPublicTags() abort
|
|
|
|
let g:tagbar_hide_nonpublic = !g:tagbar_hide_nonpublic
|
|
|
|
call s:RenderKeepView()
|
2014-02-10 12:10:43 +08:00
|
|
|
call s:SetStatusLine('current')
|
2014-02-05 13:08:04 +08:00
|
|
|
endfunction
|
|
|
|
|
2014-06-25 13:52:43 +08:00
|
|
|
" s:ToggleAutoclose() {{{2
|
|
|
|
function! s:ToggleAutoclose() abort
|
|
|
|
let g:tagbar_autoclose = !g:tagbar_autoclose
|
|
|
|
call s:SetStatusLine('current')
|
|
|
|
endfunction
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
" s:IsValidFile() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:IsValidFile(fname, ftype) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Checking if file is valid [' . a:fname . ']')
|
2011-06-29 04:59:49 +08:00
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
if a:fname == '' || a:ftype == ''
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Empty filename or type')
|
2012-02-27 21:34:01 +08:00
|
|
|
return 0
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
2011-12-21 14:28:34 +08:00
|
|
|
|
2012-07-22 17:49:17 +08:00
|
|
|
if !filereadable(a:fname) && getbufvar(a:fname, 'netrw_tmpfile') == ''
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('File not readable')
|
2012-02-27 21:34:01 +08:00
|
|
|
return 0
|
2011-12-21 14:28:34 +08:00
|
|
|
endif
|
|
|
|
|
2013-11-08 12:27:34 +08:00
|
|
|
if getbufvar(a:fname, 'tagbar_ignore') == 1
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('File is marked as ignored')
|
2013-11-08 12:27:34 +08:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2013-02-06 16:21:18 +08:00
|
|
|
if &previewwindow
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('In preview window')
|
2013-02-06 16:21:18 +08:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
if !has_key(s:known_types, a:ftype)
|
|
|
|
if exists('g:tagbar_type_' . a:ftype)
|
|
|
|
" Filetype definition must have been specified in an 'ftplugin'
|
|
|
|
" file, so load it now
|
|
|
|
call s:LoadUserTypeDefs(a:ftype)
|
|
|
|
else
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('Unsupported filetype: ' . a:ftype)
|
2012-02-27 21:34:01 +08:00
|
|
|
return 0
|
|
|
|
endif
|
2011-12-21 14:28:34 +08:00
|
|
|
endif
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
return 1
|
|
|
|
endfunction
|
2011-12-21 14:28:34 +08:00
|
|
|
|
2012-03-26 14:42:12 +08:00
|
|
|
" s:SetStatusLine() {{{2
|
|
|
|
function! s:SetStatusLine(current)
|
|
|
|
" Make sure we're actually in the Tagbar window
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
if tagbarwinnr != winnr()
|
|
|
|
let in_tagbar = 0
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr)
|
2012-03-26 14:42:12 +08:00
|
|
|
else
|
|
|
|
let in_tagbar = 1
|
|
|
|
endif
|
2013-08-21 14:28:40 +08:00
|
|
|
let current = a:current == 'current'
|
2012-03-26 14:42:12 +08:00
|
|
|
|
2013-08-21 14:28:40 +08:00
|
|
|
let sort = g:tagbar_sort ? 'Name' : 'Order'
|
2012-03-26 14:42:12 +08:00
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
if !empty(s:known_files.getCurrent(0))
|
|
|
|
let fname = fnamemodify(s:known_files.getCurrent(0).fpath, ':t')
|
2012-03-26 14:42:12 +08:00
|
|
|
else
|
|
|
|
let fname = ''
|
|
|
|
endif
|
|
|
|
|
2014-06-25 13:52:43 +08:00
|
|
|
let flags = []
|
|
|
|
let flags += exists('w:autoclose') && w:autoclose ? ['c'] : []
|
|
|
|
let flags += g:tagbar_autoclose ? ['C'] : []
|
|
|
|
let flags += g:tagbar_hide_nonpublic ? ['v'] : []
|
|
|
|
|
2013-08-21 14:28:40 +08:00
|
|
|
if exists('g:tagbar_status_func')
|
2014-06-25 13:52:43 +08:00
|
|
|
let args = [current, sort, fname, flags]
|
2013-08-21 14:28:40 +08:00
|
|
|
let &l:statusline = call(g:tagbar_status_func, args)
|
2012-03-26 14:42:12 +08:00
|
|
|
else
|
|
|
|
let colour = current ? '%#StatusLine#' : '%#StatusLineNC#'
|
2014-06-25 13:52:43 +08:00
|
|
|
let flagstr = join(flags, '')
|
|
|
|
if flagstr != ''
|
|
|
|
let flagstr = '[' . flagstr . '] '
|
|
|
|
endif
|
|
|
|
let text = colour . '[' . sort . '] ' . flagstr . fname
|
2012-03-26 14:42:12 +08:00
|
|
|
let &l:statusline = text
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !in_tagbar
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win('p')
|
2012-03-26 14:42:12 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-02-27 21:34:01 +08:00
|
|
|
" s:QuitIfOnlyWindow() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:QuitIfOnlyWindow() abort
|
2013-11-13 11:53:52 +08:00
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curwinnr = winnr()
|
2015-01-13 17:32:17 +08:00
|
|
|
let prevwinnr = winnr('#') == 0 ? curwinnr : winnr('#')
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(tagbarwinnr, 1)
|
2013-11-13 11:53:52 +08:00
|
|
|
|
2013-02-06 13:43:51 +08:00
|
|
|
" Check if there is more than one window
|
2012-11-10 04:17:27 +08:00
|
|
|
if s:NextNormalWindow() == -1
|
2012-02-27 21:34:01 +08:00
|
|
|
" Check if there is more than one tab page
|
|
|
|
if tabpagenr('$') == 1
|
|
|
|
" Before quitting Vim, delete the tagbar buffer so that
|
|
|
|
" the '0 mark is correctly set to the previous buffer.
|
2012-12-01 00:05:30 +08:00
|
|
|
" Also disable autocmd on this command to avoid unnecessary
|
|
|
|
" autocmd nesting.
|
|
|
|
if winnr('$') == 1
|
|
|
|
noautocmd bdelete
|
|
|
|
endif
|
2012-11-30 07:39:28 +08:00
|
|
|
quit
|
2012-02-27 21:34:01 +08:00
|
|
|
else
|
|
|
|
close
|
|
|
|
endif
|
|
|
|
endif
|
2013-11-13 11:53:52 +08:00
|
|
|
|
2014-01-21 10:59:11 +08:00
|
|
|
call s:goto_win(prevwinnr, 1)
|
2013-11-15 11:21:12 +08:00
|
|
|
call s:goto_win(curwinnr, 1)
|
2011-12-21 14:28:34 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-11-10 04:17:27 +08:00
|
|
|
" s:NextNormalWindow() {{{2
|
2013-02-06 14:00:34 +08:00
|
|
|
function! s:NextNormalWindow() abort
|
2013-02-06 13:43:51 +08:00
|
|
|
for i in range(1, winnr('$'))
|
|
|
|
let buf = winbufnr(i)
|
2012-11-10 04:17:27 +08:00
|
|
|
|
|
|
|
" skip unlisted buffers
|
2014-06-25 14:37:51 +08:00
|
|
|
if !buflisted(buf)
|
2012-11-10 04:17:27 +08:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
" skip temporary buffers with buftype set
|
2013-02-06 13:43:51 +08:00
|
|
|
if getbufvar(buf, '&buftype') != ''
|
2012-11-10 04:17:27 +08:00
|
|
|
continue
|
|
|
|
endif
|
2013-11-11 12:39:48 +08:00
|
|
|
|
|
|
|
" skip the preview window
|
|
|
|
if getwinvar(i, '&previewwindow')
|
|
|
|
continue
|
|
|
|
endif
|
2012-11-10 04:17:27 +08:00
|
|
|
|
2013-02-06 13:43:51 +08:00
|
|
|
" skip current window
|
|
|
|
if i == winnr()
|
2012-11-10 04:17:27 +08:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2013-02-06 13:43:51 +08:00
|
|
|
return i
|
|
|
|
endfor
|
|
|
|
|
2012-11-10 04:17:27 +08:00
|
|
|
return -1
|
2013-02-06 13:43:51 +08:00
|
|
|
endfunction
|
2012-11-10 04:17:27 +08:00
|
|
|
|
2013-11-15 11:21:12 +08:00
|
|
|
" s:goto_win() {{{2
|
|
|
|
function! s:goto_win(winnr, ...) abort
|
2013-11-29 13:40:09 +08:00
|
|
|
let cmd = type(a:winnr) == type(0) ? a:winnr . 'wincmd w'
|
|
|
|
\ : 'wincmd ' . a:winnr
|
2013-11-15 11:21:12 +08:00
|
|
|
let noauto = a:0 > 0 ? a:1 : 0
|
2012-02-23 15:41:31 +08:00
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug("goto_win(): " . cmd . ", " . noauto)
|
2012-01-31 15:58:49 +08:00
|
|
|
|
2013-11-15 11:21:12 +08:00
|
|
|
if noauto
|
|
|
|
noautocmd execute cmd
|
|
|
|
else
|
|
|
|
execute cmd
|
|
|
|
endif
|
2012-01-31 15:58:49 +08:00
|
|
|
endfunction
|
2011-12-21 14:28:34 +08:00
|
|
|
|
2013-11-29 13:40:09 +08:00
|
|
|
" s:goto_tagbar() {{{2
|
|
|
|
function! s:goto_tagbar(...) abort
|
|
|
|
let noauto = a:0 > 0 ? a:1 : 0
|
|
|
|
call s:goto_win(bufwinnr('__Tagbar__'), noauto)
|
|
|
|
endfunction
|
|
|
|
|
2014-02-01 16:17:00 +08:00
|
|
|
" s:mark_window() {{{2
|
|
|
|
" Mark window with a window-local variable so we can jump back to it even if
|
|
|
|
" the window numbers have changed.
|
|
|
|
function! s:mark_window() abort
|
|
|
|
let w:tagbar_mark = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:goto_markedwin() {{{2
|
|
|
|
" Go to a previously marked window and delete the mark.
|
2014-10-14 10:59:29 +08:00
|
|
|
function! s:goto_markedwin(...) abort
|
|
|
|
let noauto = a:0 > 0 ? a:1 : 0
|
2014-02-01 16:17:00 +08:00
|
|
|
for window in range(1, winnr('$'))
|
2014-10-14 10:59:29 +08:00
|
|
|
call s:goto_win(window, noauto)
|
2014-02-01 16:17:00 +08:00
|
|
|
if exists('w:tagbar_mark')
|
|
|
|
unlet w:tagbar_mark
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2014-10-27 17:35:19 +08:00
|
|
|
" s:warning() {{{2
|
|
|
|
function! s:warning(msg) abort
|
|
|
|
echohl WarningMsg
|
|
|
|
echomsg a:msg
|
|
|
|
echohl None
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" TagbarBalloonExpr() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! TagbarBalloonExpr() abort
|
2011-06-29 04:59:49 +08:00
|
|
|
let taginfo = s:GetTagInfo(v:beval_lnum, 1)
|
|
|
|
|
|
|
|
if empty(taginfo)
|
2012-08-26 21:57:56 +08:00
|
|
|
return ''
|
2011-06-29 04:59:49 +08:00
|
|
|
endif
|
|
|
|
|
2012-08-26 21:57:56 +08:00
|
|
|
return taginfo.getPrototype(0)
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2011-12-12 14:47:43 +08:00
|
|
|
" Debugging {{{1
|
|
|
|
" s:StartDebug() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:StartDebug(filename) abort
|
2011-12-12 14:47:43 +08:00
|
|
|
if empty(a:filename)
|
|
|
|
let s:debug_file = 'tagbardebug.log'
|
|
|
|
else
|
|
|
|
let s:debug_file = a:filename
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Empty log file
|
|
|
|
exe 'redir! > ' . s:debug_file
|
|
|
|
redir END
|
|
|
|
|
|
|
|
" Check whether the log file could be created
|
|
|
|
if !filewritable(s:debug_file)
|
|
|
|
echomsg 'Tagbar: Unable to create log file ' . s:debug_file
|
|
|
|
let s:debug_file = ''
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:debug = 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" s:StopDebug() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! s:StopDebug() abort
|
2011-12-12 14:47:43 +08:00
|
|
|
let s:debug = 0
|
|
|
|
let s:debug_file = ''
|
|
|
|
endfunction
|
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
" s:debug() {{{2
|
2014-04-03 19:31:27 +08:00
|
|
|
if has('reltime')
|
|
|
|
function! s:gettime() abort
|
|
|
|
let time = split(reltimestr(reltime()), '\.')
|
|
|
|
return strftime('%Y-%m-%d %H:%M:%S.', time[0]) . time[1]
|
|
|
|
endfunction
|
|
|
|
else
|
|
|
|
function! s:gettime() abort
|
|
|
|
return strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
endfunction
|
|
|
|
endif
|
2014-04-03 19:39:26 +08:00
|
|
|
function! s:debug(msg) abort
|
2011-12-12 14:47:43 +08:00
|
|
|
if s:debug
|
2012-08-22 21:47:59 +08:00
|
|
|
execute 'redir >> ' . s:debug_file
|
2014-04-03 19:31:27 +08:00
|
|
|
silent echon s:gettime() . ': ' . a:msg . "\n"
|
2011-12-12 14:47:43 +08:00
|
|
|
redir END
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Autoload functions {{{1
|
2012-04-15 19:10:34 +08:00
|
|
|
|
|
|
|
" Wrappers {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#ToggleWindow() abort
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:ToggleWindow()
|
|
|
|
endfunction
|
|
|
|
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#OpenWindow(...) abort
|
2011-11-23 14:56:31 +08:00
|
|
|
let flags = a:0 > 0 ? a:1 : ''
|
|
|
|
call s:OpenWindow(flags)
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#CloseWindow() abort
|
2011-06-29 04:59:49 +08:00
|
|
|
call s:CloseWindow()
|
|
|
|
endfunction
|
|
|
|
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#SetFoldLevel(level, force) abort
|
2012-03-14 17:41:39 +08:00
|
|
|
call s:SetFoldLevel(a:level, a:force)
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-09-15 12:49:28 +08:00
|
|
|
function! tagbar#highlighttag(openfolds, force) abort
|
|
|
|
let tagbarwinnr = bufwinnr('__Tagbar__')
|
|
|
|
if tagbarwinnr == -1
|
|
|
|
echohl WarningMsg
|
|
|
|
echomsg "Warning: Can't highlight tag, Tagbar window not open"
|
|
|
|
echohl None
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
call s:HighlightTag(a:openfolds, a:force)
|
2011-06-29 04:59:49 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#StartDebug(...) abort
|
2011-12-12 14:47:43 +08:00
|
|
|
let filename = a:0 > 0 ? a:1 : ''
|
|
|
|
call s:StartDebug(filename)
|
|
|
|
endfunction
|
|
|
|
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#StopDebug() abort
|
2011-12-12 14:47:43 +08:00
|
|
|
call s:StopDebug()
|
|
|
|
endfunction
|
|
|
|
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#RestoreSession() abort
|
2011-07-03 17:14:56 +08:00
|
|
|
call s:RestoreSession()
|
|
|
|
endfunction
|
2012-10-01 21:22:35 +08:00
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
" }}}2
|
2011-07-03 17:14:56 +08:00
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
" tagbar#toggle_pause() {{{2
|
|
|
|
function! tagbar#toggle_pause() abort
|
|
|
|
let s:paused = !s:paused
|
|
|
|
|
|
|
|
if s:paused
|
|
|
|
call s:known_files.setPaused()
|
|
|
|
else
|
|
|
|
call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 1)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-03-08 13:06:51 +08:00
|
|
|
" tagbar#getusertypes() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#getusertypes() abort
|
2013-04-05 06:57:57 +08:00
|
|
|
let userdefs = filter(copy(g:), 'v:key =~ "^tagbar_type_"')
|
2012-03-08 13:06:51 +08:00
|
|
|
|
2013-04-05 06:57:57 +08:00
|
|
|
let typedict = {}
|
|
|
|
for [key, val] in items(userdefs)
|
|
|
|
let type = substitute(key, '^tagbar_type_', '', '')
|
|
|
|
let typedict[type] = val
|
2012-03-08 13:06:51 +08:00
|
|
|
endfor
|
|
|
|
|
2013-04-05 06:57:57 +08:00
|
|
|
return typedict
|
2012-03-08 13:06:51 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
" tagbar#autoopen() {{{2
|
2011-12-21 14:28:34 +08:00
|
|
|
" Automatically open Tagbar if one of the open buffers contains a supported
|
|
|
|
" file
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#autoopen(...) abort
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('tagbar#autoopen called [' . bufname('%') . ']')
|
2012-01-14 14:35:01 +08:00
|
|
|
let always = a:0 > 0 ? a:1 : 1
|
|
|
|
|
2012-07-01 14:48:00 +08:00
|
|
|
call s:Init(0)
|
2011-12-21 14:28:34 +08:00
|
|
|
|
|
|
|
for bufnr in range(1, bufnr('$'))
|
2012-01-14 14:35:01 +08:00
|
|
|
if buflisted(bufnr) && (always || bufwinnr(bufnr) != -1)
|
2011-12-21 14:28:34 +08:00
|
|
|
let ftype = s:DetectFiletype(bufnr)
|
|
|
|
if s:IsValidFile(bufname(bufnr), ftype)
|
|
|
|
call s:OpenWindow('')
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('tagbar#autoopen finished after finding valid ' .
|
|
|
|
\ 'file [' . bufname(bufnr) . ']')
|
2011-12-21 14:28:34 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
2012-02-23 15:41:31 +08:00
|
|
|
|
2014-04-03 19:39:26 +08:00
|
|
|
call s:debug('tagbar#autoopen finished without finding valid file')
|
2011-12-21 14:28:34 +08:00
|
|
|
endfunction
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
" tagbar#currenttag() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#currenttag(fmt, default, ...) abort
|
2013-07-30 07:38:46 +08:00
|
|
|
" Indicate that the statusline functionality is being used. This prevents
|
|
|
|
" the CloseWindow() function from removing the autocommands.
|
|
|
|
let s:statusline_in_use = 1
|
|
|
|
|
2012-04-15 19:10:34 +08:00
|
|
|
if a:0 > 0
|
|
|
|
" also test for non-zero value for backwards compatibility
|
2012-09-09 16:17:44 +08:00
|
|
|
let longsig = a:1 =~# 's' || (type(a:1) == type(0) && a:1 != 0)
|
|
|
|
let fullpath = a:1 =~# 'f'
|
|
|
|
let prototype = a:1 =~# 'p'
|
2012-04-15 19:10:34 +08:00
|
|
|
else
|
2012-09-09 16:17:44 +08:00
|
|
|
let longsig = 0
|
|
|
|
let fullpath = 0
|
|
|
|
let prototype = 0
|
2012-04-15 19:10:34 +08:00
|
|
|
endif
|
2012-02-28 19:21:50 +08:00
|
|
|
|
2012-07-01 14:48:00 +08:00
|
|
|
if !s:Init(1)
|
|
|
|
return a:default
|
2012-02-28 19:21:50 +08:00
|
|
|
endif
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
let tag = s:GetNearbyTag(0, 1)
|
2012-02-28 19:21:50 +08:00
|
|
|
|
|
|
|
if !empty(tag)
|
2012-09-09 16:17:44 +08:00
|
|
|
if prototype
|
|
|
|
return tag.getPrototype(1)
|
|
|
|
else
|
|
|
|
return printf(a:fmt, tag.str(longsig, fullpath))
|
|
|
|
endif
|
2012-02-28 19:21:50 +08:00
|
|
|
else
|
|
|
|
return a:default
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-05-15 20:00:08 +08:00
|
|
|
" tagbar#currentfile() {{{2
|
|
|
|
function! tagbar#currentfile() abort
|
|
|
|
let filename = ''
|
|
|
|
|
2013-11-06 17:33:27 +08:00
|
|
|
if !empty(s:known_files.getCurrent(1))
|
|
|
|
let filename = fnamemodify(s:known_files.getCurrent(1).fpath, ':t')
|
2013-05-15 20:00:08 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
return filename
|
|
|
|
endfunction
|
|
|
|
|
2012-06-16 17:46:54 +08:00
|
|
|
" tagbar#gettypeconfig() {{{2
|
2012-07-19 21:12:00 +08:00
|
|
|
function! tagbar#gettypeconfig(type) abort
|
2012-07-01 14:48:00 +08:00
|
|
|
if !s:Init(1)
|
2012-06-16 17:46:54 +08:00
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
let typeinfo = get(s:known_types, a:type, {})
|
|
|
|
|
|
|
|
if empty(typeinfo)
|
2014-10-27 17:35:19 +08:00
|
|
|
call s:warning('Unknown type ' . a:type . '!')
|
2012-06-16 17:46:54 +08:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let output = "let g:tagbar_type_" . a:type . " = {\n"
|
|
|
|
|
|
|
|
let output .= " \\ 'kinds' : [\n"
|
|
|
|
for kind in typeinfo.kinds
|
|
|
|
let output .= " \\ '" . kind.short . ":" . kind.long
|
|
|
|
if kind.fold || !kind.stl
|
|
|
|
if kind.fold
|
|
|
|
let output .= ":1"
|
|
|
|
else
|
|
|
|
let output .= ":0"
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if !kind.stl
|
|
|
|
let output .= ":0"
|
|
|
|
endif
|
|
|
|
let output .= "',\n"
|
|
|
|
endfor
|
|
|
|
let output .= " \\ ],\n"
|
|
|
|
|
|
|
|
let output .= "\\ }"
|
|
|
|
|
|
|
|
silent put =output
|
|
|
|
endfunction
|
|
|
|
|
2014-10-27 17:38:59 +08:00
|
|
|
" tagbar#inspect() {{{2
|
|
|
|
function! tagbar#inspect(var) abort
|
|
|
|
return get(s:, a:var)
|
|
|
|
endfunction
|
|
|
|
|
2011-06-29 04:59:49 +08:00
|
|
|
" Modeline {{{1
|
2011-07-15 13:34:47 +08:00
|
|
|
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1
|