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

Extract ctags execution into separate function

This commit is contained in:
Jan Larres
2011-05-08 23:08:15 +12:00
parent e28eab7945
commit d8122efcc6

View File

@@ -1471,60 +1471,15 @@ function! s:ProcessFile(fname, ftype)
return
endif
let typeinfo = s:known_types[a:ftype]
let ctags_output = s:ExecuteCtags(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
let ctags_cmd = s:EscapeCtagsCmd(ctags_bin, ctags_args, a:fname)
if ctags_cmd == ''
return
endif
let ctags_output = system(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
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
@@ -1536,6 +1491,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
@@ -1599,6 +1556,64 @@ function! s:ProcessFile(fname, ftype)
call s:known_files.put(fileinfo)
endfunction
" s:ExecuteCtags() {{{2
function! s:ExecuteCtags(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 = system(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