forked from luna/vim-rana-local
remove away prompt
This commit is contained in:
parent
3d17c2dee7
commit
284d7247ee
1 changed files with 9 additions and 90 deletions
|
@ -31,16 +31,6 @@ let s:VERSION = '0.2.6'
|
||||||
let s:old_cpo = &cpo
|
let s:old_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
" Set default away minutes
|
|
||||||
if !exists("g:wakatime_AwayMinutes")
|
|
||||||
let g:wakatime_AwayMinutes = 10
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Set default action frequency in minutes
|
|
||||||
if !exists("g:wakatime_ActionFrequency")
|
|
||||||
let g:wakatime_ActionFrequency = 5
|
|
||||||
endif
|
|
||||||
|
|
||||||
" To be backwards compatible, rename config file
|
" To be backwards compatible, rename config file
|
||||||
if filereadable(expand("$HOME/.wakatime"))
|
if filereadable(expand("$HOME/.wakatime"))
|
||||||
exec "silent !mv" expand("$HOME/.wakatime") expand("$HOME/.wakatime.conf")
|
exec "silent !mv" expand("$HOME/.wakatime") expand("$HOME/.wakatime.conf")
|
||||||
|
@ -55,6 +45,11 @@ let s:VERSION = '0.2.6'
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Set default action frequency in minutes
|
||||||
|
if !exists("g:wakatime_ActionFrequency")
|
||||||
|
let g:wakatime_ActionFrequency = 5
|
||||||
|
endif
|
||||||
|
|
||||||
" Globals
|
" Globals
|
||||||
let s:plugin_directory = expand("<sfile>:p:h") . '/'
|
let s:plugin_directory = expand("<sfile>:p:h") . '/'
|
||||||
let s:last_action = 0
|
let s:last_action = 0
|
||||||
|
@ -78,7 +73,7 @@ let s:VERSION = '0.2.6'
|
||||||
return current_time
|
return current_time
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Api(targetFile, time, endtime, is_write, last)
|
function! s:Api(targetFile, time, is_write, last)
|
||||||
let targetFile = a:targetFile
|
let targetFile = a:targetFile
|
||||||
if targetFile == ''
|
if targetFile == ''
|
||||||
let targetFile = a:last[2]
|
let targetFile = a:last[2]
|
||||||
|
@ -91,16 +86,9 @@ let s:VERSION = '0.2.6'
|
||||||
if a:is_write
|
if a:is_write
|
||||||
let cmd = cmd + ['--write']
|
let cmd = cmd + ['--write']
|
||||||
endif
|
endif
|
||||||
if a:endtime > 1
|
|
||||||
let cmd = cmd + ['--endtime', printf('%f', a:endtime)]
|
|
||||||
endif
|
|
||||||
"let cmd = cmd + ['--verbose']
|
"let cmd = cmd + ['--verbose']
|
||||||
exec 'silent !' . join(cmd, ' ') . ' &'
|
exec 'silent !' . join(cmd, ' ') . ' &'
|
||||||
let time = a:time
|
call s:SetLastAction(a:time, a:time, targetFile)
|
||||||
if a:endtime > 1 && float2nr(round(time)) < float2nr(round(a:endtime))
|
|
||||||
let time = a:endtime
|
|
||||||
endif
|
|
||||||
call s:SetLastAction(time, time, targetFile)
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -136,47 +124,6 @@ let s:VERSION = '0.2.6'
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ShouldPromptUser(now, last)
|
|
||||||
let prev = a:last[1]
|
|
||||||
if s:fresh || prev < 1
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
let duration = a:now - prev
|
|
||||||
if duration > g:wakatime_AwayMinutes * 60
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:Away(now, last)
|
|
||||||
let minutes = ''
|
|
||||||
let duration = a:now - a:last[1]
|
|
||||||
let units = 'second'
|
|
||||||
if duration >= 60
|
|
||||||
let duration = round(duration / 60)
|
|
||||||
let units = 'minute'
|
|
||||||
if duration >= 60
|
|
||||||
let remainder = float2nr(round(duration)) % 60
|
|
||||||
if remainder > 0
|
|
||||||
let minutes = printf(" and %.f minute", remainder)
|
|
||||||
if remainder > 1
|
|
||||||
let minutes = minutes . 's'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
let duration = round(duration / 60)
|
|
||||||
let units = 'hour'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
if duration > 1
|
|
||||||
let units = units . 's'
|
|
||||||
endif
|
|
||||||
let answer = input(printf("You were away %.f %s%s. Add time to current file? (y/n)", duration, units, minutes))
|
|
||||||
if answer == "y"
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,19 +134,7 @@ let s:VERSION = '0.2.6'
|
||||||
let now = s:GetCurrentTime()
|
let now = s:GetCurrentTime()
|
||||||
let last = s:GetLastAction()
|
let last = s:GetLastAction()
|
||||||
if s:EnoughTimePassed(now, last) || targetFile != last[2]
|
if s:EnoughTimePassed(now, last) || targetFile != last[2]
|
||||||
if s:ShouldPromptUser(now, last)
|
call s:Api(targetFile, now, 0, last)
|
||||||
if s:Away(now, last)
|
|
||||||
call s:Api(targetFile, now, last[0], 0, last)
|
|
||||||
else
|
|
||||||
call s:Api(targetFile, now, 0.0, 0, last)
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if !s:fresh
|
|
||||||
call s:Api(targetFile, now, last[0], 0, last)
|
|
||||||
else
|
|
||||||
call s:Api(targetFile, now, 0, 0, last)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
if now - last[1] > 5
|
if now - last[1] > 5
|
||||||
call s:SetLastAction(last[0], now, targetFile)
|
call s:SetLastAction(last[0], now, targetFile)
|
||||||
|
@ -211,23 +146,7 @@ let s:VERSION = '0.2.6'
|
||||||
let targetFile = s:GetCurrentFile()
|
let targetFile = s:GetCurrentFile()
|
||||||
let now = s:GetCurrentTime()
|
let now = s:GetCurrentTime()
|
||||||
let last = s:GetLastAction()
|
let last = s:GetLastAction()
|
||||||
if s:EnoughTimePassed(now, last) || targetFile != last[2]
|
call s:Api(targetFile, now, 1, last)
|
||||||
if s:ShouldPromptUser(now, last)
|
|
||||||
if s:Away(now, last)
|
|
||||||
call s:Api(targetFile, now, last[0], 1, last)
|
|
||||||
else
|
|
||||||
call s:Api(targetFile, now, 0.0, 1, last)
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if !s:fresh
|
|
||||||
call s:Api(targetFile, now, last[0], 1, last)
|
|
||||||
else
|
|
||||||
call s:Api(targetFile, now, 0, 1, last)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
call s:Api(targetFile, now, 0.0, 1, last)
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
Loading…
Reference in a new issue