Skip to content
This repository
Browse code

Version detection, better error handling, bug fix for dynamic highlig…

…hting

 * 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.
  • Loading branch information...
commit 5cb775c9a8e8ea07abbb39f09f72c818c2ad518b 1 parent d064e06
Peter Odding authored June 15, 2010
8  TODO.md
Source Rendered
@@ -31,3 +31,11 @@
31 31
    `~/.vim/autoload/easytags.vim` (a symbolic link to
32 32
    `~/Development/Vim/vim-easytags/autoload.vim`). I was already editing
33 33
    `~/.vim/autoload/easytags.vim` in another Vim buffer.
  34
+
  35
+ * Convert `easytags#update_cmd()` to a function that can be executed on a
  36
+   list of files and will only execute Exuberant Ctags once to do so, then
  37
+   change `:UpdateTags` to accept an optional file glob, e.g. `:UpdateTags
  38
+   /usr/include/lua5.1/*.h` and call `easytags#update_cmd()` on the matching
  39
+   files.
  40
+
  41
+vim: ai nofen
32  autoload.vim
... ...
@@ -1,8 +1,10 @@
1 1
 " Vim script
2 2
 " Maintainer: Peter Odding <peter@peterodding.com>
3  
-" Last Change: June 14, 2010
  3
+" Last Change: June 15, 2010
4 4
 " URL: http://peterodding.com/code/vim/easytags
5 5
 
  6
+let s:script = expand('<sfile>:p:~')
  7
+
6 8
 " Public interface through (automatic) commands. {{{1
7 9
 
8 10
 function! easytags#autoload() " {{{2
@@ -28,7 +30,7 @@ function! easytags#autoload() " {{{2
28 30
       let b:easytags_last_highlighted = localtime()
29 31
     endif
30 32
   catch
31  
-    call xolox#warning("easytags.vim: %s (at %s)", v:exception, v:throwpoint)
  33
+    call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
32 34
   endtry
33 35
 endfunction
34 36
 
@@ -59,7 +61,8 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
59 61
           call filter(entries, join(filters, ' && '))
60 62
           if len(entries) != num_entries
61 63
             if !easytags#write_tagsfile(tagsfile, header, entries)
62  
-              throw "Failed to write filtered tags file!"
  64
+              let msg = "Failed to write filtered tags file %s!"
  65
+              throw printf(msg, fnamemodify(tagsfile, ':~'))
63 66
             endif
64 67
           endif
65 68
         endif
@@ -69,16 +72,18 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
69 72
         call add(command, shellescape(filename))
70 73
         let listing = system(join(command))
71 74
         if v:shell_error
72  
-          throw "Failed to update tags file! (Ctags output: `" . listing . "')"
  75
+          let msg = "Failed to update tags file %s: %s!"
  76
+          throw printf(msg, fnamemodify(tagsfile, ':~'), strtrans(v:exception))
73 77
         endif
74 78
         call easytags#add_tagged_file(filename)
75 79
       endif
76  
-      call xolox#timer#stop(start, "easytags.vim: Updated tags in %s second(s)")
  80
+      let msg = "%s: Updated tags for %s in %s."
  81
+      call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
77 82
       return 1
78 83
     endif
79 84
     return 0
80 85
   catch
81  
-    call xolox#warning("easytags.vim: %s (at %s)", v:exception, v:throwpoint)
  86
+    call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
82 87
   endtry
83 88
 endfunction
84 89
 
@@ -108,10 +113,11 @@ function! easytags#highlight_cmd() " {{{2
108 113
         endif
109 114
       endfor
110 115
       redraw
111  
-      call xolox#timer#stop(start, "easytags.vim: Highlighted tags in %s second(s)")
  116
+      let msg = "%s: Highlighted tags in %s in %s."
  117
+      call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
112 118
     endif
113 119
   catch
114  
-    call xolox#warning("easytags.vim: %s (at %s)", v:exception, v:throwpoint)
  120
+    call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)
115 121
   endtry
116 122
 endfunction
117 123
 
@@ -122,11 +128,13 @@ function! easytags#supported_filetypes() " {{{2
122 128
     let start = xolox#timer#start()
123 129
     let listing = system(g:easytags_cmd . ' --list-languages')
124 130
     if v:shell_error
125  
-      throw "Failed to get Exuberant Ctags language mappings!"
  131
+      let msg = "Failed to get supported languages! (output: %s)"
  132
+      throw printf(msg, strtrans(listing))
126 133
     endif
127 134
     let s:supported_filetypes = split(listing, '\n')
128 135
     call map(s:supported_filetypes, 'easytags#to_vim_ft(v:val)')
129  
-    call xolox#timer#stop(start, "easytags.vim: Parsed language mappings in %s second(s)")
  136
+    let msg = "%s: Retrieved supported languages in %s."
  137
+    call xolox#timer#stop(msg, s:script, start)
130 138
   endif
131 139
   return s:supported_filetypes
132 140
 endfunction
@@ -173,8 +181,8 @@ endfunction
173 181
 function! easytags#get_tagsfile() " {{{2
174 182
   let tagsfile = expand(g:easytags_file)
175 183
   if filereadable(tagsfile) && filewritable(tagsfile) != 1
176  
-    let message = "The tags file isn't writable! (%s)"
177  
-    throw printf(message, tagsfile)
  184
+    let message = "The tags file %s isn't writable!"
  185
+    throw printf(message, fnamemodify(tagsfile, ':~'))
178 186
   endif
179 187
   return tagsfile
180 188
 endfunction
75  easytags.vim
... ...
@@ -1,10 +1,10 @@
1 1
 " Vim plug-in
2 2
 " Maintainer: Peter Odding <peter@peterodding.com>
3  
-" Last Change: June 13, 2010
  3
+" Last Change: June 15, 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.9
  7
+" Version: 1.9.3
8 8
 
9 9
 " Support for automatic update using the GLVS plug-in.
10 10
 " GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip
@@ -40,38 +40,62 @@ if !exists('g:easytags_ignored_filetypes')
40 40
   let g:easytags_ignored_filetypes = '^tex$'
41 41
 endif
42 42
 
43  
-" Before sourcing the rest of the plug-in first check that the location of the
44  
-" "Exuberant Ctags" program has been configured or that the program exists in
45  
-" one of its default locations.
46  
-
47  
-if exists('g:easytags_cmd') && executable(g:easytags_cmd)
48  
-  let s:ctags_installed = 1
49  
-else
  43
+function! s:InitEasyTags(version)
  44
+  " Check that the location of Exuberant Ctags has been configured or that the
  45
+  " correct version of the program exists in one of its default locations.
  46
+  if exists('g:easytags_cmd') && s:CheckCtags(g:easytags_cmd, a:version)
  47
+    return 1
  48
+  endif
50 49
   " On Ubuntu Linux, Exuberant Ctags is installed as `ctags'. On Debian Linux,
51 50
   " Exuberant Ctags is installed as `exuberant-ctags'. On Free-BSD, Exuberant
52 51
   " Ctags is installed as `exctags'. Finally there is `ctags.exe' on Windows.
53  
-  for s:command in ['ctags', 'exuberant-ctags', 'esctags', 'ctags.exe']
54  
-    if executable(s:command)
55  
-      let g:easytags_cmd = s:command
56  
-      let s:ctags_installed = 1
57  
-      break
  52
+  for name in ['ctags', 'exuberant-ctags', 'esctags']
  53
+    if s:CheckCtags(name, a:version)
  54
+      let g:easytags_cmd = name
  55
+      return 1
58 56
     endif
59 57
   endfor
60  
-  unlet s:command
61  
-endif
62  
-
63  
-if !exists('s:ctags_installed')
64  
-  echomsg "easytags.vim: Exuberant Ctags unavailable! Plug-in not loaded."
65  
-  if executable('apt-get')
66  
-    echomsg "On Ubuntu & Debian Linux, you can install Exuberant Ctags"
67  
-    echomsg "by installing the package named `exuberant-ctags':"
68  
-    echomsg "  sudo apt-get install exuberant-ctags"
  58
+endfunction
  59
+
  60
+function! s:CheckCtags(name, version)
  61
+  " Not every executable out there named `ctags' is in fact Exuberant Ctags.
  62
+  " This function makes sure it is because the easytags plug-in requires the
  63
+  " --list-languages option.
  64
+  if executable(a:name)
  65
+    let listing = system(a:name . ' --version')
  66
+    let pattern = 'Exuberant Ctags \zs\d\+\(\.\d\+\)*'
  67
+    let g:easytags_ctags_version = matchstr(listing, pattern)
  68
+    return s:VersionToNumber(g:easytags_ctags_version) >= a:version
  69
+  endif
  70
+endfunction
  71
+
  72
+function! s:VersionToNumber(s)
  73
+  let values = split(a:s, '\.')
  74
+  if len(values) == 1
  75
+    return values[0] * 10
  76
+  elseif len(values) >= 2
  77
+    return values[0] * 10 + values[1][0]
  78
+  endif
  79
+endfunction
  80
+
  81
+if !s:InitEasyTags(55)
  82
+  if !exists('g:easytags_ctags_version') || empty(g:easytags_ctags_version)
  83
+    let msg = "easytags.vim: Plug-in not loaded because Exuberant Ctags isn't installed!"
  84
+    if executable('apt-get')
  85
+      let msg ,= " On Ubuntu & Debian you can install Exuberant Ctags by"
  86
+      let msg .= " installing the package named `exuberant-ctags':"
  87
+      let msg .= " sudo apt-get install exuberant-ctags"
  88
+    else
  89
+      let msg .= " Please download & install Exuberant Ctags from http://ctags.sf.net"
  90
+    endif
  91
+    echomsg msg
69 92
   else
70  
-    echomsg "Please download & install Exuberant Ctags from http://ctags.sf.net"
  93
+    let msg = "easytags.vim: Plug-in not loaded because Exuberant Ctags 5.5"
  94
+    let msg .= " or newer is required while you have version %s installed!"
  95
+    echomsg printf(msg, g:easytags_ctags_version)
71 96
   endif
72 97
   finish
73 98
 endif
74  
-unlet s:ctags_installed
75 99
 
76 100
 " Let Vim know about the global tags file created by this plug-in.
77 101
 
@@ -106,6 +130,7 @@ augroup PluginEasyTags
106 130
   endif
107 131
   if g:easytags_on_cursorhold
108 132
     autocmd CursorHold,CursorHoldI * call easytags#autoload()
  133
+    autocmd BufReadPost * unlet! b:easytags_last_highlighted
109 134
   endif
110 135
   autocmd User PublishPre HighlightTags
111 136
 augroup END

0 notes on commit 5cb775c

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