From 92cd87df83b24e1c45b946bc9eadbe4482de12ba Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sat, 10 Jul 2010 18:21:25 +0200 Subject: Handle patterns that are too large for Vim to evaluate --- README.md | 24 ++++++++++++++++++++++++ autoload.vim | 12 +++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c92b78c..7e90292 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,28 @@ Every time the plug-in executes it will time how long the execution takes and add the results to Vim's message history, which you can view by executing the [:messages][messages] command. +### Failed to highlight tags because pattern is too big! + +If the `easytags.vim` plug-in fails to highlight your tags and the error +message mentions that the pattern is too big, your tags file has grown too +large for Vim to be able to highlight all tagged identifiers! I've had this +happen to me with 50 KB patterns because I added most of the headers in +`/usr/include/` to my tags file. Internally Vim raises the error [E339: Pattern +too long] [E339] and unfortunately the only way to avoid this problem once it +occurs is to reduce the number of tagged identifiers... + +In my case the solution was to move most of the tags from `/usr/include/` over +to project specific tags files which are automatically loaded by Vim when I +edit files in different projects because I've set the ['tags' option] +[tags_option] as follows: + + :set tags=./.tags;,~/.vimtags + +Once you've executed the above command, Vim will automatically look for a file +named `.tags` in the directory of the current file. Because of the `;` Vim also +recurses upwards so that you can nest files arbitrarily deep under your project +directories. + ## Contact 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]. [ctags]: http://en.wikipedia.org/wiki/Ctags [ctags_support]: http://ctags.sourceforge.net/languages.html [cursorhold]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#CursorHold +[E339]: http://vimdoc.sourceforge.net/htmldoc/message.html#E339 [exuberant_ctags]: http://ctags.sourceforge.net/ [hardlinks]: http://en.wikipedia.org/wiki/Hard_link [ide]: http://en.wikipedia.org/wiki/Integrated_development_environment @@ -195,6 +218,7 @@ This software is licensed under the [MIT license] [mit_license]. [shell]: http://peterodding.com/code/vim/shell/ [symlinks]: http://en.wikipedia.org/wiki/Symbolic_link [system]: http://vimdoc.sourceforge.net/htmldoc/eval.html#system() +[tags_option]: http://vimdoc.sourceforge.net/htmldoc/options.html#'tags' [vim]: http://www.vim.org/ [vim_scripts_entry]: http://www.vim.org/scripts/script.php?script_id=3114 [vim_support]: http://ftp.vim.org/vim/runtime/syntax/ diff --git a/autoload.vim b/autoload.vim index 025cc2c..4722202 100644 --- a/autoload.vim +++ b/autoload.vim @@ -1,6 +1,6 @@ " Vim script " Maintainer: Peter Odding -" Last Change: June 16, 2010 +" Last Change: July 10, 2010 " URL: http://peterodding.com/code/vim/easytags let s:script = expand(':p:~') @@ -114,8 +114,14 @@ function! easytags#highlight_cmd() " {{{2 if matches != [] call map(matches, 'xolox#escape#pattern(get(v:val, "name"))') let pattern = tagkind.pattern_prefix . '\%(' . join(xolox#unique(matches), '\|') . '\)' . tagkind.pattern_suffix - let command = 'syntax match %s /%s/ containedin=ALLBUT,.*String.*,.*Comment.*' - execute printf(command, hlgroup_tagged, escape(pattern, '/')) + let template = 'syntax match %s /%s/ containedin=ALLBUT,.*String.*,.*Comment.*' + let command = printf(template, hlgroup_tagged, escape(pattern, '/')) + try + execute command + catch /^Vim\%((\a\+)\)\=:E339/ + let msg = "easytags.vim: Failed to highlight %i %s tags because pattern is too big! (%i KB)" + call xolox#warning(printf(msg, len(matches), tagkind.hlgroup, len(pattern) / 1024)) + endtry endif endfor redraw -- cgit v1.2.3