Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Allow to specify different ctags tool for particular languages. #40

Merged
merged 1 commit into from
Apr 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 49 additions & 27 deletions autoload/xolox/easytags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,47 @@ function! s:check_cfile(silent, filter_tags, have_args) " {{{3
endfunction

function! s:prep_cmdline(cfile, tagsfile, firstrun, arguments, context) " {{{3
let program = xolox#misc#option#get('easytags_cmd')
let cmdline = [program, '--fields=+l', '--c-kinds=+p', '--c++-kinds=+p']
if a:firstrun
call add(cmdline, xolox#misc#escape#shell('-f' . a:tagsfile))
call add(cmdline, '--sort=' . (&ic ? 'foldcase' : 'yes'))
let languages = xolox#misc#option#get('easytags_languages', {})
let ctags_language_name = xolox#easytags#to_ctags_ft(&filetype)
let language = get(languages, ctags_language_name, {})
if empty(language)
let program = xolox#misc#option#get('easytags_cmd')
let cmdline = [program, '--fields=+l', '--c-kinds=+p', '--c++-kinds=+p']
if a:firstrun
call add(cmdline, xolox#misc#escape#shell('-f' . a:tagsfile))
call add(cmdline, '--sort=' . (&ic ? 'foldcase' : 'yes'))
else
call add(cmdline, '--sort=no')
call add(cmdline, '-f-')
endif
if xolox#misc#option#get('easytags_include_members', 0)
call add(cmdline, '--extra=+q')
endif
else
call add(cmdline, '--sort=no')
call add(cmdline, '-f-')
endif
if xolox#misc#option#get('easytags_include_members', 0)
call add(cmdline, '--extra=+q')
let program = get(language, 'cmd', xolox#misc#option#get('easytags_cmd'))
if empty(program)
call xolox#misc#msg#warn("easytags.vim %s: No 'cmd' defined for language '%s', and also no global default!", g:xolox#easytags#version, ctags_language_name)
return
endif
let cmdline = [program] + get(language, 'args', [])
if a:firstrun
call add(cmdline, xolox#misc#escape#shell(get(language, 'fileoutput_opt', '-f') . a:tagsfile))
else
call add(cmdline, xolox#misc#escape#shell(get(language, 'stdout_opt', '-f-')))
endif
endif
let have_args = 0
if a:cfile != ''
if xolox#misc#option#get('easytags_autorecurse', 0)
call add(cmdline, '-R')
call add(cmdline, empty(language) ? '-R' : xolox#misc#escape#shell(get(language, 'recurse_flag', '-R')))
call add(cmdline, xolox#misc#escape#shell(a:cfile))
else
" TODO Should --language-force distinguish between C and C++?
" TODO --language-force doesn't make sense for JavaScript tags in HTML files?
let filetype = xolox#easytags#to_ctags_ft(&filetype)
call add(cmdline, xolox#misc#escape#shell('--language-force=' . filetype))
if empty(language)
" TODO Should --language-force distinguish between C and C++?
" TODO --language-force doesn't make sense for JavaScript tags in HTML files?
let filetype = xolox#easytags#to_ctags_ft(&filetype)
call add(cmdline, xolox#misc#escape#shell('--language-force=' . filetype))
endif
call add(cmdline, xolox#misc#escape#shell(a:cfile))
endif
let have_args = 1
Expand Down Expand Up @@ -414,18 +433,21 @@ endfunction
function! xolox#easytags#supported_filetypes() " {{{2
if !exists('s:supported_filetypes')
let starttime = xolox#misc#timer#start()
let command = g:easytags_cmd . ' --list-languages'
try
let listing = xolox#shell#execute(command, 1)
catch /^Vim\%((\a\+)\)\=:E117/
" Ignore missing shell.vim plug-in.
let listing = split(system(command), "\n")
if v:shell_error
let msg = "Failed to get supported languages! (output: %s)"
throw printf(msg, strtrans(join(listing, "\n")))
endif
endtry
let s:supported_filetypes = map(copy(listing), 's:check_filetype(listing, v:val)')
let listing = []
if !empty(g:easytags_cmd)
let command = g:easytags_cmd . ' --list-languages'
try
let listing = xolox#shell#execute(command, 1)
catch /^Vim\%((\a\+)\)\=:E117/
" Ignore missing shell.vim plug-in.
let listing = split(system(command), "\n")
if v:shell_error
let msg = "Failed to get supported languages! (output: %s)"
throw printf(msg, strtrans(join(listing, "\n")))
endif
endtry
endif
let s:supported_filetypes = map(copy(listing) + keys(xolox#misc#option#get('easytags_languages', {})), 's:check_filetype(listing, v:val)')
let msg = "easytags.vim %s: Retrieved %i supported languages in %s."
call xolox#misc#timer#stop(msg, g:xolox#easytags#version, len(s:supported_filetypes), starttime)
endif
Expand Down
27 changes: 27 additions & 0 deletions doc/easytags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ where you've installed Exuberant Ctags, e.g.:
>
:let g:easytags_cmd = '/usr/local/bin/ctags'

If you entirely rely on language-specific configuration and don't have a
general ctags program, set this to the empty string.

-------------------------------------------------------------------------------
The *g:easytags_languages* option

The Exuberant Ctags tools supports many languages and can be extended via
regexp patterns, but for some languages, separate tools with ctags-compatible
output exist (e.g. jsctags for Javascript). To use these, the executable and
its arguments must be configured. >

let g:easytags_languages = {
\ 'language': {
\ 'cmd': g:easytags_cmd,
\ 'args': [],
\ 'fileoutput_opt': '-f',
\ 'stdout_opt': '-f-',
\ 'recurse_flag': '-R'
\ }
\}

Each key is a special language definition. The key is in the notation of
ctags in lowercase; you still need to use xolox#easytags#map_filetypes() to
map this to Vim's filetypes, if necessary.
Above snippets shows the defaults; you only need to specify options that
differ.

-------------------------------------------------------------------------------
The *g:easytags_file* option

Expand Down