From b9aa577c5905287c1295c162aa646b2f35ec1d93 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Tue, 5 Oct 2021 19:30:37 +0200 Subject: [PATCH] Add nvim availability check to annotation plugin --- vim/plugin/annotate.vim | 72 +++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/vim/plugin/annotate.vim b/vim/plugin/annotate.vim index 250141f..e6a06b0 100644 --- a/vim/plugin/annotate.vim +++ b/vim/plugin/annotate.vim @@ -1,41 +1,43 @@ let s:namespace = nvim_create_namespace("annotate_cursor") let s:callbacks = [] -function! Blame() - if exists("b:blame") - let l:lineblame = b:blame[line('.')-1] - return l:lineblame['author'] . ' @ ' . l:lineblame['time'] - end -endfun - -function! Annotate(callback) - call insert(s:callbacks, a:callback) - call s:update() -endfun -com! -nargs=1 Annotate call Annotate(funcref()) - -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()) - -function! Annotated(callback) - for l:Callback in s:callbacks - if l:Callback == a:callback - return 1 +if has("nvim") + function! Blame() + if exists("b:blame") + let l:lineblame = b:blame[line('.')-1] + return l:lineblame['author'] . ' @ ' . l:lineblame['time'] end - endfor - return 0 -endfun + 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 + function! Annotate(callback) + call insert(s:callbacks, a:callback) + call s:update() + endfun + com! -nargs=1 Annotate call Annotate(funcref()) -au CursorMoved * call update() -au CursorMovedI * call update() + 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()) + + 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 update() + au CursorMovedI * call update() +end