aboutsummaryrefslogtreecommitdiffstats
path: root/autoload
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2013-04-19 02:58:51 +0200
committerPeter Odding <peter@peterodding.com>2013-04-19 02:58:51 +0200
commit43ae6d7b7195517a9b91dc19464c2ff9112ccb55 (patch)
tree65f07695c8b5bd4d56b24bd6e03523c28eee2524 /autoload
parentebe2ba9aedafeac5ffc19b52e9f6cf0d994e5726 (diff)
downloadvim-easytags-43ae6d7b7195517a9b91dc19464c2ff9112ccb55.tar.gz
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 :-)
Diffstat (limited to 'autoload')
-rw-r--r--autoload/xolox/easytags.vim29
1 files changed, 18 insertions, 11 deletions
diff --git a/autoload/xolox/easytags.vim b/autoload/xolox/easytags.vim
index 2197be6..0380956 100644
--- a/autoload/xolox/easytags.vim
+++ b/autoload/xolox/easytags.vim
@@ -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
@@ -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