1
0
mirror of https://github.com/gryf/tagbar.git synced 2026-05-10 16:32:58 +02:00

24 Commits

Author SHA1 Message Date
Jan Larres 9d5af93a5b Version 2.1 2011-05-29 19:19:03 +12:00
Jan Larres 8662779deb Properly restore Tagbar after a session got loaded 2011-05-25 15:18:26 +12:00
Jan Larres 397e1741f8 Check version of exuberant ctags 2011-05-23 22:43:47 +12:00
Jan Larres 8cde134333 Return an empty string when encoding conversion fails 2011-05-22 17:23:11 +12:00
Jan Larres 5b819914b9 Test for Vim >= 7.0 2011-05-19 01:42:18 +12:00
Jan Larres 8d1ba9fc11 Clarify that type definitions have to be put into vimrc 2011-05-16 00:00:06 +12:00
Jan Larres cd188c6669 Locally reset foldmethod and foldexpr in case it's set to something expensive globally 2011-05-15 18:26:10 +12:00
Jan Larres e84eda8437 Ignore autocmds when printing just in case 2011-05-15 18:26:10 +12:00
Jan Larres 49c15b92d8 Properly resize window when pressing 'q', closes #15 2011-05-13 16:06:34 +12:00
Jan Larres 845754bdad Don't check ctags on each 'window open' 2011-05-12 20:50:14 +12:00
Jan Larres 7a06b1615f Make the ctags execution work in (hopefully) all cases under Windows 2011-05-09 23:40:07 +12:00
Jan Larres d8122efcc6 Extract ctags execution into separate function 2011-05-08 23:08:15 +12:00
Jan Larres e28eab7945 Explain some jsctags issues 2011-05-07 18:48:59 +12:00
Jan Larres c33b0409cd Check whether filetype detection is turned on 2011-05-07 18:13:00 +12:00
Jan Larres 1a77a1e9c6 Add additional ctags binary name 2011-05-07 18:06:29 +12:00
Jan Larres 804aa3b170 Small cleanup 2011-05-07 18:04:01 +12:00
Jan Larres 8b539ad91c Explicitly check for Exuberant Ctags 2011-05-07 18:02:03 +12:00
Jan Larres 33d5a5e84f Fix bug with empty filetype 2011-05-07 04:17:26 +12:00
Jan Larres eb10c1d05c Fix bug with subtypes not being properly recognized 2011-05-07 03:46:56 +12:00
Jan Larres 1916c55b7c Handle cases where 'encoding' is different from system encoding 2011-05-05 21:27:47 +12:00
Jan Larres 98fe5ec994 Make sure to jump to the correct buffer/window on tag jump 2011-04-27 15:48:07 +12:00
Jan Larres a76d07cfeb Version 2.0.1 2011-04-27 01:03:04 +12:00
Jan Larres 40d8edf505 Fix sorting bug when 'ignorecase' is set 2011-04-27 01:01:27 +12:00
Jan Larres 1f4713d4ab Typo 2011-04-26 23:46:10 +12:00
3 changed files with 372 additions and 93 deletions
+51 -6
View File
@@ -3,7 +3,7 @@
Author: Jan Larres <jan@majutsushi.net>
Licence: Vim licence, see |license|
Homepage: http://majutsushi.github.com/tagbar/
Version: 2.0
Version: 2.1
==============================================================================
Contents *tagbar* *tagbar-contents*
@@ -113,6 +113,12 @@ with doctorjs/jsctags and will use that if present, other programs require
some configuration (see |tagbar-extend|). If a program does not work even with
correct configuration please contact me.
Note: 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
moment (especially regarding line numbers), so if you notice some strange
behaviour with it please run it manually in a terminal to check whether the
bug is in jsctags or Tagbar.
==============================================================================
2. Requirements *tagbar-requirements*
@@ -339,7 +345,9 @@ g:tagbar_sort~
Default: 1
If this option is set the tags are sorted according to their name. If it is
unset they are sorted according to their order in the source file.
unset they are sorted according to their order in the source file. Note that
in the second case Pseudo-tags are always sorted before normal tags of the
same kind since they don't have a real position in the file.
Example:
>
@@ -415,6 +423,21 @@ Example:
let g:tagbar_autoshowtag = 1
<
*g:tagbar_systemenc*
g:tagbar_systemenc~
Default: value of 'encoding'
This variable is for cases where the character encoding of your operating
system is different from the one set in Vim, i.e. the 'encoding' option. For
example, if you use a Simplified Chinese Windows version that has a system
encoding of "cp936", and you have set 'encoding' to "utf-8", then you would
have to set this variable to "cp936".
Example:
>
let g:tagbar_systemenc = 'cp936'
<
------------------------------------------------------------------------------
HIGHLIGHT COLOURS *tagbar-highlight*
@@ -484,7 +507,9 @@ complicated cases.
Tagbar has a flexible mechanism for extending the existing file type (i.e.
language) definitions. This can be used both to change the settings of the
existing types and to add completely new types.
existing types and to add completely new types. A complete configuration
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.
Every type definition in Tagbar is a dictionary with the following keys:
@@ -575,12 +600,13 @@ ctagsargs: The arguments to be passed to the filetype-specific ctags program
program.
You then have to assign this dictionary to a variable with the name
You then have to assign this dictionary to a variable in your vimrc with the
name
>
g:tagbar_type_{vim filetype}
<
For example, for C++ the name would be "g:tagbar_type_cpp". If you don't know
the vim file type run the following command:
the vim file type then run the following command:
>
:set filetype?
<
@@ -778,10 +804,29 @@ files.
==============================================================================
8. History *tagbar-history*
2.1 (2011-05-29)
- Make Tagbar work in (hopefully) all cases under Windows
- Handle cases where 'encoding' is different from system encoding, for
example on a Chinese Windows with 'encoding' set to "utf-8" (see manual
for details in case it doesn't work out-of-the-box)
- Fixed a bug with the handling of subtypes like "python.django"
- If a session got saved with Tagbar open it now gets restored properly
- Locally reset foldmethod/foldexpr in case foldexpr got set to something
expensive globally
- Tagbar now tries hard to go to the correct window when jumping to a tag
- Explain some possible issues with the current jsctags version in the
manual
- Explicitly check for some possible configuration problems to be able to
give better feedback
- A few other small fixes
2.0.1 (2011-04-26)
- Fix sorting bug when 'ignorecase' is set
2.0 (2011-04-26)
- Folding now works correctly. Folds will be preserved when leaving the
Tagbar window and when switching between files. Also tag types can be
configured to be folded by default, which is usefult for things like
configured to be folded by default, which is useful for things like
includes and imports.
- DoctorJS/jsctags and other compatible programs are now supported.
- All of the highlight groups can now be overridden.
+320 -86
View File
@@ -4,7 +4,7 @@
" Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/
" Version: 2.0
" Version: 2.1
" Note: This plugin was heavily inspired by the 'Taglist' plugin by
" Yegappan Lakshmanan and uses a small amount of code from it.
"
@@ -25,9 +25,17 @@ endif
" Initialization {{{1
" Basic init {{{2
if v:version < 700
echomsg 'Tagbar: Vim version is too old, Tagbar requires at least 7.0'
finish
endif
if !exists('g:tagbar_ctags_bin')
if executable('ctags-exuberant')
let g:tagbar_ctags_bin = 'ctags-exuberant'
elseif executable('exuberant-ctags')
let g:tagbar_ctags_bin = 'exuberant-ctags'
elseif executable('exctags')
let g:tagbar_ctags_bin = 'exctags'
elseif executable('ctags')
@@ -49,6 +57,16 @@ else
endif
endif
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
let g:loaded_tagbar = 1
if !exists('g:tagbar_left')
@@ -91,6 +109,10 @@ if !exists('g:tagbar_autoshowtag')
let g:tagbar_autoshowtag = 0
endif
if !exists('g:tagbar_systemenc')
let g:tagbar_systemenc = &encoding
endif
if has('multi_byte') && has('unix') && &encoding == 'utf-8' &&
\ (empty(&termencoding) || &termencoding == 'utf-8')
let s:icon_closed = 'â–¶'
@@ -105,6 +127,7 @@ endif
let s:type_init_done = 0
let s:autocommands_done = 0
let s:checked_ctags = 0
let s:window_expanded = 0
let s:access_symbols = {
@@ -113,6 +136,8 @@ let s:access_symbols = {
\ 'private' : '-'
\ }
autocmd SessionLoadPost * nested call s:RestoreSession()
" s:InitTypes() {{{2
function! s:InitTypes()
let s:known_types = {}
@@ -808,6 +833,42 @@ function! s:GetUserTypeDefs()
return defdict
endfunction
" s:RestoreSession() {{{2
" Properly restore Tagbar after a session got loaded
function! s:RestoreSession()
let tagbarwinnr = bufwinnr('__Tagbar__')
if tagbarwinnr == -1
" Tagbar wasn't open in the saved session, nothing to do
return
else
let in_tagbar = 1
if winnr() != tagbarwinnr
execute tagbarwinnr . 'wincmd w'
let in_tagbar = 0
endif
endif
if !s:type_init_done
call s:InitTypes()
endif
if !s:checked_ctags
if !s:CheckForExCtags()
return
endif
endif
call s:InitWindow(g:tagbar_autoclose)
" Leave the Tagbar window and come back so the update event gets triggered
execute 'wincmd p'
execute tagbarwinnr . 'wincmd w'
if !in_tagbar
execute 'wincmd p'
endif
endfunction
" s:MapKeys() {{{2
function! s:MapKeys()
nnoremap <script> <silent> <buffer> <CR> :call <SID>JumpToTag(0)<CR>
@@ -841,7 +902,7 @@ function! s:MapKeys()
nnoremap <script> <silent> <buffer> s :call <SID>ToggleSort()<CR>
nnoremap <script> <silent> <buffer> x :call <SID>ZoomWindow()<CR>
nnoremap <script> <silent> <buffer> q :close<CR>
nnoremap <script> <silent> <buffer> q :call <SID>CloseWindow()<CR>
nnoremap <script> <silent> <buffer> <F1> :call <SID>ToggleHelp()<CR>
endfunction
@@ -862,6 +923,58 @@ function! s:CreateAutocommands()
let s:autocommands_done = 1
endfunction
" s:CheckForExCtags() {{{2
" Test whether the ctags binary is actually Exuberant Ctags and not GNU ctags
" (or something else)
function! s:CheckForExCtags()
let ctags_cmd = s:EscapeCtagsCmd(g:tagbar_ctags_bin, '--version')
if ctags_cmd == ''
return
endif
let ctags_output = s:ExecuteCtags(ctags_cmd)
if v:shell_error || ctags_output !~# 'Exuberant Ctags'
echoerr 'Tagbar: Ctags doesn''t seem to be Exuberant Ctags!'
echomsg 'GNU ctags will NOT WORK.'
\ 'Please download Exuberant Ctags from ctags.sourceforge.net'
\ 'and install it in a directory in your $PATH'
\ 'or set g:tagbar_ctags_bin.'
echomsg 'Executed command: "' . ctags_cmd . '"'
if !empty(ctags_output)
echomsg 'Command output:'
for line in split(ctags_output, '\n')
echomsg line
endfor
endif
return 0
elseif !s:CheckExCtagsVersion(ctags_output)
echoerr 'Tagbar: Exuberant Ctags is too old!'
echomsg 'You need at least version 5.5 for Tagbar to work.'
\ 'Please download a newer version from ctags.sourceforge.net.'
echomsg 'Executed command: "' . ctags_cmd . '"'
if !empty(ctags_output)
echomsg 'Command output:'
for line in split(ctags_output, '\n')
echomsg line
endfor
endif
return 0
else
let s:checked_ctags = 1
return 1
endif
endfunction
" s:CheckExCtagsVersion() {{{2
function! s:CheckExCtagsVersion(output)
let matchlist = matchlist(a:output, '\vExuberant Ctags (\d+)\.(\d+)')
let major = matchlist[1]
let minor = matchlist[2]
return major >= 6 || (major == 5 && minor >= 5)
endfunction
" Prototypes {{{1
" Base tag {{{2
let s:BaseTag = {}
@@ -1284,10 +1397,6 @@ endfunction
" s:OpenWindow() {{{2
function! s:OpenWindow(autoclose)
if !s:type_init_done
call s:InitTypes()
endif
" If the tagbar window is already open jump to it
let tagbarwinnr = bufwinnr('__Tagbar__')
if tagbarwinnr != -1
@@ -1297,6 +1406,16 @@ function! s:OpenWindow(autoclose)
return
endif
if !s:type_init_done
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
if g:tagbar_expand && !s:window_expanded && has('gui_running')
let &columns += g:tagbar_width + 1
@@ -1306,6 +1425,20 @@ function! s:OpenWindow(autoclose)
let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical '
exe 'silent keepalt ' . openpos . g:tagbar_width . 'split ' . '__Tagbar__'
call s:InitWindow(a:autoclose)
execute 'wincmd p'
" Jump back to the tagbar window if autoclose or autofocus is set. Can't
" just stay in it since it wouldn't trigger the update event
if g:tagbar_autoclose || a:autoclose || g:tagbar_autofocus
let tagbarwinnr = bufwinnr('__Tagbar__')
execute tagbarwinnr . 'wincmd w'
endif
endfunction
" s:InitWindow() {{{2
function! s:InitWindow(autoclose)
setlocal noreadonly " in case the "view" mode is used
setlocal buftype=nofile
setlocal bufhidden=hide
@@ -1324,13 +1457,14 @@ function! s:OpenWindow(autoclose)
endif
setlocal nofoldenable
" 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&
setlocal statusline=%!TagbarGenerateStatusline()
" Variable for saving the current file for functions that are called from
" the tagbar window
let s:current_file = ''
" Script-local variable needed since compare functions can't
" take extra arguments
let s:compare_typeinfo = {}
@@ -1357,15 +1491,6 @@ function! s:OpenWindow(autoclose)
endif
let &cpoptions = cpoptions_save
execute 'wincmd p'
" Jump back to the tagbar window if autoclose or autofocus is set. Can't
" just stay in it since it wouldn't trigger the update event
if g:tagbar_autoclose || a:autoclose || g:tagbar_autofocus
let tagbarwinnr = bufwinnr('__Tagbar__')
execute tagbarwinnr . 'wincmd w'
endif
endfunction
" s:CloseWindow() {{{2
@@ -1430,61 +1555,15 @@ function! s:ProcessFile(fname, ftype)
return
endif
let typeinfo = s:known_types[a:ftype]
let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:ftype)
if has_key(typeinfo, 'ctagsargs')
let ctags_args = ' ' . typeinfo.ctagsargs . ' '
else
let ctags_args = ' -f - '
let ctags_args .= ' --format=2 '
let ctags_args .= ' --excmd=pattern '
let ctags_args .= ' --fields=nksSa '
let ctags_args .= ' --extra= '
let ctags_args .= ' --sort=yes '
" Include extra type definitions
if has_key(typeinfo, 'deffile')
let ctags_args .= ' --options=' . typeinfo.deffile . ' '
endif
let ctags_type = typeinfo.ctagstype
let ctags_kinds = ''
for kind in typeinfo.kinds
let ctags_kinds .= kind.short
endfor
let ctags_args .= ' --language-force=' . ctags_type .
\ ' --' . ctags_type . '-kinds=' . ctags_kinds . ' '
endif
if has_key(typeinfo, 'ctagsbin')
let ctags_bin = expand(typeinfo.ctagsbin)
else
let ctags_bin = g:tagbar_ctags_bin
endif
if has('win32') || has('win64')
let ctags_bin = fnamemodify(ctags_bin, ':8')
else
let ctags_bin = shellescape(ctags_bin)
endif
let ctags_cmd = ctags_bin . ctags_args . shellescape(a:fname)
let ctags_output = system(ctags_cmd)
if v:shell_error
echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!'
echomsg 'Executed command: "' . ctags_cmd . '"'
if !empty(ctags_output)
echomsg 'Command output:'
for line in split(ctags_output, '\n')
echomsg line
endfor
endif
if ctags_output == -1
" put an empty entry into known_files so the error message is only
" shown once
call s:known_files.put({}, a:fname)
return
elseif ctags_output == ''
return
endif
" If the file has only been updated preserve the fold states, otherwise
@@ -1496,6 +1575,8 @@ function! s:ProcessFile(fname, ftype)
let fileinfo = s:FileInfo.New(a:fname, a:ftype)
endif
let typeinfo = s:known_types[a:ftype]
" Parse the ctags output lines
let rawtaglist = split(ctags_output, '\n\+')
for line in rawtaglist
@@ -1559,6 +1640,64 @@ function! s:ProcessFile(fname, ftype)
call s:known_files.put(fileinfo)
endfunction
" s:ExecuteCtagsOnFile() {{{2
function! s:ExecuteCtagsOnFile(fname, ftype)
let typeinfo = s:known_types[a:ftype]
if has_key(typeinfo, 'ctagsargs')
let ctags_args = ' ' . typeinfo.ctagsargs . ' '
else
let ctags_args = ' -f - '
let ctags_args .= ' --format=2 '
let ctags_args .= ' --excmd=pattern '
let ctags_args .= ' --fields=nksSa '
let ctags_args .= ' --extra= '
let ctags_args .= ' --sort=yes '
" Include extra type definitions
if has_key(typeinfo, 'deffile')
let ctags_args .= ' --options=' . typeinfo.deffile . ' '
endif
let ctags_type = typeinfo.ctagstype
let ctags_kinds = ''
for kind in typeinfo.kinds
let ctags_kinds .= kind.short
endfor
let ctags_args .= ' --language-force=' . ctags_type .
\ ' --' . ctags_type . '-kinds=' . ctags_kinds . ' '
endif
if has_key(typeinfo, 'ctagsbin')
let ctags_bin = expand(typeinfo.ctagsbin)
else
let ctags_bin = g:tagbar_ctags_bin
endif
let ctags_cmd = s:EscapeCtagsCmd(ctags_bin, ctags_args, a:fname)
if ctags_cmd == ''
return ''
endif
let ctags_output = s:ExecuteCtags(ctags_cmd)
if v:shell_error || ctags_output =~ 'Warning: cannot open source file'
echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!'
echomsg 'Executed command: "' . ctags_cmd . '"'
if !empty(ctags_output)
echomsg 'Command output:'
for line in split(ctags_output, '\n')
echomsg line
endfor
endif
return -1
endif
return ctags_output
endfunction
" s:ParseTagline() {{{2
" Structure of a tag line:
" tagname<TAB>filename<TAB>expattern;"fields
@@ -1575,7 +1714,7 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo)
let pattern = join(basic_info[2:], "\t")
let start = 2 " skip the slash and the ^
let end = strlen(pattern) - 1
if pattern[end - 1] == '$'
if pattern[end - 1] ==# '$'
let end -= 1
let dollar = '\$'
else
@@ -1650,9 +1789,9 @@ function! s:AddScopedTags(tags, processedtags, parent, 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 ||
\ (v:val.path ==# curpath ||
\ match(v:val.path, ''\V\^\C'' . curpath . a:typeinfo.sro) == 0) &&
\ (v:val.path == curpath ? (v:val.scope == pscope) : 1)'
\ (v:val.path ==# curpath ? (v:val.scope ==# pscope) : 1)'
endif
let curtags = filter(copy(a:tags), is_cur_tag)
@@ -1732,7 +1871,7 @@ function! s:ProcessPseudoTag(curtags, tag, parent, typeinfo, 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 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 . ')')
@@ -1819,27 +1958,27 @@ endfunction
function! s:CompareByKind(tag1, tag2)
let typeinfo = s:compare_typeinfo
if typeinfo.kinddict[a:tag1.fields.kind] <
if typeinfo.kinddict[a:tag1.fields.kind] <#
\ typeinfo.kinddict[a:tag2.fields.kind]
return -1
elseif typeinfo.kinddict[a:tag1.fields.kind] >
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] == '~'
if a:tag1.name[0] ==# '~'
let name1 = a:tag1.name[1:]
else
let name1 = a:tag1.name
endif
if a:tag2.name[0] == '~'
if a:tag2.name[0] ==# '~'
let name2 = a:tag2.name[1:]
else
let name2 = a:tag2.name
endif
if name1 <= name2
if name1 <=# name2
return -1
else
return 1
@@ -1902,7 +2041,7 @@ function! s:RenderContent(...)
endif
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
let saveline = line('.')
let savecol = col('.')
@@ -1911,6 +2050,8 @@ function! s:RenderContent(...)
let lazyredraw_save = &lazyredraw
set lazyredraw
let eventignore_save = &eventignore
set eventignore=all
setlocal modifiable
@@ -1935,7 +2076,7 @@ function! s:RenderContent(...)
setlocal nomodifiable
if !empty(s:known_files.getCurrent()) &&
\ fileinfo.fpath == s:known_files.getCurrent().fpath
\ fileinfo.fpath ==# s:known_files.getCurrent().fpath
let scrolloff_save = &scrolloff
set scrolloff=0
@@ -1951,7 +2092,8 @@ function! s:RenderContent(...)
call winline()
endif
let &lazyredraw = lazyredraw_save
let &lazyredraw = lazyredraw_save
let &eventignore = eventignore_save
if !in_tagbar
execute prevwinnr . 'wincmd w'
@@ -2177,7 +2319,30 @@ function! s:JumpToTag(stay_in_tagbar)
endif
let tagbarwinnr = winnr()
" This elaborate construct will try to switch to the correct
" buffer/window; if the buffer isn't currently shown in a window it will
" open it in the first window with a non-special buffer in it
execute 'wincmd p'
let filebufnr = bufnr(taginfo.fileinfo.fpath)
if bufnr('%') != filebufnr
let filewinnr = bufwinnr(filebufnr)
if filewinnr != -1
execute filewinnr . 'wincmd w'
else
for i in range(1, winnr('$'))
execute i . 'wincmd w'
if &buftype == ''
execute 'buffer ' . filebufnr
break
endif
endfor
endif
" To make ctrl-w_p work we switch between the Tagbar window and the
" correct window once
execute tagbarwinnr . 'wincmd w'
execute 'wincmd p'
endif
" Mark current position so it can be jumped back to
mark '
@@ -2400,7 +2565,6 @@ endfunction
function! s:CleanUp()
silent autocmd! TagbarAutoCmds
unlet s:current_file
unlet s:is_maximized
unlet s:compare_typeinfo
unlet s:short_help
@@ -2434,14 +2598,14 @@ function! s:AutoUpdate(fname)
return
endif
" Only consider the main filetype in cases like 'python.django'
let ftype = get(split(&filetype, '\.'), 0, '')
" Don't do anything if the file isn't supported
if !s:IsValidFile(a:fname, &filetype)
if !s:IsValidFile(a:fname, ftype)
return
endif
" Only consider the main filetype in cases like 'python.django'
let ftype = split(&filetype, '\.')[0]
" Process the file if it's unknown or the information is outdated
" Also test for entries that exist but are empty, which will be the case
" if there was an error during the ctags execution
@@ -2490,6 +2654,76 @@ function! s:IsValidFile(fname, ftype)
return 1
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
function! s:EscapeCtagsCmd(ctags_bin, args, ...)
if exists('+shellslash')
let shellslash_save = &shellslash
set noshellslash
endif
if a:0 == 1
let fname = shellescape(a:1)
else
let fname = ''
endif
let ctags_cmd = shellescape(a:ctags_bin) . ' ' . a:args . ' ' . fname
if exists('+shellslash')
let &shellslash = shellslash_save
endif
" Needed for cases where 'encoding' is different from the system's
" encoding
if g:tagbar_systemenc != &encoding
let ctags_cmd = iconv(ctags_cmd, &encoding, g:tagbar_systemenc)
elseif $LANG != ''
let ctags_cmd = iconv(ctags_cmd, &encoding, $LANG)
endif
if ctags_cmd == ''
echoerr 'Tagbar: Encoding conversion failed!'
\ 'Please make sure your system is set up correctly'
\ 'and that Vim is compiled with the "iconv" feature.'
endif
return ctags_cmd
endfunction
" s:ExecuteCtags() {{{2
" Execute ctags with necessary shell settings
" Partially based on the discussion at
" http://vim.1045645.n5.nabble.com/bad-default-shellxquote-in-Widows-td1208284.html
function! s:ExecuteCtags(ctags_cmd)
if exists('+shellslash')
let shellslash_save = &shellslash
set noshellslash
endif
if &shell =~ 'cmd\.exe'
let shellxquote_save = &shellxquote
set shellxquote=\"
let shellcmdflag_save = &shellcmdflag
set shellcmdflag=/s\ /c
endif
let ctags_output = system(a:ctags_cmd)
if &shell =~ 'cmd\.exe'
let &shellxquote = shellxquote_save
let &shellcmdflag = shellcmdflag_save
endif
if exists('+shellslash')
let &shellslash = shellslash_save
endif
return ctags_output
endfunction
" 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
+1 -1
View File
@@ -3,7 +3,7 @@
" Author: Jan Larres <jan@majutsushi.net>
" Licence: Vim licence
" Website: http://majutsushi.github.com/tagbar/
" Version: 2.0
" Version: 2.1
if exists("b:current_syntax")
finish