From 61b99f078557d65331e72de60d145e16b8bbb88e Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Wed, 9 Jun 2010 08:28:05 +0200 Subject: 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++. --- autoload.vim | 34 ++++++++++++++++++++++++++++++++-- easytags.vim | 4 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/autoload.vim b/autoload.vim index 80b4800..67377b2 100644 --- a/autoload.vim +++ b/autoload.vim @@ -60,7 +60,7 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{1 let filtered = filter(copy(lines), filter) if lines != filtered if writefile(filtered, tagsfile) != 0 - throw "Failed to filter tags file!" + throw "Failed to write filtered tags file!" endif endif call xolox#timer#stop(start_filter, "easytags.vim: Filtered tags file in %s second(s)") @@ -100,7 +100,12 @@ function! easytags#highlight_cmd() " {{{1 try if exists('g:syntax_on') && has_key(s:tagkinds, &ft) let start = xolox#timer#start() - let taglist = filter(taglist('.'), "get(v:val, 'language', '') ==? &ft") + if !has_key(s:aliases, &ft) + let taglist = filter(taglist('.'), "get(v:val, 'language', '') ==? &ft") + else + let aliases = s:aliases[&ft] + let taglist = filter(taglist('.'), "has_key(aliases, tolower(get(v:val, 'language', '')))") + endif for tagkind in s:tagkinds[&ft] let hlgroup_tagged = tagkind.hlgroup . 'Tag' if hlexists(hlgroup_tagged) @@ -149,6 +154,28 @@ function! easytags#map_filetypes(vim_ft, ctags_ft) " {{{1 call add(s:ctags_filetypes, a:ctags_ft) endfunction +function! easytags#alias_filetypes(...) " {{{1 + for type in a:000 + if !has_key(s:aliases, type) + let s:aliases[type] = {} + endif + endfor + for i in range(a:0) + for j in range(a:0) + let vimft1 = a:000[i] + let ctagsft1 = easytags#to_ctags_ft(vimft1) + let vimft2 = a:000[j] + let ctagsft2 = easytags#to_ctags_ft(vimft2) + if !has_key(s:aliases[vimft1], ctagsft2) + let s:aliases[vimft1][ctagsft2] = 1 + endif + if !has_key(s:aliases[vimft2], ctagsft1) + let s:aliases[vimft2][ctagsft1] = 1 + endif + endfor + endfor +endfunction + function! easytags#to_vim_ft(ctags_ft) " {{{1 let type = tolower(a:ctags_ft) let index = index(s:ctags_filetypes, type) @@ -171,6 +198,9 @@ if !exists('s:tagkinds') call easytags#map_filetypes('cs', 'c#') call easytags#map_filetypes(exists('filetype_asp') ? filetype_asp : 'aspvbs', 'asp') + let s:aliases = {} + call easytags#alias_filetypes('c', 'cpp', 'objc', 'objcpp') + let s:tagkinds = {} " Enable line continuation. diff --git a/easytags.vim b/easytags.vim index 9373d9a..9dc58ea 100644 --- a/easytags.vim +++ b/easytags.vim @@ -1,10 +1,10 @@ " Vim plug-in " Maintainer: Peter Odding -" Last Change: June 8, 2010 +" Last Change: June 9, 2010 " URL: http://peterodding.com/code/vim/easytags " Requires: Exuberant Ctags (http://ctags.sf.net) " License: MIT -" Version: 1.6 +" Version: 1.7 " Support for automatic update using the GLVS plug-in. " GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip -- cgit v1.2.3