Skip to content

Commit 370a6a3

Browse files
committed
number to string helper function
1 parent 81e2a93 commit 370a6a3

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

plugin/wakatime.vim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ let s:VERSION = '7.1.0'
223223

224224
function! s:SanitizeArg(arg)
225225
let sanitized = shellescape(a:arg)
226-
let sanitized = substitute(sanitized, '!', '\\!', '')
226+
let sanitized = substitute(sanitized, '!', '\\!', 'g')
227227
return sanitized
228228
endfunction
229229

@@ -250,7 +250,7 @@ let s:VERSION = '7.1.0'
250250
if s:has_reltime
251251
return split(reltimestr(reltime()))[0]
252252
endif
253-
return printf('%d', localtime())
253+
return s:n2s(localtime())
254254
endfunction
255255

256256
function! s:AppendHeartbeat(file, now, is_write, last)
@@ -330,7 +330,7 @@ let s:VERSION = '7.1.0'
330330
let cmd = [python_bin, '-W', 'ignore', s:cli_location]
331331
let cmd = cmd + ['--entity', heartbeat.entity]
332332
let cmd = cmd + ['--time', heartbeat.time]
333-
let cmd = cmd + ['--plugin', printf('vim/%d vim-wakatime/%s', v:version, s:VERSION)]
333+
let cmd = cmd + ['--plugin', printf('vim/%s vim-wakatime/%s', s:n2s(v:version), s:VERSION)]
334334
if heartbeat.is_write
335335
let cmd = cmd + ['--write']
336336
endif
@@ -460,7 +460,7 @@ let s:VERSION = '7.1.0'
460460
" Add a milisecond to a:time.
461461
" Time prevision doesn't matter, but order of heartbeats does.
462462
if !(a:time_str =~ "\.")
463-
let millisecond = printf('%d', a:loop_count)
463+
let millisecond = s:n2s(a:loop_count)
464464
while strlen(millisecond) < 6
465465
let millisecond = '0' . millisecond
466466
endwhile
@@ -487,9 +487,13 @@ let s:VERSION = '7.1.0'
487487
let s:last_heartbeat = {'last_activity_at': a:last_activity_at, 'last_heartbeat_at': a:last_heartbeat_at, 'file': a:file}
488488
endfunction
489489

490+
function! s:n2s(number)
491+
return substitute(printf('%d', a:number), ',', '.', '')
492+
endfunction
493+
490494
function! s:SetLastHeartbeat(last_activity_at, last_heartbeat_at, file)
491495
call s:SetLastHeartbeatInMemory(a:last_activity_at, a:last_heartbeat_at, a:file)
492-
call writefile([substitute(printf('%d', a:last_activity_at), ',', '.', ''), substitute(printf('%d', a:last_heartbeat_at), ',', '.', ''), a:file], s:data_file)
496+
call writefile([s:n2s(a:last_activity_at), s:n2s(a:last_heartbeat_at), a:file], s:data_file)
493497
endfunction
494498

495499
function! s:EnoughTimePassed(now, last)

0 commit comments

Comments
 (0)