Skip to content
This repository

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

Merged
merged 1 commit into from 12 months ago

3 participants

Ingo Karkat Andrew Myers Peter Odding
Ingo Karkat

Implement this via a new configuration option g:easytags_languages, a Dictionary that contains the ctags languages as keys, and corresponding special cmds, args, etc. as values.

Ingo Karkat ENH: Allow to specify different ctags tool for particular languages.
Implement this via a new configuration option g:easytags_languages, a Dictionary that contains the ctags languages as keys, and corresponding special cmds, args, etc. as values.
8a0a363
Andrew Myers

I would love to see this feature merged into mainline easytags.

Peter Odding xolox referenced this pull request from a commit April 19, 2013
Peter Odding Move g:easytags_languages documentation to README.md
Integration of pull request #40:
#40
ebe2ba9
Peter Odding xolox merged commit 8a0a363 into from April 18, 2013
Peter Odding xolox closed this April 18, 2013
Peter Odding
Owner
xolox commented April 18, 2013

Hey Ingo,

I like the feature! You got vim-easytags to 3.0. Thank you kind sir :-)

- Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 07, 2013
Ingo Karkat ENH: Allow to specify different ctags tool for particular languages.
Implement this via a new configuration option g:easytags_languages, a Dictionary that contains the ctags languages as keys, and corresponding special cmds, args, etc. as values.
8a0a363
This page is out of date. Refresh to see the latest.
76  autoload/xolox/easytags.vim
@@ -157,28 +157,47 @@ function! s:check_cfile(silent, filter_tags, have_args) " {{{3
157 157
 endfunction
158 158
 
159 159
 function! s:prep_cmdline(cfile, tagsfile, firstrun, arguments, context) " {{{3
160  
-  let program = xolox#misc#option#get('easytags_cmd')
161  
-  let cmdline = [program, '--fields=+l', '--c-kinds=+p', '--c++-kinds=+p']
162  
-  if a:firstrun
163  
-    call add(cmdline, xolox#misc#escape#shell('-f' . a:tagsfile))
164  
-    call add(cmdline, '--sort=' . (&ic ? 'foldcase' : 'yes'))
  160
+  let languages = xolox#misc#option#get('easytags_languages', {})
  161
+  let ctags_language_name = xolox#easytags#to_ctags_ft(&filetype)
  162
+  let language = get(languages, ctags_language_name, {})
  163
+  if empty(language)
  164
+    let program = xolox#misc#option#get('easytags_cmd')
  165
+    let cmdline = [program, '--fields=+l', '--c-kinds=+p', '--c++-kinds=+p']
  166
+    if a:firstrun
  167
+      call add(cmdline, xolox#misc#escape#shell('-f' . a:tagsfile))
  168
+      call add(cmdline, '--sort=' . (&ic ? 'foldcase' : 'yes'))
  169
+    else
  170
+      call add(cmdline, '--sort=no')
  171
+      call add(cmdline, '-f-')
  172
+    endif
  173
+    if xolox#misc#option#get('easytags_include_members', 0)
  174
+      call add(cmdline, '--extra=+q')
  175
+    endif
165 176
   else
166  
-    call add(cmdline, '--sort=no')
167  
-    call add(cmdline, '-f-')
168  
-  endif
169  
-  if xolox#misc#option#get('easytags_include_members', 0)
170  
-    call add(cmdline, '--extra=+q')
  177
+    let program = get(language, 'cmd', xolox#misc#option#get('easytags_cmd'))
  178
+    if empty(program)
  179
+      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)
  180
+      return
  181
+    endif
  182
+    let cmdline = [program] + get(language, 'args', [])
  183
+    if a:firstrun
  184
+      call add(cmdline, xolox#misc#escape#shell(get(language, 'fileoutput_opt', '-f') . a:tagsfile))
  185
+    else
  186
+      call add(cmdline, xolox#misc#escape#shell(get(language, 'stdout_opt', '-f-')))
  187
+    endif
171 188
   endif
172 189
   let have_args = 0
173 190
   if a:cfile != ''
174 191
     if xolox#misc#option#get('easytags_autorecurse', 0)
175  
-      call add(cmdline, '-R')
  192
+      call add(cmdline, empty(language) ? '-R' : xolox#misc#escape#shell(get(language, 'recurse_flag', '-R')))
176 193
       call add(cmdline, xolox#misc#escape#shell(a:cfile))
177 194
     else
178  
-      " TODO Should --language-force distinguish between C and C++?
179  
-      " TODO --language-force doesn't make sense for JavaScript tags in HTML files?
180  
-      let filetype = xolox#easytags#to_ctags_ft(&filetype)
181  
-      call add(cmdline, xolox#misc#escape#shell('--language-force=' . filetype))
  195
+      if empty(language)
  196
+        " TODO Should --language-force distinguish between C and C++?
  197
+        " TODO --language-force doesn't make sense for JavaScript tags in HTML files?
  198
+        let filetype = xolox#easytags#to_ctags_ft(&filetype)
  199
+        call add(cmdline, xolox#misc#escape#shell('--language-force=' . filetype))
  200
+      endif
182 201
       call add(cmdline, xolox#misc#escape#shell(a:cfile))
183 202
     endif
184 203
     let have_args = 1
@@ -414,18 +433,21 @@ endfunction
414 433
 function! xolox#easytags#supported_filetypes() " {{{2
415 434
   if !exists('s:supported_filetypes')
416 435
     let starttime = xolox#misc#timer#start()
417  
-    let command = g:easytags_cmd . ' --list-languages'
418  
-    try
419  
-      let listing = xolox#shell#execute(command, 1)
420  
-    catch /^Vim\%((\a\+)\)\=:E117/
421  
-      " Ignore missing shell.vim plug-in.
422  
-      let listing = split(system(command), "\n")
423  
-      if v:shell_error
424  
-        let msg = "Failed to get supported languages! (output: %s)"
425  
-        throw printf(msg, strtrans(join(listing, "\n")))
426  
-      endif
427  
-    endtry
428  
-    let s:supported_filetypes = map(copy(listing), 's:check_filetype(listing, v:val)')
  436
+    let listing = []
  437
+    if !empty(g:easytags_cmd)
  438
+      let command = g:easytags_cmd . ' --list-languages'
  439
+      try
  440
+        let listing = xolox#shell#execute(command, 1)
  441
+      catch /^Vim\%((\a\+)\)\=:E117/
  442
+        " Ignore missing shell.vim plug-in.
  443
+        let listing = split(system(command), "\n")
  444
+        if v:shell_error
  445
+          let msg = "Failed to get supported languages! (output: %s)"
  446
+          throw printf(msg, strtrans(join(listing, "\n")))
  447
+        endif
  448
+      endtry
  449
+    endif
  450
+    let s:supported_filetypes = map(copy(listing) + keys(xolox#misc#option#get('easytags_languages', {})), 's:check_filetype(listing, v:val)')
429 451
     let msg = "easytags.vim %s: Retrieved %i supported languages in %s."
430 452
     call xolox#misc#timer#stop(msg, g:xolox#easytags#version, len(s:supported_filetypes), starttime)
431 453
   endif
27  doc/easytags.txt
@@ -125,6 +125,33 @@ where you've installed Exuberant Ctags, e.g.:
125 125
 >
126 126
     :let g:easytags_cmd = '/usr/local/bin/ctags'
127 127
 
  128
+If you entirely rely on language-specific configuration and don't have a
  129
+general ctags program, set this to the empty string.
  130
+
  131
+-------------------------------------------------------------------------------
  132
+The *g:easytags_languages* option
  133
+
  134
+The Exuberant Ctags tools supports many languages and can be extended via
  135
+regexp patterns, but for some languages, separate tools with ctags-compatible
  136
+output exist (e.g. jsctags for Javascript). To use these, the executable and
  137
+its arguments must be configured. >
  138
+
  139
+    let g:easytags_languages = {
  140
+    \   'language': {
  141
+    \       'cmd': g:easytags_cmd,
  142
+    \	    'args': [],
  143
+    \	    'fileoutput_opt': '-f',
  144
+    \	    'stdout_opt': '-f-',
  145
+    \	    'recurse_flag': '-R'
  146
+    \   }
  147
+    \}
  148
+
  149
+Each key is a special language definition. The key is in the notation of
  150
+ctags in lowercase; you still need to use xolox#easytags#map_filetypes() to
  151
+map this to Vim's filetypes, if necessary.
  152
+Above snippets shows the defaults; you only need to specify options that
  153
+differ.
  154
+
128 155
 -------------------------------------------------------------------------------
129 156
 The *g:easytags_file* option
130 157
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.