Skip to content

Commit 43ae6d7

Browse files
committed
Workaround low 'updatetime' intelligently
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 :-)
1 parent ebe2ba9 commit 43ae6d7

File tree

3 files changed

+50
-52
lines changed

3 files changed

+50
-52
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ Note: Like the `g:easytags_always_enabled` option, if you change this option it
125125

126126
### The `g:easytags_updatetime_min` option
127127

128-
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).
128+
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).
129129

130-
### The `g:easytags_updatetime_autodisable` option
131-
132-
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.
130+
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.
133131

134132
### The `g:easytags_auto_update` option
135133

autoload/xolox/easytags.vim

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Last Change: April 19, 2013
44
" URL: http://peterodding.com/code/vim/easytags/
55

6-
let g:xolox#easytags#version = '3.0'
6+
let g:xolox#easytags#version = '3.1'
77

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

@@ -33,25 +33,32 @@ function! xolox#easytags#register(global) " {{{2
3333
endif
3434
endif
3535
endfunction
36+
37+
" The localtime() when the CursorHold event last fired.
38+
let s:last_automatic_run = 0
3639

3740
function! xolox#easytags#autoload(event) " {{{2
3841
try
3942
if a:event =~? 'cursorhold'
4043
" Only for the CursorHold automatic command: check for unreasonable
4144
" &updatetime values. The minimum value 4000 is kind of arbitrary
42-
" (apart from being Vim's default) so I made it configurable:
45+
" (apart from being Vim's default) so I made it configurable.
4346
let updatetime_min = xolox#misc#option#get('easytags_updatetime_min', 4000)
4447
if &updatetime < updatetime_min
45-
" Other plug-ins may lower &updatetime in certain contexts, e.g.
46-
" insert mode in the case of the neocomplcache plug-in. The following
47-
" option (disabled by default unless neocomplcache is loaded) silences
48-
" the warning and makes the easytags plug-in skip the update and
49-
" highlight. When the &updatetime is restored to a reasonable value
50-
" the plug-in resumes.
51-
if xolox#misc#option#get('easytags_updatetime_autodisable', exists('g:loaded_neocomplcache'))
52-
return
48+
if s:last_automatic_run == 0
49+
" Warn once about the low &updatetime value.
50+
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)
51+
let s:last_automatic_run = localtime()
5352
else
54-
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)
53+
let next_scheduled_run = s:last_automatic_run + max([1, updatetime_min / 1000])
54+
if localtime() < next_scheduled_run
55+
" It's not our time yet; wait for the next event.
56+
call xolox#misc#msg#debug("easytags.vim %s: Skipping this beat of 'updatetime' to compensate for low value.", g:xolox#easytags#version)
57+
return
58+
else
59+
call xolox#misc#msg#debug("easytags.vim %s: This is our beat of 'updatetime'!", g:xolox#easytags#version)
60+
let s:last_automatic_run = localtime()
61+
endif
5562
endif
5663
endif
5764
endif

doc/easytags.txt

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ Contents ~
1919
6. The |g:easytags_always_enabled| option
2020
7. The |g:easytags_on_cursorhold| option
2121
8. The |g:easytags_updatetime_min| option
22-
9. The |g:easytags_updatetime_autodisable| option
23-
10. The |g:easytags_auto_update| option
24-
11. The |g:easytags_auto_highlight| option
25-
12. The |g:easytags_autorecurse| option
26-
13. The |g:easytags_include_members| option
27-
14. The |g:easytags_resolve_links| option
28-
15. The |g:easytags_suppress_ctags_warning| option
29-
16. The |g:easytags_ignored_syntax_groups| option
22+
9. The |g:easytags_auto_update| option
23+
10. The |g:easytags_auto_highlight| option
24+
11. The |g:easytags_autorecurse| option
25+
12. The |g:easytags_include_members| option
26+
13. The |g:easytags_resolve_links| option
27+
14. The |g:easytags_suppress_ctags_warning| option
28+
15. The |g:easytags_ignored_syntax_groups| option
3029
5. Faster syntax highlighting using Python |easytags-faster-syntax-highlighting-using-python|
3130
1. The |g:easytags_python_enabled| option
3231
2. The |g:easytags_python_script| option
@@ -293,20 +292,15 @@ The *g:easytags_updatetime_min* option
293292

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

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

311305
-------------------------------------------------------------------------------
312306
The *g:easytags_auto_update* option
@@ -374,14 +368,14 @@ your vimrc script, a file type plug-in, etc.):
374368
-------------------------------------------------------------------------------
375369
The *g:easytags_resolve_links* option
376370

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

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

474468
===============================================================================
475469
*easytags-troubleshooting*
@@ -569,7 +563,7 @@ project directories.
569563
-------------------------------------------------------------------------------
570564
The plug-in doesn't seem to work in Cygwin ~
571565

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

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

585579
===============================================================================
586580
*easytags-license*
587581
License ~
588582

589-
This software is licensed under the MIT license [18]. Copyright 2011 Peter
583+
This software is licensed under the MIT license [17]. Copyright 2011 Peter
590584
Odding <peter@peterodding.com>.
591585

592586
===============================================================================
@@ -602,14 +596,13 @@ References ~
602596
[7] http://peterodding.com/code/vim/shell/
603597
[8] http://en.wikipedia.org/wiki/Dynamic-link_library
604598
[9] https://npmjs.org/package/jsctags
605-
[10] http://www.vim.org/scripts/script.php?script_id=2620
606-
[11] http://en.wikipedia.org/wiki/Symbolic_link
607-
[12] http://en.wikipedia.org/wiki/Hard_link
608-
[13] http://en.wikipedia.org/wiki/Canonicalization
609-
[14] http://www.vim.org/scripts/script.php?script_id=1764
610-
[15] http://ctags.sourceforge.net/ctags.html#FILES
611-
[16] http://en.wikipedia.org/wiki/Cygwin
612-
[17] http://www.vim.org/scripts/script.php?script_id=3114
613-
[18] http://en.wikipedia.org/wiki/MIT_License
599+
[10] http://en.wikipedia.org/wiki/Symbolic_link
600+
[11] http://en.wikipedia.org/wiki/Hard_link
601+
[12] http://en.wikipedia.org/wiki/Canonicalization
602+
[13] http://www.vim.org/scripts/script.php?script_id=1764
603+
[14] http://ctags.sourceforge.net/ctags.html#FILES
604+
[15] http://en.wikipedia.org/wiki/Cygwin
605+
[16] http://www.vim.org/scripts/script.php?script_id=3114
606+
[17] http://en.wikipedia.org/wiki/MIT_License
614607

615608
vim: ft=help

0 commit comments

Comments
 (0)