1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-17 19:40:29 +01:00

Tagbar update, removed tab config from common in python ft

This commit is contained in:
2011-12-28 21:58:53 +01:00
parent 34e72ff7f5
commit 3a2343fbce
8 changed files with 331 additions and 125 deletions

4
.vimrc
View File

@@ -181,6 +181,8 @@ nmap <C-Down> \dj
let g:buffergator_split_size=10 let g:buffergator_split_size=10
let g:buffergator_viewport_split_policy='B' let g:buffergator_viewport_split_policy='B'
let g:buffergator_suppress_keymaps=1 let g:buffergator_suppress_keymaps=1
let g:buffergator_sort_regime="filepath"
let g:buffergator_display_regime="filepath"
map <Leader>b :BuffergatorToggle<CR> map <Leader>b :BuffergatorToggle<CR>
" }}} " }}}
"Gundo {{{2 "Gundo {{{2
@@ -386,7 +388,7 @@ endfunction
" GUI: detect graphics mode, set colorscheme {{{ " GUI: detect graphics mode, set colorscheme {{{
if has('gui_running') if has('gui_running')
"set guifont=Consolas\ 12 "I like this font, but it looks like crap on linux "set guifont=Consolas\ 12 "I like this font, but it looks like crap on linux
"set guifont=Consolas\ 13 "Let's try again "set guifont=DejaVu\ Sans\ Mono\ 12 "at least, some ttf font that looks good
set guifont=Fixed\ 14 "I like this font better. set guifont=Fixed\ 14 "I like this font better.
set mouse=a "Enable mouse support set mouse=a "Enable mouse support
"No toolbar, menu, scrollbars, draw simple text tabs. This would keep "No toolbar, menu, scrollbars, draw simple text tabs. This would keep

View File

@@ -17,7 +17,7 @@ ScriptID SourceID Filename
152 3342 showmarks.vim 152 3342 showmarks.vim
2540 11006 snipMate.vim 2540 11006 snipMate.vim
1697 12566 :AutoInstall: surround.vim 1697 12566 :AutoInstall: surround.vim
3465 16977 Tagbar 3465 17112 Tagbar
90 17031 vcscommand.vim 90 17031 vcscommand.vim
2226 15854 vimwiki.vim 2226 15854 vimwiki.vim
1334 6377 vst.vim 1334 6377 vst.vim

View File

@@ -4,7 +4,7 @@
" Author: Jan Larres <jan@majutsushi.net> " Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence " Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/ " Website: http://majutsushi.github.com/tagbar/
" Version: 2.2 " Version: 2.3
" Note: This plugin was heavily inspired by the 'Taglist' plugin by " Note: This plugin was heavily inspired by the 'Taglist' plugin by
" Yegappan Lakshmanan and uses a small amount of code from it. " Yegappan Lakshmanan and uses a small amount of code from it.
" "
@@ -73,17 +73,8 @@ if s:ftype_out !~# 'detection:ON'
endif endif
unlet s:ftype_out unlet s:ftype_out
if has('multi_byte') && has('unix') && &encoding == 'utf-8' && let s:icon_closed = g:tagbar_iconchars[0]
\ (empty(&termencoding) || &termencoding == 'utf-8') let s:icon_open = g:tagbar_iconchars[1]
let s:icon_closed = '▶'
let s:icon_open = '▼'
elseif has('multi_byte') && (has('win32') || has('win64')) && g:tagbar_usearrows
let s:icon_closed = '▷'
let s:icon_open = '◢'
else
let s:icon_closed = '+'
let s:icon_open = '-'
endif
let s:type_init_done = 0 let s:type_init_done = 0
let s:autocommands_done = 0 let s:autocommands_done = 0
@@ -99,9 +90,26 @@ let s:access_symbols = {
let g:loaded_tagbar = 1 let g:loaded_tagbar = 1
let s:last_highlight_tline = 0 let s:last_highlight_tline = 0
let s:debug = 0
let s:debug_file = ''
" s:Init() {{{2
function! s:Init()
if !s:type_init_done
call s:InitTypes()
endif
if !s:checked_ctags
if !s:CheckForExCtags()
return
endif
endif
endfunction
" s:InitTypes() {{{2 " s:InitTypes() {{{2
function! s:InitTypes() function! s:InitTypes()
call s:LogDebugMessage('Initializing types')
let s:known_types = {} let s:known_types = {}
" Ant {{{3 " Ant {{{3
@@ -401,7 +409,8 @@ function! s:InitTypes()
" Alternatively jsctags/doctorjs will be used if available. " Alternatively jsctags/doctorjs will be used if available.
let type_javascript = {} let type_javascript = {}
let type_javascript.ctagstype = 'javascript' let type_javascript.ctagstype = 'javascript'
if executable('jsctags') let jsctags = s:CheckFTCtags('jsctags', 'javascript')
if jsctags != ''
let type_javascript.kinds = [ let type_javascript.kinds = [
\ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, \ {'short' : 'v', 'long' : 'variables', 'fold' : 0},
\ {'short' : 'f', 'long' : 'functions', 'fold' : 0} \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}
@@ -414,7 +423,7 @@ function! s:InitTypes()
let type_javascript.scope2kind = { let type_javascript.scope2kind = {
\ 'namespace' : 'v' \ 'namespace' : 'v'
\ } \ }
let type_javascript.ctagsbin = 'jsctags' let type_javascript.ctagsbin = jsctags
let type_javascript.ctagsargs = '-f -' let type_javascript.ctagsargs = '-f -'
else else
let type_javascript.kinds = [ let type_javascript.kinds = [
@@ -748,6 +757,8 @@ endfunction
" s:GetUserTypeDefs() {{{2 " s:GetUserTypeDefs() {{{2
function! s:GetUserTypeDefs() function! s:GetUserTypeDefs()
call s:LogDebugMessage('Initializing user types')
redir => defs redir => defs
silent execute 'let g:' silent execute 'let g:'
redir END redir END
@@ -766,18 +777,20 @@ function! s:GetUserTypeDefs()
" generate the other one " generate the other one
" Also, transform the 'kind' definitions into dictionary format " Also, transform the 'kind' definitions into dictionary format
for def in values(defdict) for def in values(defdict)
let kinds = def.kinds if has_key(def, 'kinds')
let def.kinds = [] let kinds = def.kinds
for kind in kinds let def.kinds = []
let kindlist = split(kind, ':') for kind in kinds
let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]} let kindlist = split(kind, ':')
if len(kindlist) == 3 let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]}
let kinddict.fold = kindlist[2] if len(kindlist) == 3
else let kinddict.fold = kindlist[2]
let kinddict.fold = 0 else
endif let kinddict.fold = 0
call add(def.kinds, kinddict) endif
endfor call add(def.kinds, kinddict)
endfor
endif
if has_key(def, 'kind2scope') && !has_key(def, 'scope2kind') if has_key(def, 'kind2scope') && !has_key(def, 'scope2kind')
let def.scope2kind = {} let def.scope2kind = {}
@@ -798,6 +811,8 @@ endfunction
" s:RestoreSession() {{{2 " s:RestoreSession() {{{2
" Properly restore Tagbar after a session got loaded " Properly restore Tagbar after a session got loaded
function! s:RestoreSession() function! s:RestoreSession()
call s:LogDebugMessage('Restoring session')
let tagbarwinnr = bufwinnr('__Tagbar__') let tagbarwinnr = bufwinnr('__Tagbar__')
if tagbarwinnr == -1 if tagbarwinnr == -1
" Tagbar wasn't open in the saved session, nothing to do " Tagbar wasn't open in the saved session, nothing to do
@@ -810,15 +825,7 @@ function! s:RestoreSession()
endif endif
endif endif
if !s:type_init_done call s:Init()
call s:InitTypes()
endif
if !s:checked_ctags
if !s:CheckForExCtags()
return
endif
endif
call s:InitWindow(g:tagbar_autoclose) call s:InitWindow(g:tagbar_autoclose)
@@ -833,6 +840,8 @@ endfunction
" s:MapKeys() {{{2 " s:MapKeys() {{{2
function! s:MapKeys() function! s:MapKeys()
call s:LogDebugMessage('Mapping keys')
nnoremap <script> <silent> <buffer> <2-LeftMouse> nnoremap <script> <silent> <buffer> <2-LeftMouse>
\ :call <SID>JumpToTag(0)<CR> \ :call <SID>JumpToTag(0)<CR>
nnoremap <script> <silent> <buffer> <LeftRelease> nnoremap <script> <silent> <buffer> <LeftRelease>
@@ -876,6 +885,8 @@ endfunction
" s:CreateAutocommands() {{{2 " s:CreateAutocommands() {{{2
function! s:CreateAutocommands() function! s:CreateAutocommands()
call s:LogDebugMessage('Creating autocommands')
augroup TagbarAutoCmds augroup TagbarAutoCmds
autocmd! autocmd!
autocmd BufEnter __Tagbar__ nested call s:QuitIfOnlyWindow() autocmd BufEnter __Tagbar__ nested call s:QuitIfOnlyWindow()
@@ -899,6 +910,8 @@ endfunction
" Test whether the ctags binary is actually Exuberant Ctags and not GNU ctags " Test whether the ctags binary is actually Exuberant Ctags and not GNU ctags
" (or something else) " (or something else)
function! s:CheckForExCtags() function! s:CheckForExCtags()
call s:LogDebugMessage('Checking for Exuberant Ctags')
let ctags_cmd = s:EscapeCtagsCmd(g:tagbar_ctags_bin, '--version') let ctags_cmd = s:EscapeCtagsCmd(g:tagbar_ctags_bin, '--version')
if ctags_cmd == '' if ctags_cmd == ''
return return
@@ -940,6 +953,8 @@ endfunction
" s:CheckExCtagsVersion() {{{2 " s:CheckExCtagsVersion() {{{2
function! s:CheckExCtagsVersion(output) function! s:CheckExCtagsVersion(output)
call s:LogDebugMessage('Checking Exuberant Ctags version')
if a:output =~ 'Exuberant Ctags Development' if a:output =~ 'Exuberant Ctags Development'
return 1 return 1
endif endif
@@ -951,6 +966,24 @@ function! s:CheckExCtagsVersion(output)
return major >= 6 || (major == 5 && minor >= 5) return major >= 6 || (major == 5 && minor >= 5)
endfunction endfunction
" s:CheckFTCtags() {{{2
function! s:CheckFTCtags(bin, ftype)
if executable(a:bin)
return a:bin
endif
if exists('g:tagbar_type_' . a:ftype)
execute 'let userdef = ' . 'g:tagbar_type_' . a:ftype
if has_key(userdef, 'ctagsbin')
return userdef.ctagsbin
else
return ''
endif
endif
return ''
endfunction
" Prototypes {{{1 " Prototypes {{{1
" Base tag {{{2 " Base tag {{{2
let s:BaseTag = {} let s:BaseTag = {}
@@ -1369,7 +1402,7 @@ function! s:ToggleWindow()
return return
endif endif
call s:OpenWindow(0) call s:OpenWindow('')
endfunction endfunction
" s:OpenWindow() {{{2 " s:OpenWindow() {{{2
@@ -1391,15 +1424,7 @@ function! s:OpenWindow(flags)
return return
endif endif
if !s:type_init_done call s:Init()
call s:InitTypes()
endif
if !s:checked_ctags
if !s:CheckForExCtags()
return
endif
endif
" Expand the Vim window to accomodate for the Tagbar window if requested " Expand the Vim window to accomodate for the Tagbar window if requested
if g:tagbar_expand && !s:window_expanded && has('gui_running') if g:tagbar_expand && !s:window_expanded && has('gui_running')
@@ -1550,18 +1575,23 @@ endfunction
" s:ProcessFile() {{{2 " s:ProcessFile() {{{2
" Execute ctags and put the information into a 'FileInfo' object " Execute ctags and put the information into a 'FileInfo' object
function! s:ProcessFile(fname, ftype) function! s:ProcessFile(fname, ftype)
call s:LogDebugMessage('ProcessFile called on ' . a:fname)
if !s:IsValidFile(a:fname, a:ftype) if !s:IsValidFile(a:fname, a:ftype)
call s:LogDebugMessage('Not a valid file, returning')
return return
endif endif
let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:ftype) let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:ftype)
if ctags_output == -1 if ctags_output == -1
call s:LogDebugMessage('Ctags error when processing file')
" put an empty entry into known_files so the error message is only " put an empty entry into known_files so the error message is only
" shown once " shown once
call s:known_files.put({}, a:fname) call s:known_files.put({}, a:fname)
return return
elseif ctags_output == '' elseif ctags_output == ''
call s:LogDebugMessage('Ctags output empty')
return return
endif endif
@@ -1577,8 +1607,14 @@ function! s:ProcessFile(fname, ftype)
let typeinfo = s:known_types[a:ftype] let typeinfo = s:known_types[a:ftype]
" Parse the ctags output lines " Parse the ctags output lines
call s:LogDebugMessage('Parsing ctags output')
let rawtaglist = split(ctags_output, '\n\+') let rawtaglist = split(ctags_output, '\n\+')
for line in rawtaglist for line in rawtaglist
" skip comments
if line =~# '^!_TAG_'
continue
endif
let parts = split(line, ';"') let parts = split(line, ';"')
if len(parts) == 2 " Is a valid tag line if len(parts) == 2 " Is a valid tag line
let taginfo = s:ParseTagline(parts[0], parts[1], typeinfo, fileinfo) let taginfo = s:ParseTagline(parts[0], parts[1], typeinfo, fileinfo)
@@ -1590,6 +1626,8 @@ function! s:ProcessFile(fname, ftype)
" Process scoped tags " Process scoped tags
let processedtags = [] let processedtags = []
if has_key(typeinfo, 'kind2scope') if has_key(typeinfo, 'kind2scope')
call s:LogDebugMessage('Processing scoped tags')
let scopedtags = [] let scopedtags = []
let is_scoped = 'has_key(typeinfo.kind2scope, v:val.fields.kind) || let is_scoped = 'has_key(typeinfo.kind2scope, v:val.fields.kind) ||
\ has_key(v:val, "scope")' \ has_key(v:val, "scope")'
@@ -1605,11 +1643,15 @@ function! s:ProcessFile(fname, ftype)
\ 'Please contact the script maintainer with an example.' \ 'Please contact the script maintainer with an example.'
endif endif
endif endif
call s:LogDebugMessage('Number of top-level tags: ' . len(processedtags))
" Create a placeholder tag for the 'kind' header for folding purposes " Create a placeholder tag for the 'kind' header for folding purposes
for kind in typeinfo.kinds for kind in typeinfo.kinds
let curtags = filter(copy(fileinfo.tags), let curtags = filter(copy(fileinfo.tags),
\ 'v:val.fields.kind ==# kind.short') \ 'v:val.fields.kind ==# kind.short')
call s:LogDebugMessage('Processing kind: ' . kind.short .
\ ', number of tags: ' . len(curtags))
if empty(curtags) if empty(curtags)
continue continue
@@ -1629,7 +1671,7 @@ function! s:ProcessFile(fname, ftype)
call extend(fileinfo.tags, processedtags) call extend(fileinfo.tags, processedtags)
endif endif
" Clear old folding information from previous file version " Clear old folding information from previous file version to prevent leaks
call fileinfo.clearOldFolds() call fileinfo.clearOldFolds()
" Sort the tags " Sort the tags
@@ -1641,6 +1683,8 @@ endfunction
" s:ExecuteCtagsOnFile() {{{2 " s:ExecuteCtagsOnFile() {{{2
function! s:ExecuteCtagsOnFile(fname, ftype) function! s:ExecuteCtagsOnFile(fname, ftype)
call s:LogDebugMessage('ExecuteCtagsOnFile called on ' . a:fname)
let typeinfo = s:known_types[a:ftype] let typeinfo = s:known_types[a:ftype]
if has_key(typeinfo, 'ctagsargs') if has_key(typeinfo, 'ctagsargs')
@@ -1690,6 +1734,8 @@ function! s:ExecuteCtagsOnFile(fname, ftype)
echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!' echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!'
echomsg 'Executed command: "' . ctags_cmd . '"' echomsg 'Executed command: "' . ctags_cmd . '"'
if !empty(ctags_output) if !empty(ctags_output)
call s:LogDebugMessage('Command output:')
call s:LogDebugMessage(ctags_output)
echomsg 'Command output:' echomsg 'Command output:'
for line in split(ctags_output, '\n') for line in split(ctags_output, '\n')
echomsg line echomsg line
@@ -1698,6 +1744,7 @@ function! s:ExecuteCtagsOnFile(fname, ftype)
return -1 return -1
endif endif
call s:LogDebugMessage('Ctags executed successfully')
return ctags_output return ctags_output
endfunction endfunction
@@ -1736,7 +1783,9 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo)
let delimit = stridx(field, ':') let delimit = stridx(field, ':')
let key = strpart(field, 0, delimit) let key = strpart(field, 0, delimit)
let val = strpart(field, delimit + 1) let val = strpart(field, delimit + 1)
let taginfo.fields[key] = val if len(val) > 0
let taginfo.fields[key] = val
endif
endfor endfor
" Needed for jsctags " Needed for jsctags
if has_key(taginfo.fields, 'lineno') if has_key(taginfo.fields, 'lineno')
@@ -2029,6 +2078,8 @@ endfunction
" Display {{{1 " Display {{{1
" s:RenderContent() {{{2 " s:RenderContent() {{{2
function! s:RenderContent(...) function! s:RenderContent(...)
call s:LogDebugMessage('RenderContent called')
if a:0 == 1 if a:0 == 1
let fileinfo = a:1 let fileinfo = a:1
else else
@@ -2036,6 +2087,7 @@ function! s:RenderContent(...)
endif endif
if empty(fileinfo) if empty(fileinfo)
call s:LogDebugMessage('Empty fileinfo, returning')
return return
endif endif
@@ -2052,6 +2104,7 @@ function! s:RenderContent(...)
if !empty(s:known_files.getCurrent()) && if !empty(s:known_files.getCurrent()) &&
\ fileinfo.fpath ==# s:known_files.getCurrent().fpath \ fileinfo.fpath ==# s:known_files.getCurrent().fpath
" We're redisplaying the same file, so save the view " We're redisplaying the same file, so save the view
call s:LogDebugMessage('Redisplaying file' . fileinfo.fpath)
let saveline = line('.') let saveline = line('.')
let savecol = col('.') let savecol = col('.')
let topline = line('w0') let topline = line('w0')
@@ -2114,11 +2167,15 @@ endfunction
" s:PrintKinds() {{{2 " s:PrintKinds() {{{2
function! s:PrintKinds(typeinfo, fileinfo) function! s:PrintKinds(typeinfo, fileinfo)
call s:LogDebugMessage('PrintKinds called')
let first_tag = 1 let first_tag = 1
for kind in a:typeinfo.kinds for kind in a:typeinfo.kinds
let curtags = filter(copy(a:fileinfo.tags), let curtags = filter(copy(a:fileinfo.tags),
\ 'v:val.fields.kind ==# kind.short') \ 'v:val.fields.kind ==# kind.short')
call s:LogDebugMessage('Printing kind: ' . kind.short .
\ ', number of (top-level) tags: ' . len(curtags))
if empty(curtags) if empty(curtags)
continue continue
@@ -2669,17 +2726,23 @@ endfunction
" s:AutoUpdate() {{{2 " s:AutoUpdate() {{{2
function! s:AutoUpdate(fname) function! s:AutoUpdate(fname)
call s:LogDebugMessage('AutoUpdate called on ' . a:fname)
" Don't do anything if tagbar is not open or if we're in the tagbar window " Don't do anything if tagbar is not open or if we're in the tagbar window
let tagbarwinnr = bufwinnr('__Tagbar__') let tagbarwinnr = bufwinnr('__Tagbar__')
if tagbarwinnr == -1 || &filetype == 'tagbar' if tagbarwinnr == -1 || &filetype == 'tagbar'
call s:LogDebugMessage('Tagbar window not open or in Tagbar window')
return return
endif endif
" Only consider the main filetype in cases like 'python.django' " Only consider the main filetype in cases like 'python.django'
let ftype = get(split(&filetype, '\.'), 0, '') let ftype = get(split(&filetype, '\.'), 0, '')
call s:LogDebugMessage('Vim filetype: ' . &filetype .
\ ', sanitized filetype: ' . ftype)
" Don't do anything if the file isn't supported " Don't do anything if the file isn't supported
if !s:IsValidFile(a:fname, ftype) if !s:IsValidFile(a:fname, ftype)
call s:LogDebugMessage('Not a valid file, stopping processing')
return return
endif endif
@@ -2688,9 +2751,11 @@ function! s:AutoUpdate(fname)
" if there was an error during the ctags execution " if there was an error during the ctags execution
if s:known_files.has(a:fname) && !empty(s:known_files.get(a:fname)) if s:known_files.has(a:fname) && !empty(s:known_files.get(a:fname))
if s:known_files.get(a:fname).mtime != getftime(a:fname) if s:known_files.get(a:fname).mtime != getftime(a:fname)
call s:LogDebugMessage('Filedata outdated, updating ' . a:fname)
call s:ProcessFile(a:fname, ftype) call s:ProcessFile(a:fname, ftype)
endif endif
elseif !s:known_files.has(a:fname) elseif !s:known_files.has(a:fname)
call s:LogDebugMessage('Unknown file, processing ' . a:fname)
call s:ProcessFile(a:fname, ftype) call s:ProcessFile(a:fname, ftype)
endif endif
@@ -2699,6 +2764,7 @@ function! s:AutoUpdate(fname)
" If we don't have an entry for the file by now something must have gone " If we don't have an entry for the file by now something must have gone
" wrong, so don't change the tagbar content " wrong, so don't change the tagbar content
if empty(fileinfo) if empty(fileinfo)
call s:LogDebugMessage('fileinfo empty after processing: ' . a:fname)
return return
endif endif
@@ -2708,23 +2774,28 @@ function! s:AutoUpdate(fname)
" Call setCurrent after rendering so RenderContent can check whether the " Call setCurrent after rendering so RenderContent can check whether the
" same file is redisplayed " same file is redisplayed
if !empty(fileinfo) if !empty(fileinfo)
call s:LogDebugMessage('Setting current file to ' . a:fname)
call s:known_files.setCurrent(fileinfo) call s:known_files.setCurrent(fileinfo)
endif endif
call s:HighlightTag() call s:HighlightTag()
call s:LogDebugMessage('AutoUpdate finished successfully')
endfunction endfunction
" s:IsValidFile() {{{2 " s:IsValidFile() {{{2
function! s:IsValidFile(fname, ftype) function! s:IsValidFile(fname, ftype)
if a:fname == '' || a:ftype == '' if a:fname == '' || a:ftype == ''
call s:LogDebugMessage('Empty filename or type')
return 0 return 0
endif endif
if !filereadable(a:fname) if !filereadable(a:fname)
call s:LogDebugMessage('File not readable')
return 0 return 0
endif endif
if !has_key(s:known_types, a:ftype) if !has_key(s:known_types, a:ftype)
call s:LogDebugMessage('Unsupported filetype: ' . a:ftype)
return 0 return 0
endif endif
@@ -2736,6 +2807,10 @@ endfunction
" properly escaped and converted to the system's encoding " properly escaped and converted to the system's encoding
" Optional third parameter is a file name to run ctags on " Optional third parameter is a file name to run ctags on
function! s:EscapeCtagsCmd(ctags_bin, args, ...) function! s:EscapeCtagsCmd(ctags_bin, args, ...)
call s:LogDebugMessage('EscapeCtagsCmd called')
call s:LogDebugMessage('ctags_bin: ' . a:ctags_bin)
call s:LogDebugMessage('ctags_args: ' . a:args)
if exists('+shellslash') if exists('+shellslash')
let shellslash_save = &shellslash let shellslash_save = &shellslash
set noshellslash set noshellslash
@@ -2761,6 +2836,8 @@ function! s:EscapeCtagsCmd(ctags_bin, args, ...)
let ctags_cmd = iconv(ctags_cmd, &encoding, $LANG) let ctags_cmd = iconv(ctags_cmd, &encoding, $LANG)
endif endif
call s:LogDebugMessage('Escaped ctags command: ' . ctags_cmd)
if ctags_cmd == '' if ctags_cmd == ''
echoerr 'Tagbar: Encoding conversion failed!' echoerr 'Tagbar: Encoding conversion failed!'
\ 'Please make sure your system is set up correctly' \ 'Please make sure your system is set up correctly'
@@ -2870,6 +2947,38 @@ function! s:CheckMouseClick()
endif endif
endfunction endfunction
" s:DetermineFiletype() {{{2
function! s:DetectFiletype(bufnr)
" 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
endif
if ftype != ''
return ftype
endif
" 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
endfunction
" TagbarBalloonExpr() {{{2 " TagbarBalloonExpr() {{{2
function! TagbarBalloonExpr() function! TagbarBalloonExpr()
let taginfo = s:GetTagInfo(v:beval_lnum, 1) let taginfo = s:GetTagInfo(v:beval_lnum, 1)
@@ -2897,6 +3006,44 @@ function! TagbarGenerateStatusline()
return text return text
endfunction endfunction
" Debugging {{{1
" s:StartDebug() {{{2
function! s:StartDebug(filename)
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
function! s:StopDebug()
let s:debug = 0
let s:debug_file = ''
endfunction
" s:LogDebugMessage() {{{2
function! s:LogDebugMessage(msg)
if s:debug
exe 'redir >> ' . s:debug_file
silent echon strftime('%H:%M:%S') . ': ' . a:msg . "\n"
redir END
endif
endfunction
" Autoload functions {{{1 " Autoload functions {{{1
function! tagbar#ToggleWindow() function! tagbar#ToggleWindow()
call s:ToggleWindow() call s:ToggleWindow()
@@ -2919,9 +3066,34 @@ function! tagbar#OpenParents()
call s:OpenParents() call s:OpenParents()
endfunction endfunction
function! tagbar#StartDebug(...)
let filename = a:0 > 0 ? a:1 : ''
call s:StartDebug(filename)
endfunction
function! tagbar#StopDebug()
call s:StopDebug()
endfunction
function! tagbar#RestoreSession() function! tagbar#RestoreSession()
call s:RestoreSession() call s:RestoreSession()
endfunction endfunction
" Automatically open Tagbar if one of the open buffers contains a supported
" file
function! tagbar#autoopen()
call s:Init()
for bufnr in range(1, bufnr('$'))
if buflisted(bufnr)
let ftype = s:DetectFiletype(bufnr)
if s:IsValidFile(bufname(bufnr), ftype)
call s:OpenWindow('')
return
endif
endif
endfor
endfunction
" Modeline {{{1 " Modeline {{{1
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1 " vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1

View File

@@ -3,7 +3,7 @@
Author: Jan Larres <jan@majutsushi.net> Author: Jan Larres <jan@majutsushi.net>
Licence: Vim licence, see |license| Licence: Vim licence, see |license|
Homepage: http://majutsushi.github.com/tagbar/ Homepage: http://majutsushi.github.com/tagbar/
Version: 2.2 Version: 2.3
============================================================================== ==============================================================================
Contents *tagbar* *tagbar-contents* Contents *tagbar* *tagbar-contents*
@@ -260,6 +260,14 @@ COMMANDS *tagbar-commands*
Open the parent folds of the current tag in the file window as much as Open the parent folds of the current tag in the file window as much as
needed for the tag to be visible in the Tagbar window. needed for the tag to be visible in the Tagbar window.
:TagbarDebug [logfile]
Start debug mode. This will write debug messages to file [logfile] while
using Tagbar. If no argument is given "tagbardebug.log" in the current
directory is used. Note: an existing file will be overwritten!
:TagbarDebugEnd
End debug mode, debug messages will no longer be written to the logfile.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
KEY MAPPINGS *tagbar-keys* KEY MAPPINGS *tagbar-keys*
@@ -413,21 +421,22 @@ Example:
let g:tagbar_foldlevel = 2 let g:tagbar_foldlevel = 2
< <
*g:tagbar_usearrows* *g:tagbar_iconchars*
g:tagbar_usearrows~ g:tagbar_iconchars~
{Windows only}
Default: 0
Tagbar can display nice Unicode arrows instead of +/- characters as fold icons. Since the display of the icons used to indicate open or closed folds depends
However, Windows doesn't seem to be able to substitute in characters from on the actual font used, different characters may be optimal for different
other fonts if the current font doesn't support them. This means that you have fonts. With this variable you can set the icons to characters of your liking.
to use a font that supports those arrows. Unfortunately there is no way to The first character in the list specifies the icon to use for a closed fold,
detect whether specific characters are supported in the current font. So if and the second one for an open fold.
your font supports those arrows you have to set this option to make it work.
Example: Examples (don't worry if some the characters aren't displayed correctly, just
choose other characters in that case):
> >
let g:tagbar_usearrows = 1 let g:tagbar_iconchars = ['▶', '▼'] (default on Linux and Mac OS X)
let g:tagbar_iconchars = ['▾', '▸']
let g:tagbar_iconchars = ['▷', '◢']
let g:tagbar_iconchars = ['+', '-'] (default on Windows)
< <
*g:tagbar_autoshowtag* *g:tagbar_autoshowtag*
@@ -528,19 +537,32 @@ See |:highlight| for more information.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
AUTOMATICALLY OPENING TAGBAR *tagbar-autoopen* AUTOMATICALLY OPENING TAGBAR *tagbar-autoopen*
If you want Tagbar to open automatically, for example on Vim startup or for Since there are several different situations in which you might want to open
specific filetypes, there are various ways to do it. For example, to always Tagbar automatically there is no single option to enable automatic opening.
open Tagbar on Vim startup you can put this into your vimrc file: Instead, autocommands can be used together with a convenience function that
> opens Tagbar only if a supported file is open(ed).
autocmd VimEnter * nested TagbarOpen
<
If you want to have it start for specific filetypes put
>
TagbarOpen
<
into a corresponding filetype plugin (see |filetype-plugin|).
Check out |autocmd.txt| if you want it to automatically open in more If you want to open Tagbar automatically on Vim startup no matter what put
this into your vimrc:
>
autocmd VimEnter * nested :TagbarOpen
<
If you want to open it only if you're opening Vim with a supported file/files
use this instead:
>
autocmd VimEnter * nested :call tagbar#autoopen()
<
For opening Tagbar also if you open a supported file in an already running
Vim:
>
autocmd FileType * nested :call tagbar#autoopen()
<
And if you only want to open Tagbar only for specific filetypes, not for all
of the supported ones:
>
autocmd FileType c,cpp nested :TagbarOpen
<
Check out |autocmd.txt| if you want it to open automatically in more
complicated cases. complicated cases.
============================================================================== ==============================================================================
@@ -552,15 +574,11 @@ existing types and to add completely new types. A complete configuration
consists of a type definition for Tagbar in your |vimrc| and optionally a consists of a type definition for Tagbar in your |vimrc| and optionally a
language definition for ctags in case you want to add a new language. language definition for ctags in case you want to add a new language.
Before writing your own extension try googling for already existing ones. For Before writing your own extension have a look at the wiki
example, here is one for Scala: (https://github.com/majutsushi/tagbar/wiki/Support-for-additional-filetypes)
http://latestbuild.net/scala-ctags-and-vim-tagbar or try googling for existing ones. If you do end up creating your own
Since those aren't "canonical" configurations and are somewhat subjective they extension please consider adding it to the wiki so that others will be able to
probably won't be included in Tagbar, but it is easy enough to just copy&paste use it, too.
them into your own setup. Note that you don't have to modify Tagbar directly
like the article suggests, you can just put the configuration into your
|vimrc| (see below for more details).
Every type definition in Tagbar is a dictionary with the following keys: Every type definition in Tagbar is a dictionary with the following keys:
@@ -642,9 +660,9 @@ deffile: The path to a file with additional ctags definitions (see the
ctagsbin: The path to a filetype-specific ctags-compatible program like ctagsbin: The path to a filetype-specific ctags-compatible program like
{optional} jsctags. Set it in the same way as |g:tagbar_ctags_bin|. jsctags is {optional} jsctags. Set it in the same way as |g:tagbar_ctags_bin|. jsctags is
used automatically if found in your $PATH and does not have to be used automatically if found in your $PATH and does not have to be
set in that case. If it is not in your path you have to provide the set in that case. If it is not in your path you have to set this
complete configuration and use the "replace" key (see the key, the rest of the configuration should not be necessary (unless
Tagbar source code for the suggested configuration). you want to change something, of course).
ctagsargs: The arguments to be passed to the filetype-specific ctags program ctagsargs: The arguments to be passed to the filetype-specific ctags program
{optional} (without the filename). Make sure you set an option that makes the {optional} (without the filename). Make sure you set an option that makes the
program output its data on stdout. Not used for the normal ctags program output its data on stdout. Not used for the normal ctags
@@ -821,6 +839,12 @@ ctags manually execute the following command in a terminal:
If you set the |g:tagbar_ctags_bin| variable you probably have to use the same If you set the |g:tagbar_ctags_bin| variable you probably have to use the same
value here instead of simply "ctags". value here instead of simply "ctags".
If Tagbar doesn't seem to work at all, but you don't get any error messages,
you can use Tagbar's debug mode to try to find the source of the problem (see
|tagbar-commands| on how to invoke it). In that case you should especially pay
attention to the reported file type and the ctags command line in the log
file.
- jsctags has to be newer than 2011-01-06 since it needs the "-f" option to - jsctags has to be newer than 2011-01-06 since it needs the "-f" option to
work. Also, the output of jsctags seems to be a bit unreliable at the work. Also, the output of jsctags seems to be a bit unreliable at the
@@ -874,6 +898,16 @@ value here instead of simply "ctags".
============================================================================== ==============================================================================
8. History *tagbar-history* 8. History *tagbar-history*
2.3 (2011-12-24)
- Add a convenience function that allows more flexible ways to
automatically open Tagbar.
- Replace option tagbar_usearrows with tagbar_iconchars to allow custom
characters to be specified. This helps with fonts that don't display the
default characters properly.
- Remove the need to provide the complete jsctags configuration if jsctags
is not found in $PATH, now only the concrete path has to be specified.
- Add debugging functionality.
2.2 (2011-11-26) 2.2 (2011-11-26)
- Small incompatible change: TagbarOpen now doesn't jump to the Tagbar - Small incompatible change: TagbarOpen now doesn't jump to the Tagbar
window anymore if it is already open. Use "TagbarOpen j" instead or see window anymore if it is already open. Use "TagbarOpen j" instead or see

View File

@@ -412,12 +412,12 @@ g:tagbar_compact tagbar.txt /*g:tagbar_compact*
g:tagbar_ctags_bin tagbar.txt /*g:tagbar_ctags_bin* g:tagbar_ctags_bin tagbar.txt /*g:tagbar_ctags_bin*
g:tagbar_expand tagbar.txt /*g:tagbar_expand* g:tagbar_expand tagbar.txt /*g:tagbar_expand*
g:tagbar_foldlevel tagbar.txt /*g:tagbar_foldlevel* g:tagbar_foldlevel tagbar.txt /*g:tagbar_foldlevel*
g:tagbar_iconchars tagbar.txt /*g:tagbar_iconchars*
g:tagbar_left tagbar.txt /*g:tagbar_left* g:tagbar_left tagbar.txt /*g:tagbar_left*
g:tagbar_singleclick tagbar.txt /*g:tagbar_singleclick* g:tagbar_singleclick tagbar.txt /*g:tagbar_singleclick*
g:tagbar_sort tagbar.txt /*g:tagbar_sort* g:tagbar_sort tagbar.txt /*g:tagbar_sort*
g:tagbar_systemenc tagbar.txt /*g:tagbar_systemenc* g:tagbar_systemenc tagbar.txt /*g:tagbar_systemenc*
g:tagbar_updateonsave_maxlines tagbar.txt /*g:tagbar_updateonsave_maxlines* g:tagbar_updateonsave_maxlines tagbar.txt /*g:tagbar_updateonsave_maxlines*
g:tagbar_usearrows tagbar.txt /*g:tagbar_usearrows*
g:tagbar_width tagbar.txt /*g:tagbar_width* g:tagbar_width tagbar.txt /*g:tagbar_width*
g:vimwiki_CJK_length vimwiki.txt /*g:vimwiki_CJK_length* g:vimwiki_CJK_length vimwiki.txt /*g:vimwiki_CJK_length*
g:vimwiki_auto_checkbox vimwiki.txt /*g:vimwiki_auto_checkbox* g:vimwiki_auto_checkbox vimwiki.txt /*g:vimwiki_auto_checkbox*

View File

@@ -1,18 +1,12 @@
setlocal cinkeys-=0# setlocal cinkeys-=0#
setlocal indentkeys-=0# setlocal indentkeys-=0#
setlocal expandtab
setlocal foldlevel=100 setlocal foldlevel=100
setlocal foldmethod=indent setlocal foldmethod=indent
setlocal list setlocal list
setlocal noautoindent setlocal noautoindent
setlocal shiftwidth=4
setlocal smartindent setlocal smartindent
setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class,with setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class,with
setlocal smarttab setlocal smarttab
setlocal softtabstop=4
setlocal tabstop=4
setlocal textwidth=78
setlocal colorcolumn=+1
set wildignore+=*.pyc set wildignore+=*.pyc

View File

@@ -4,7 +4,7 @@
" Author: Jan Larres <jan@majutsushi.net> " Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence " Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/ " Website: http://majutsushi.github.com/tagbar/
" Version: 2.2 " Version: 2.3
" Note: This plugin was heavily inspired by the 'Taglist' plugin by " Note: This plugin was heavily inspired by the 'Taglist' plugin by
" Yegappan Lakshmanan and uses a small amount of code from it. " Yegappan Lakshmanan and uses a small amount of code from it.
" "
@@ -78,8 +78,13 @@ if !exists('g:tagbar_foldlevel')
let g:tagbar_foldlevel = 99 let g:tagbar_foldlevel = 99
endif endif
if !exists('g:tagbar_usearrows') if !exists('g:tagbar_iconchars')
let g:tagbar_usearrows = 0 if has('multi_byte') && has('unix') && &encoding == 'utf-8' &&
\ (empty(&termencoding) || &termencoding == 'utf-8')
let g:tagbar_iconchars = ['▶', '▼']
else
let g:tagbar_iconchars = ['+', '-']
endif
endif endif
if !exists('g:tagbar_autoshowtag') if !exists('g:tagbar_autoshowtag')
@@ -106,6 +111,8 @@ command! -nargs=0 TagbarOpenAutoClose call tagbar#OpenWindow('fc')
command! -nargs=0 TagbarClose call tagbar#CloseWindow() command! -nargs=0 TagbarClose call tagbar#CloseWindow()
command! -nargs=1 TagbarSetFoldlevel call tagbar#SetFoldLevel(<args>) command! -nargs=1 TagbarSetFoldlevel call tagbar#SetFoldLevel(<args>)
command! -nargs=0 TagbarShowTag call tagbar#OpenParents() command! -nargs=0 TagbarShowTag call tagbar#OpenParents()
command! -nargs=? TagbarDebug call tagbar#StartDebug(<f-args>)
command! -nargs=0 TagbarDebugEnd call tagbar#StopDebug()
" Modeline {{{1 " Modeline {{{1
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1 " vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1

View File

@@ -3,7 +3,7 @@
" Author: Jan Larres <jan@majutsushi.net> " Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence " Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/ " Website: http://majutsushi.github.com/tagbar/
" Version: 2.2 " Version: 2.3
scriptencoding utf-8 scriptencoding utf-8
@@ -11,35 +11,32 @@ if exists("b:current_syntax")
finish finish
endif endif
if has('multi_byte') && has('unix') && &encoding == 'utf-8' && let s:ic = g:tagbar_iconchars[0]
\ (empty(&termencoding) || &termencoding == 'utf-8') if s:ic =~ '[]^\\-]'
syntax match TagbarKind '\([▶▼] \)\@<=[^-+: ]\+[^:]\+$' let s:ic = '\' . s:ic
syntax match TagbarScope '\([▶▼][-+# ]\)\@<=[^*]\+\(\*\?\(([^)]\+)\)\? :\)\@='
syntax match TagbarFoldIcon '[▶▼]\([-+# ]\)\@='
syntax match TagbarAccessPublic '\([▶▼ ]\)\@<=+\([^-+# ]\)\@='
syntax match TagbarAccessProtected '\([▶▼ ]\)\@<=#\([^-+# ]\)\@='
syntax match TagbarAccessPrivate '\([▶▼ ]\)\@<=-\([^-+# ]\)\@='
elseif has('multi_byte') && (has('win32') || has('win64')) && g:tagbar_usearrows
syntax match TagbarKind '\([▷◢] \)\@<=[^-+: ]\+[^:]\+$'
syntax match TagbarScope '\([▷◢][-+# ]\)\@<=[^*]\+\(\*\?\(([^)]\+)\)\? :\)\@='
syntax match TagbarFoldIcon '[▷◢]\([-+# ]\)\@='
syntax match TagbarAccessPublic '\([▷◢ ]\)\@<=+\([^-+# ]\)\@='
syntax match TagbarAccessProtected '\([▷◢ ]\)\@<=#\([^-+# ]\)\@='
syntax match TagbarAccessPrivate '\([▷◢ ]\)\@<=-\([^-+# ]\)\@='
else
syntax match TagbarKind '\([-+] \)\@<=[^-+: ]\+[^:]\+$'
syntax match TagbarScope '\([-+][-+# ]\)\@<=[^*]\+\(\*\?\(([^)]\+)\)\? :\)\@='
syntax match TagbarFoldIcon '[-+]\([-+# ]\)\@='
syntax match TagbarAccessPublic '\([-+ ]\)\@<=+\([^-+# ]\)\@='
syntax match TagbarAccessProtected '\([-+ ]\)\@<=#\([^-+# ]\)\@='
syntax match TagbarAccessPrivate '\([-+ ]\)\@<=-\([^-+# ]\)\@='
endif endif
let s:io = g:tagbar_iconchars[1]
if s:io =~ '[]^\\-]'
let s:io = '\' . s:io
endif
let s:pattern = '\([' . s:ic . s:io . '] \)\@<=[^-+: ]\+[^:]\+$'
execute "syntax match TagbarKind '" . s:pattern . "'"
let s:pattern = '\([' . s:ic . s:io . '][-+# ]\)\@<=[^*]\+\(\*\?\(([^)]\+)\)\? :\)\@='
execute "syntax match TagbarScope '" . s:pattern . "'"
let s:pattern = '[' . s:ic . s:io . ']\([-+# ]\)\@='
execute "syntax match TagbarFoldIcon '" . s:pattern . "'"
let s:pattern = '\([' . s:ic . s:io . ' ]\)\@<=+\([^-+# ]\)\@='
execute "syntax match TagbarAccessPublic '" . s:pattern . "'"
let s:pattern = '\([' . s:ic . s:io . ' ]\)\@<=#\([^-+# ]\)\@='
execute "syntax match TagbarAccessProtected '" . s:pattern . "'"
let s:pattern = '\([' . s:ic . s:io . ' ]\)\@<=-\([^-+# ]\)\@='
execute "syntax match TagbarAccessPrivate '" . s:pattern . "'"
unlet s:pattern
syntax match TagbarNestedKind '^\s\+\[[^]]\+\]$' syntax match TagbarNestedKind '^\s\+\[[^]]\+\]$'
syntax match TagbarComment '^".*' syntax match TagbarComment '^".*'