Skip to content
This repository
Browse code

Handle patterns that are too large for Vim to evaluate

  • Loading branch information...
commit 92cd87df83b24e1c45b946bc9eadbe4482de12ba 1 parent 726c08b
Peter Odding authored July 10, 2010

Showing 2 changed files with 33 additions and 3 deletions. Show diff stats Hide diff stats

  1. 24  README.md
  2. 12  autoload.vim
24  README.md
Source Rendered
@@ -166,6 +166,28 @@ Every time the plug-in executes it will time how long the execution takes and
166 166
 add the results to Vim's message history, which you can view by executing the
167 167
 [:messages][messages] command.
168 168
 
  169
+### Failed to highlight tags because pattern is too big!
  170
+
  171
+If the `easytags.vim` plug-in fails to highlight your tags and the error
  172
+message mentions that the pattern is too big, your tags file has grown too
  173
+large for Vim to be able to highlight all tagged identifiers! I've had this
  174
+happen to me with 50 KB patterns because I added most of the headers in
  175
+`/usr/include/` to my tags file. Internally Vim raises the error [E339: Pattern
  176
+too long] [E339] and unfortunately the only way to avoid this problem once it
  177
+occurs is to reduce the number of tagged identifiers...
  178
+
  179
+In my case the solution was to move most of the tags from `/usr/include/` over
  180
+to project specific tags files which are automatically loaded by Vim when I
  181
+edit files in different projects because I've set the ['tags' option]
  182
+[tags_option] as follows:
  183
+
  184
+    :set tags=./.tags;,~/.vimtags
  185
+
  186
+Once you've executed the above command, Vim will automatically look for a file
  187
+named `.tags` in the directory of the current file. Because of the `;` Vim also
  188
+recurses upwards so that you can nest files arbitrarily deep under your project
  189
+directories.
  190
+
169 191
 ## Contact
170 192
 
171 193
 If you have questions, bug reports, suggestions, etc. the author can be
@@ -185,6 +207,7 @@ This software is licensed under the [MIT license] [mit_license].
185 207
 [ctags]: http://en.wikipedia.org/wiki/Ctags
186 208
 [ctags_support]: http://ctags.sourceforge.net/languages.html
187 209
 [cursorhold]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#CursorHold
  210
+[E339]: http://vimdoc.sourceforge.net/htmldoc/message.html#E339
188 211
 [exuberant_ctags]: http://ctags.sourceforge.net/
189 212
 [hardlinks]: http://en.wikipedia.org/wiki/Hard_link
190 213
 [ide]: http://en.wikipedia.org/wiki/Integrated_development_environment
@@ -195,6 +218,7 @@ This software is licensed under the [MIT license] [mit_license].
195 218
 [shell]: http://peterodding.com/code/vim/shell/
196 219
 [symlinks]: http://en.wikipedia.org/wiki/Symbolic_link
197 220
 [system]: http://vimdoc.sourceforge.net/htmldoc/eval.html#system()
  221
+[tags_option]: http://vimdoc.sourceforge.net/htmldoc/options.html#'tags'
198 222
 [vim]: http://www.vim.org/
199 223
 [vim_scripts_entry]: http://www.vim.org/scripts/script.php?script_id=3114
200 224
 [vim_support]: http://ftp.vim.org/vim/runtime/syntax/
12  autoload.vim
... ...
@@ -1,6 +1,6 @@
1 1
 " Vim script
2 2
 " Maintainer: Peter Odding <peter@peterodding.com>
3  
-" Last Change: June 16, 2010
  3
+" Last Change: July 10, 2010
4 4
 " URL: http://peterodding.com/code/vim/easytags
5 5
 
6 6
 let s:script = expand('<sfile>:p:~')
@@ -114,8 +114,14 @@ function! easytags#highlight_cmd() " {{{2
114 114
         if matches != []
115 115
           call map(matches, 'xolox#escape#pattern(get(v:val, "name"))')
116 116
           let pattern = tagkind.pattern_prefix . '\%(' . join(xolox#unique(matches), '\|') . '\)' . tagkind.pattern_suffix
117  
-          let command = 'syntax match %s /%s/ containedin=ALLBUT,.*String.*,.*Comment.*'
118  
-          execute printf(command, hlgroup_tagged, escape(pattern, '/'))
  117
+          let template = 'syntax match %s /%s/ containedin=ALLBUT,.*String.*,.*Comment.*'
  118
+          let command = printf(template, hlgroup_tagged, escape(pattern, '/'))
  119
+          try
  120
+            execute command
  121
+          catch /^Vim\%((\a\+)\)\=:E339/
  122
+            let msg = "easytags.vim: Failed to highlight %i %s tags because pattern is too big! (%i KB)"
  123
+            call xolox#warning(printf(msg, len(matches), tagkind.hlgroup, len(pattern) / 1024))
  124
+          endtry
119 125
         endif
120 126
       endfor
121 127
       redraw

0 notes on commit 92cd87d

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