From a2e10e13868d7ffe383b397c3b291cce88a688ad Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Tue, 25 Jun 2013 21:09:52 -0700 Subject: [PATCH] improve setting updatetime --- plugin/wakatime.vim | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugin/wakatime.vim b/plugin/wakatime.vim index d5e932c..f13915e 100644 --- a/plugin/wakatime.vim +++ b/plugin/wakatime.vim @@ -5,6 +5,7 @@ " Version: 0.1.2 " ============================================================================ + " Init {{{ " Check Vim version @@ -46,9 +47,9 @@ set cpo&vim let s:plugin_directory = expand(":p:h") -" Set a nice updatetime value, if updatetime is too short -if &updatetime < 60 * 1000 * 2 - let &updatetime = 60 * 1000 * 15 " 15 minutes +" Set default updatetime +if !exists("g:wakatime_updatetime") + let g:wakatime_updatetime = 15 " 15 minutes endif python << ENDPYTHON @@ -62,6 +63,7 @@ ENDPYTHON " }}} + " Function Definitions {{{ function! s:initVariable(var, value) @@ -72,6 +74,12 @@ function! s:initVariable(var, value) return 0 endfunction +function! s:setUpdateTime() + if &updatetime < 60 * 1000 * 2 + let &updatetime = g:wakatime_updatetime * 60 * 1000 + endif +endfunction + function! s:GetCurrentFile() return expand("%:p") endfunction @@ -94,6 +102,7 @@ endfunction " }}} + " Event Handlers {{{ function! s:bufenter() @@ -132,6 +141,10 @@ function! s:cursormoved() python vim.command("let away_end=%f" % time.time()) let away_unit = "minutes" let away_duration = (away_end - s:away_start) / 60 + if away_duration < 2 + call s:setUpdateTime() + return + endif if away_duration > 59 let away_duration = away_duration / 60 let away_unit = "hours" @@ -153,6 +166,10 @@ endfunction " }}} + +call s:setUpdateTime() + + " Autocommand Events {{{ augroup Wakatime @@ -167,5 +184,6 @@ augroup END " }}} + " Restore cpoptions let &cpo = s:old_cpo