Skip to content
This repository
Browse code

Alias support & defaults for C/C++/Obj-C/Obj-C++

In my ~/.vimrc I've set the following:

    :let c_syntax_for_h = 1

Which means easytags.vim will also scan *.h files as C source-code.
However Exuberant Ctags by default scans *.h files as C++, so when
you update your global tags file as follows from the command-line:

    ctags -af ~/.vimtags /usr/include/lua5.1/*.h

Which I happened to try today, the new tags won't be highlighted in
your C source-code because Exuberant Ctags thinks it's C++ and Vim
doesn't know otherwise. I've now added support for aliases between
file types and added a default set of aliases between C, C++, Obj-C
and Obj-C++.
  • Loading branch information...
commit 61b99f078557d65331e72de60d145e16b8bbb88e 1 parent cfeac5a
Peter Odding authored June 09, 2010

Showing 2 changed files with 34 additions and 4 deletions. Show diff stats Hide diff stats

  1. 34  autoload.vim
  2. 4  easytags.vim
34  autoload.vim
@@ -60,7 +60,7 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{1
60 60
         let filtered = filter(copy(lines), filter)
61 61
         if lines != filtered
62 62
           if writefile(filtered, tagsfile) != 0
63  
-            throw "Failed to filter tags file!"
  63
+            throw "Failed to write filtered tags file!"
64 64
           endif
65 65
         endif
66 66
         call xolox#timer#stop(start_filter, "easytags.vim: Filtered tags file in %s second(s)")
@@ -100,7 +100,12 @@ function! easytags#highlight_cmd() " {{{1
100 100
   try
101 101
     if exists('g:syntax_on') && has_key(s:tagkinds, &ft)
102 102
       let start = xolox#timer#start()
103  
-      let taglist = filter(taglist('.'), "get(v:val, 'language', '') ==? &ft")
  103
+      if !has_key(s:aliases, &ft)
  104
+        let taglist = filter(taglist('.'), "get(v:val, 'language', '') ==? &ft")
  105
+      else
  106
+        let aliases = s:aliases[&ft]
  107
+        let taglist = filter(taglist('.'), "has_key(aliases, tolower(get(v:val, 'language', '')))")
  108
+      endif
104 109
       for tagkind in s:tagkinds[&ft]
105 110
         let hlgroup_tagged = tagkind.hlgroup . 'Tag'
106 111
         if hlexists(hlgroup_tagged)
@@ -149,6 +154,28 @@ function! easytags#map_filetypes(vim_ft, ctags_ft) " {{{1
149 154
   call add(s:ctags_filetypes, a:ctags_ft)
150 155
 endfunction
151 156
 
  157
+function! easytags#alias_filetypes(...) " {{{1
  158
+  for type in a:000
  159
+    if !has_key(s:aliases, type)
  160
+      let s:aliases[type] = {}
  161
+    endif
  162
+  endfor
  163
+  for i in range(a:0)
  164
+    for j in range(a:0)
  165
+      let vimft1 = a:000[i]
  166
+      let ctagsft1 = easytags#to_ctags_ft(vimft1)
  167
+      let vimft2 = a:000[j]
  168
+      let ctagsft2 = easytags#to_ctags_ft(vimft2)
  169
+      if !has_key(s:aliases[vimft1], ctagsft2)
  170
+        let s:aliases[vimft1][ctagsft2] = 1
  171
+      endif
  172
+      if !has_key(s:aliases[vimft2], ctagsft1)
  173
+        let s:aliases[vimft2][ctagsft1] = 1
  174
+      endif
  175
+    endfor
  176
+  endfor
  177
+endfunction
  178
+
152 179
 function! easytags#to_vim_ft(ctags_ft) " {{{1
153 180
   let type = tolower(a:ctags_ft)
154 181
   let index = index(s:ctags_filetypes, type)
@@ -171,6 +198,9 @@ if !exists('s:tagkinds')
171 198
   call easytags#map_filetypes('cs', 'c#')
172 199
   call easytags#map_filetypes(exists('filetype_asp') ? filetype_asp : 'aspvbs', 'asp')
173 200
 
  201
+  let s:aliases = {}
  202
+  call easytags#alias_filetypes('c', 'cpp', 'objc', 'objcpp')
  203
+
174 204
   let s:tagkinds = {}
175 205
 
176 206
   " Enable line continuation.
4  easytags.vim
... ...
@@ -1,10 +1,10 @@
1 1
 " Vim plug-in
2 2
 " Maintainer: Peter Odding <peter@peterodding.com>
3  
-" Last Change: June 8, 2010
  3
+" Last Change: June 9, 2010
4 4
 " URL: http://peterodding.com/code/vim/easytags
5 5
 " Requires: Exuberant Ctags (http://ctags.sf.net)
6 6
 " License: MIT
7  
-" Version: 1.6
  7
+" Version: 1.7
8 8
 
9 9
 " Support for automatic update using the GLVS plug-in.
10 10
 " GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip

0 notes on commit 61b99f0

Please sign in to comment.
Something went wrong with that request. Please try again.