Add nvim availability check to annotation plugin

This commit is contained in:
Talia 2021-10-05 19:30:37 +02:00
parent a891a06dae
commit b9aa577c59
1 changed files with 37 additions and 35 deletions

View File

@ -1,41 +1,43 @@
let s:namespace = nvim_create_namespace("annotate_cursor") let s:namespace = nvim_create_namespace("annotate_cursor")
let s:callbacks = [] let s:callbacks = []
function! Blame() if has("nvim")
if exists("b:blame") function! Blame()
let l:lineblame = b:blame[line('.')-1] if exists("b:blame")
return l:lineblame['author'] . ' @ ' . l:lineblame['time'] let l:lineblame = b:blame[line('.')-1]
end return l:lineblame['author'] . ' @ ' . l:lineblame['time']
endfun
function! Annotate(callback)
call insert(s:callbacks, a:callback)
call s:update()
endfun
com! -nargs=1 Annotate call Annotate(funcref(<q-args>))
function! Deannotate(callback)
let s:callbacks = filter(s:callbacks, { idx, value -> value != a:callback })
call s:update()
endfun
com! -nargs=1 Deannotate call Deannotate(funcref(<q-args>))
function! Annotated(callback)
for l:Callback in s:callbacks
if l:Callback == a:callback
return 1
end end
endfor endfun
return 0
endfun
function! s:update() function! Annotate(callback)
call nvim_buf_clear_namespace(0, s:namespace, 1, -1) call insert(s:callbacks, a:callback)
for l:Callback in s:callbacks call s:update()
call nvim_buf_set_virtual_text(0, s:namespace, line('.')-1, [[l:Callback(), "comment"]], {}) endfun
endfor com! -nargs=1 Annotate call Annotate(funcref(<q-args>))
redraw!
endfun
au CursorMoved * call <SID>update() function! Deannotate(callback)
au CursorMovedI * call <SID>update() let s:callbacks = filter(s:callbacks, { idx, value -> value != a:callback })
call s:update()
endfun
com! -nargs=1 Deannotate call Deannotate(funcref(<q-args>))
function! Annotated(callback)
for l:Callback in s:callbacks
if l:Callback == a:callback
return 1
end
endfor
return 0
endfun
function! s:update()
call nvim_buf_clear_namespace(0, s:namespace, 1, -1)
for l:Callback in s:callbacks
call nvim_buf_set_virtual_text(0, s:namespace, line('.')-1, [[l:Callback(), "comment"]], {})
endfor
redraw!
endfun
au CursorMoved * call <SID>update()
au CursorMovedI * call <SID>update()
end