aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2010-06-15 08:58:12 +0200
committerPeter Odding <peter@peterodding.com>2010-06-15 08:58:12 +0200
commit5cb775c9a8e8ea07abbb39f09f72c818c2ad518b (patch)
tree7d4e93c4267f7c68c62413a2edd57bdc32723699
parentd064e0639f488b975af12aad01040493e265804c (diff)
downloadvim-easytags-5cb775c9a8e8ea07abbb39f09f72c818c2ad518b.tar.gz
Version detection, better error handling, bug fix for dynamic highlighting
* The plug-in now executes `ctags --version` on startup to verify that the correct version of Exuberant Ctags is installed because some systems (including Mac OS X apparently) ship with a `/usr/bin/ctags` installed that doesn't understand the extensive set of command-line arguments supported by Exuberant Ctags. * When a file was edited multiple times the dynamic highlighting wouldn't refresh because the plug-in thought the highlighting was still in effect while in reality it was cleared by reading the file again. Now the highlighting will be refreshed on the next CursorHold event like it's supposed to.
-rw-r--r--TODO.md8
-rw-r--r--autoload.vim32
-rw-r--r--easytags.vim75
3 files changed, 78 insertions, 37 deletions
diff --git a/TODO.md b/TODO.md
index 6a6a717..798a258 100644
--- a/TODO.md
+++ b/TODO.md
@@ -31,3 +31,11 @@
`~/.vim/autoload/easytags.vim` (a symbolic link to
`~/Development/Vim/vim-easytags/autoload.vim`). I was already editing
`~/.vim/autoload/easytags.vim` in another Vim buffer.
+
+ * Convert `easytags#update_cmd()` to a function that can be executed on a
+ list of files and will only execute Exuberant Ctags once to do so, then
+ change `:UpdateTags` to accept an optional file glob, e.g. `:UpdateTags
+ /usr/include/lua5.1/*.h` and call `easytags#update_cmd()` on the matching
+ files.
+
+vim: ai nofen
diff --git a/autoload.vim b/autoload.vim
index b536908..efd18ce 100644
--- a/autoload.vim
+++ b/autoload.vim
@@ -1,8 +1,10 @@
" Vim script
" Maintainer: Peter Odding <peter@peterodding.com>
-" Last Change: June 14, 2010
+" Last Change: June 15, 2010
" URL: http://peterodding.com/code/vim/easytags
+let s:script = expand('<sfile>:p:~')
+
" Public interface through (automatic) commands. {{{1
function! easytags#autoload() " {{{2
@@ -28,7 +30,7 @@ function! easytags#autoload() " {{{2
let b:easytags_last_highlighted = localtime()
endif
catch
- call xolox#warning("easytags.vim: %s (at %s)", v:exception, v:throwpoint)
+ call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
endtry
endfunction
@@ -59,7 +61,8 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
call filter(entries, join(filters, ' && '))
if len(entries) != num_entries
if !easytags#write_tagsfile(tagsfile, header, entries)
- throw "Failed to write filtered tags file!"
+ let msg = "Failed to write filtered tags file %s!"
+ throw printf(msg, fnamemodify(tagsfile, ':~'))
endif
endif
endif
@@ -69,16 +72,18 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
call add(command, shellescape(filename))
let listing = system(join(command))
if v:shell_error
- throw "Failed to update tags file! (Ctags output: `" . listing . "')"
+ let msg = "Failed to update tags file %s: %s!"
+ throw printf(msg, fnamemodify(tagsfile, ':~'), strtrans(v:exception))
endif
call easytags#add_tagged_file(filename)
endif
- call xolox#timer#stop(start, "easytags.vim: Updated tags in %s second(s)")
+ let msg = "%s: Updated tags for %s in %s."
+ call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
return 1
endif
return 0
catch
- call xolox#warning("easytags.vim: %s (at %s)", v:exception, v:throwpoint)
+ call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
endtry
endfunction
@@ -108,10 +113,11 @@ function! easytags#highlight_cmd() " {{{2
endif
endfor
redraw
- call xolox#timer#stop(start, "easytags.vim: Highlighted tags in %s second(s)")
+ let msg = "%s: Highlighted tags in %s in %s."
+ call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
endif
catch
- call xolox#warning("easytags.vim: %s (at %s)", v:exception, v:throwpoint)
+ call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
endtry
endfunction
@@ -122,11 +128,13 @@ function! easytags#supported_filetypes() " {{{2
let start = xolox#timer#start()
let listing = system(g:easytags_cmd . ' --list-languages')
if v:shell_error
- throw "Failed to get Exuberant Ctags language mappings!"
+ let msg = "Failed to get supported languages! (output: %s)"
+ throw printf(msg, strtrans(listing))
endif
let s:supported_filetypes = split(listing, '\n')
call map(s:supported_filetypes, 'easytags#to_vim_ft(v:val)')
- call xolox#timer#stop(start, "easytags.vim: Parsed language mappings in %s second(s)")
+ let msg = "%s: Retrieved supported languages in %s."
+ call xolox#timer#stop(msg, s:script, start)
endif
return s:supported_filetypes
endfunction
@@ -173,8 +181,8 @@ endfunction
function! easytags#get_tagsfile() " {{{2
let tagsfile = expand(g:easytags_file)
if filereadable(tagsfile) && filewritable(tagsfile) != 1
- let message = "The tags file isn't writable! (%s)"
- throw printf(message, tagsfile)
+ let message = "The tags file %s isn't writable!"
+ throw printf(message, fnamemodify(tagsfile, ':~'))
endif
return tagsfile
endfunction
diff --git a/easytags.vim b/easytags.vim
index fc6ab77..30efb3d 100644
--- a/easytags.vim
+++ b/easytags.vim
@@ -1,10 +1,10 @@
" Vim plug-in
" Maintainer: Peter Odding <peter@peterodding.com>
-" Last Change: June 13, 2010
+" Last Change: June 15, 2010
" URL: http://peterodding.com/code/vim/easytags
" Requires: Exuberant Ctags (http://ctags.sf.net)
" License: MIT
-" Version: 1.9
+" Version: 1.9.3
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip
@@ -40,38 +40,62 @@ if !exists('g:easytags_ignored_filetypes')
let g:easytags_ignored_filetypes = '^tex$'
endif
-" Before sourcing the rest of the plug-in first check that the location of the
-" "Exuberant Ctags" program has been configured or that the program exists in
-" one of its default locations.
-
-if exists('g:easytags_cmd') && executable(g:easytags_cmd)
- let s:ctags_installed = 1
-else
+function! s:InitEasyTags(version)
+ " Check that the location of Exuberant Ctags has been configured or that the
+ " correct version of the program exists in one of its default locations.
+ if exists('g:easytags_cmd') && s:CheckCtags(g:easytags_cmd, a:version)
+ return 1
+ endif
" On Ubuntu Linux, Exuberant Ctags is installed as `ctags'. On Debian Linux,
" Exuberant Ctags is installed as `exuberant-ctags'. On Free-BSD, Exuberant
" Ctags is installed as `exctags'. Finally there is `ctags.exe' on Windows.
- for s:command in ['ctags', 'exuberant-ctags', 'esctags', 'ctags.exe']
- if executable(s:command)
- let g:easytags_cmd = s:command
- let s:ctags_installed = 1
- break
+ for name in ['ctags', 'exuberant-ctags', 'esctags']
+ if s:CheckCtags(name, a:version)
+ let g:easytags_cmd = name
+ return 1
endif
endfor
- unlet s:command
-endif
-
-if !exists('s:ctags_installed')
- echomsg "easytags.vim: Exuberant Ctags unavailable! Plug-in not loaded."
- if executable('apt-get')
- echomsg "On Ubuntu & Debian Linux, you can install Exuberant Ctags"
- echomsg "by installing the package named `exuberant-ctags':"
- echomsg " sudo apt-get install exuberant-ctags"
+endfunction
+
+function! s:CheckCtags(name, version)
+ " Not every executable out there named `ctags' is in fact Exuberant Ctags.
+ " This function makes sure it is because the easytags plug-in requires the
+ " --list-languages option.
+ if executable(a:name)
+ let listing = system(a:name . ' --version')
+ let pattern = 'Exuberant Ctags \zs\d\+\(\.\d\+\)*'
+ let g:easytags_ctags_version = matchstr(listing, pattern)
+ return s:VersionToNumber(g:easytags_ctags_version) >= a:version
+ endif
+endfunction
+
+function! s:VersionToNumber(s)
+ let values = split(a:s, '\.')
+ if len(values) == 1
+ return values[0] * 10
+ elseif len(values) >= 2
+ return values[0] * 10 + values[1][0]
+ endif
+endfunction
+
+if !s:InitEasyTags(55)
+ if !exists('g:easytags_ctags_version') || empty(g:easytags_ctags_version)
+ let msg = "easytags.vim: Plug-in not loaded because Exuberant Ctags isn't installed!"
+ if executable('apt-get')
+ let msg ,= " On Ubuntu & Debian you can install Exuberant Ctags by"
+ let msg .= " installing the package named `exuberant-ctags':"
+ let msg .= " sudo apt-get install exuberant-ctags"
+ else
+ let msg .= " Please download & install Exuberant Ctags from http://ctags.sf.net"
+ endif
+ echomsg msg
else
- echomsg "Please download & install Exuberant Ctags from http://ctags.sf.net"
+ let msg = "easytags.vim: Plug-in not loaded because Exuberant Ctags 5.5"
+ let msg .= " or newer is required while you have version %s installed!"
+ echomsg printf(msg, g:easytags_ctags_version)
endif
finish
endif
-unlet s:ctags_installed
" Let Vim know about the global tags file created by this plug-in.
@@ -106,6 +130,7 @@ augroup PluginEasyTags
endif
if g:easytags_on_cursorhold
autocmd CursorHold,CursorHoldI * call easytags#autoload()
+ autocmd BufReadPost * unlet! b:easytags_last_highlighted
endif
autocmd User PublishPre HighlightTags
augroup END