From f9b50a1e95f4455c886c6c1464d46acea315ebce Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Wed, 21 Dec 2011 20:33:31 +1300 Subject: [PATCH] Remove need to provide complete jsctags configuration if jsctags not in path --- autoload/tagbar.vim | 49 ++++++++++++++++++++++++++++++++------------- doc/tagbar.txt | 6 +++--- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 49b7565..a8512c3 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -418,7 +418,8 @@ function! s:InitTypes() " Alternatively jsctags/doctorjs will be used if available. let type_javascript = {} let type_javascript.ctagstype = 'javascript' - if executable('jsctags') + let jsctags = s:CheckFTCtags('jsctags', 'javascript') + if jsctags != '' let type_javascript.kinds = [ \ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} @@ -431,7 +432,7 @@ function! s:InitTypes() let type_javascript.scope2kind = { \ 'namespace' : 'v' \ } - let type_javascript.ctagsbin = 'jsctags' + let type_javascript.ctagsbin = jsctags let type_javascript.ctagsargs = '-f -' else let type_javascript.kinds = [ @@ -785,18 +786,20 @@ function! s:GetUserTypeDefs() " generate the other one " Also, transform the 'kind' definitions into dictionary format for def in values(defdict) - let kinds = def.kinds - let def.kinds = [] - for kind in kinds - let kindlist = split(kind, ':') - let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]} - if len(kindlist) == 3 - let kinddict.fold = kindlist[2] - else - let kinddict.fold = 0 - endif - call add(def.kinds, kinddict) - endfor + if has_key(def, 'kinds') + let kinds = def.kinds + let def.kinds = [] + for kind in kinds + let kindlist = split(kind, ':') + let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]} + if len(kindlist) == 3 + let kinddict.fold = kindlist[2] + else + let kinddict.fold = 0 + endif + call add(def.kinds, kinddict) + endfor + endif if has_key(def, 'kind2scope') && !has_key(def, 'scope2kind') let def.scope2kind = {} @@ -972,6 +975,24 @@ function! s:CheckExCtagsVersion(output) return major >= 6 || (major == 5 && minor >= 5) 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 " Base tag {{{2 let s:BaseTag = {} diff --git a/doc/tagbar.txt b/doc/tagbar.txt index bd641ac..ae33cb6 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -663,9 +663,9 @@ deffile: The path to a file with additional ctags definitions (see the 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 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 - complete configuration and use the "replace" key (see the - Tagbar source code for the suggested configuration). + set in that case. If it is not in your path you have to set this + key, the rest of the configuration should not be necessary (unless + you want to change something, of course). 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 program output its data on stdout. Not used for the normal ctags