Skip to content

Commit

Permalink
Workaround low 'updatetime' intelligently
Browse files Browse the repository at this point in the history
This should hopefully resolve the following issues and pull
requests: #31, #33, #42. I tried several of their suggestions
in Vim 7.2 & 7.3 but it didn't work as it should IMHO.

All of the issues and pull requests seem to imply that CursorHold
events fire continuously when you set a low enough updatetime, but
in my testing on Vim 7.2 and 7.3 this is not true. The event fires
once, then Vim waits for user input before any new events fire.
I'm not sure exactly what user input is required; moving the
text cursor is not always enough but mode switching is.

So what happens (in my testing) with all of the proposed solutions is
that you stop typing for 'updatetime' milliseconds, the event fires, the
plug-in simply increments or decrements a counter and then Vim just sits
there doing absolutely nothing expect blinking the cursor...

What I'm now trying instead is to remember the last time the plug-in was
executed (the result of localtime()) and not acting on the CursorHold
event until the following condition holds true:

  localtime() > (last_automatic_run + (easytags_updatetime_min/1000))

I hope this provides a reliable solution. In any case it should be
better than the previous annoying behavior :-)
  • Loading branch information
xolox committed Apr 19, 2013
1 parent ebe2ba9 commit 43ae6d7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 52 deletions.
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -125,11 +125,9 @@ Note: Like the `g:easytags_always_enabled` option, if you change this option it

### The `g:easytags_updatetime_min` option

Vim has a setting which influences how often the plug-in is automatically executed. When this setting is too low, the plug-in can break. For this reason the plug-in warns you when ['updatetime'][updatetime] is lower than 4000 milliseconds. If you really want the plug-in to be executed more than once every 4 seconds (without a warning) you can lower the minimum acceptable updatetime by setting this option (number of milliseconds).
Vim has a setting which influences how often the plug-in is automatically executed. When this setting is too low, the plug-in can break. For this reason the plug-in compensates by keeping track of when it was last executed. You'll get one warning when the plug-in first notices the low value, after that it will shut up. The default value of this option is 4000 milliseconds (4 seconds).

### The `g:easytags_updatetime_autodisable` option

Other plug-ins may lower the ['updatetime'][updatetime] value in certain contexts, e.g. insert mode in the case of the [neocomplcache][neocomplcache] plug-in. By setting this option to 1 (true) you can configure the easytags plug-in so that it doesn't give warnings about the updatetime option but instead skip updating and highlighting while the updatetime is set too low. When the updatetime is restored to a reasonable value the plug-in resumes.
If you really want the plug-in to be executed more than once every 4 seconds you can lower the minimum acceptable updatetime by setting this option (as the number of milliseconds) however note that subsecond granularity is not supported.

### The `g:easytags_auto_update` option

Expand Down
29 changes: 18 additions & 11 deletions autoload/xolox/easytags.vim
Expand Up @@ -3,7 +3,7 @@
" Last Change: April 19, 2013
" URL: http://peterodding.com/code/vim/easytags/

let g:xolox#easytags#version = '3.0'
let g:xolox#easytags#version = '3.1'

" Public interface through (automatic) commands. {{{1

Expand Down Expand Up @@ -33,25 +33,32 @@ function! xolox#easytags#register(global) " {{{2
endif
endif
endfunction

" The localtime() when the CursorHold event last fired.
let s:last_automatic_run = 0

function! xolox#easytags#autoload(event) " {{{2
try
if a:event =~? 'cursorhold'
" Only for the CursorHold automatic command: check for unreasonable
" &updatetime values. The minimum value 4000 is kind of arbitrary
" (apart from being Vim's default) so I made it configurable:
" (apart from being Vim's default) so I made it configurable.
let updatetime_min = xolox#misc#option#get('easytags_updatetime_min', 4000)
if &updatetime < updatetime_min
" Other plug-ins may lower &updatetime in certain contexts, e.g.
" insert mode in the case of the neocomplcache plug-in. The following
" option (disabled by default unless neocomplcache is loaded) silences
" the warning and makes the easytags plug-in skip the update and
" highlight. When the &updatetime is restored to a reasonable value
" the plug-in resumes.
if xolox#misc#option#get('easytags_updatetime_autodisable', exists('g:loaded_neocomplcache'))
return
if s:last_automatic_run == 0
" Warn once about the low &updatetime value.
call xolox#misc#msg#warn("easytags.vim %s: The 'updatetime' option has an unreasonably low value, so I'll start compensating (see the easytags_updatetime_min option).", g:xolox#easytags#version)
let s:last_automatic_run = localtime()
else
call xolox#misc#msg#warn("easytags.vim %s: I'm being executed every %i milliseconds! Please :set updatetime=%i. To find where 'updatetime' was changed execute ':verb set ut?'", g:xolox#easytags#version, &updatetime, updatetime_min)
let next_scheduled_run = s:last_automatic_run + max([1, updatetime_min / 1000])
if localtime() < next_scheduled_run
" It's not our time yet; wait for the next event.
call xolox#misc#msg#debug("easytags.vim %s: Skipping this beat of 'updatetime' to compensate for low value.", g:xolox#easytags#version)
return
else
call xolox#misc#msg#debug("easytags.vim %s: This is our beat of 'updatetime'!", g:xolox#easytags#version)
let s:last_automatic_run = localtime()
endif
endif
endif
endif
Expand Down
67 changes: 30 additions & 37 deletions doc/easytags.txt
Expand Up @@ -19,14 +19,13 @@ Contents ~
6. The |g:easytags_always_enabled| option
7. The |g:easytags_on_cursorhold| option
8. The |g:easytags_updatetime_min| option
9. The |g:easytags_updatetime_autodisable| option
10. The |g:easytags_auto_update| option
11. The |g:easytags_auto_highlight| option
12. The |g:easytags_autorecurse| option
13. The |g:easytags_include_members| option
14. The |g:easytags_resolve_links| option
15. The |g:easytags_suppress_ctags_warning| option
16. The |g:easytags_ignored_syntax_groups| option
9. The |g:easytags_auto_update| option
10. The |g:easytags_auto_highlight| option
11. The |g:easytags_autorecurse| option
12. The |g:easytags_include_members| option
13. The |g:easytags_resolve_links| option
14. The |g:easytags_suppress_ctags_warning| option
15. The |g:easytags_ignored_syntax_groups| option
5. Faster syntax highlighting using Python |easytags-faster-syntax-highlighting-using-python|
1. The |g:easytags_python_enabled| option
2. The |g:easytags_python_script| option
Expand Down Expand Up @@ -293,20 +292,15 @@ The *g:easytags_updatetime_min* option

Vim has a setting which influences how often the plug-in is automatically
executed. When this setting is too low, the plug-in can break. For this reason
the plug-in warns you when |'updatetime'| is lower than 4000 milliseconds. If
you really want the plug-in to be executed more than once every 4 seconds
(without a warning) you can lower the minimum acceptable updatetime by setting
this option (number of milliseconds).
the plug-in compensates by keeping track of when it was last executed. You'll
get one warning when the plug-in first notices the low value, after that it
will shut up. The default value of this option is 4000 milliseconds (4
seconds).

-------------------------------------------------------------------------------
The *g:easytags_updatetime_autodisable* option

Other plug-ins may lower the |'updatetime'| value in certain contexts, e.g.
insert mode in the case of the neocomplcache [10] plug-in. By setting this
option to 1 (true) you can configure the easytags plug-in so that it doesn't
give warnings about the updatetime option but instead skip updating and
highlighting while the updatetime is set too low. When the updatetime is
restored to a reasonable value the plug-in resumes.
If you really want the plug-in to be executed more than once every 4 seconds
you can lower the minimum acceptable updatetime by setting this option (as the
number of milliseconds) however note that subsecond granularity is not
supported.

-------------------------------------------------------------------------------
The *g:easytags_auto_update* option
Expand Down Expand Up @@ -374,14 +368,14 @@ your vimrc script, a file type plug-in, etc.):
-------------------------------------------------------------------------------
The *g:easytags_resolve_links* option

UNIX has symbolic links [11] and hard links [12], both of which conflict with
UNIX has symbolic links [10] and hard links [11], both of which conflict with
the concept of having one unique location for every identifier. With regards
to hard links there's not much anyone can do, but because I use symbolic links
quite a lot I've added this option. It's disabled by default since it has a
small performance impact and might not do what unknowing users expect it to:
When you enable this option the plug-in will resolve symbolic links in
pathnames, which means your tags file will only contain entries with canonical
pathnames [13]. To enable this option (which I strongly suggest doing when you
pathnames [12]. To enable this option (which I strongly suggest doing when you
run UNIX and use symbolic links) execute the following Vim command:
>
:let g:easytags_resolve_links = 1
Expand Down Expand Up @@ -465,11 +459,11 @@ modes (except of course for the 'Tag' suffix).
Passing custom command line arguments to Exuberant Ctags ~

You may want to run Exuberant Ctags with specific command line options, for
example the code_complete [14] plug-in requires the signature field to be
example the code_complete [13] plug-in requires the signature field to be
present. To do this you can create a configuration file for Exuberant Ctags,
e.g. '~/.ctags' on UNIX or '%USERPROFILE%\ctags.cnf' on Windows. The file
should contain one command line option per line. See the Exuberant Ctags
manual [15] for details.
manual [14] for details.

===============================================================================
*easytags-troubleshooting*
Expand Down Expand Up @@ -569,7 +563,7 @@ project directories.
-------------------------------------------------------------------------------
The plug-in doesn't seem to work in Cygwin ~

If you want to use the plug-in with Vim under Cygwin [16], you need to have
If you want to use the plug-in with Vim under Cygwin [15], you need to have
the Cygwin version of Ctags installed instead of the Windows version (thanks
to Alex Zuroff for reporting this!).

Expand All @@ -580,13 +574,13 @@ Contact ~
If you have questions, bug reports, suggestions, etc. the author can be
contacted at peter@peterodding.com. The latest version is available at
http://peterodding.com/code/vim/easytags/ and http://github.com/xolox/vim-easytags.
If you like this plug-in please vote for it on Vim Online [17].
If you like this plug-in please vote for it on Vim Online [16].

===============================================================================
*easytags-license*
License ~

This software is licensed under the MIT license [18]. Copyright 2011 Peter
This software is licensed under the MIT license [17]. Copyright 2011 Peter
Odding <peter@peterodding.com>.

===============================================================================
Expand All @@ -602,14 +596,13 @@ References ~
[7] http://peterodding.com/code/vim/shell/
[8] http://en.wikipedia.org/wiki/Dynamic-link_library
[9] https://npmjs.org/package/jsctags
[10] http://www.vim.org/scripts/script.php?script_id=2620
[11] http://en.wikipedia.org/wiki/Symbolic_link
[12] http://en.wikipedia.org/wiki/Hard_link
[13] http://en.wikipedia.org/wiki/Canonicalization
[14] http://www.vim.org/scripts/script.php?script_id=1764
[15] http://ctags.sourceforge.net/ctags.html#FILES
[16] http://en.wikipedia.org/wiki/Cygwin
[17] http://www.vim.org/scripts/script.php?script_id=3114
[18] http://en.wikipedia.org/wiki/MIT_License
[10] http://en.wikipedia.org/wiki/Symbolic_link
[11] http://en.wikipedia.org/wiki/Hard_link
[12] http://en.wikipedia.org/wiki/Canonicalization
[13] http://www.vim.org/scripts/script.php?script_id=1764
[14] http://ctags.sourceforge.net/ctags.html#FILES
[15] http://en.wikipedia.org/wiki/Cygwin
[16] http://www.vim.org/scripts/script.php?script_id=3114
[17] http://en.wikipedia.org/wiki/MIT_License

vim: ft=help

0 comments on commit 43ae6d7

Please sign in to comment.