2021-10-05 13:03:54 +00:00
|
|
|
let s:namespace = nvim_create_namespace("annotate_cursor")
|
|
|
|
let s:callbacks = []
|
|
|
|
|
2021-10-05 17:30:37 +00:00
|
|
|
if has("nvim")
|
|
|
|
function! Blame()
|
|
|
|
if exists("b:blame")
|
|
|
|
let l:lineblame = b:blame[line('.')-1]
|
|
|
|
return l:lineblame['author'] . ' @ ' . l:lineblame['time']
|
|
|
|
end
|
|
|
|
endfun
|
2021-10-05 13:03:54 +00:00
|
|
|
|
2021-10-05 17:30:37 +00:00
|
|
|
function! Annotate(callback)
|
|
|
|
call insert(s:callbacks, a:callback)
|
|
|
|
call s:update()
|
|
|
|
endfun
|
|
|
|
com! -nargs=1 Annotate call Annotate(funcref(<q-args>))
|
2021-10-05 13:03:54 +00:00
|
|
|
|
2021-10-05 17:30:37 +00:00
|
|
|
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>))
|
2021-10-05 13:03:54 +00:00
|
|
|
|
2021-10-05 17:30:37 +00:00
|
|
|
function! Annotated(callback)
|
|
|
|
for l:Callback in s:callbacks
|
|
|
|
if l:Callback == a:callback
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
endfor
|
|
|
|
return 0
|
|
|
|
endfun
|
2021-10-05 13:03:54 +00:00
|
|
|
|
2021-10-05 17:30:37 +00:00
|
|
|
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
|
2021-10-05 13:03:54 +00:00
|
|
|
|
2021-10-05 17:30:37 +00:00
|
|
|
au CursorMoved * call <SID>update()
|
|
|
|
au CursorMovedI * call <SID>update()
|
|
|
|
end
|