diff --git a/autoload/denote/ft.vim b/autoload/denote/ft.vim index 1cf3484..c47fc4d 100644 --- a/autoload/denote/ft.vim +++ b/autoload/denote/ft.vim @@ -45,8 +45,11 @@ function denote#ft#qf() command! -nargs=1 -range -buffer DenoteSetTitle :call denote#notes#settitle(, ) command! -nargs=1 -range -buffer -complete=custom,denote#completion#tags DenoteTagAdd :call denote#notes#tagmod(, , , v:true) command! -nargs=1 -range -buffer -complete=custom,denote#completion#tags DenoteTagRm :call denote#notes#tagmod(, , , v:false) + command! -range -buffer DenoteDelete :call denote#notes#rm(, ) nnoremap C :DenoteSetTitle nnoremap + :DenoteTagAdd nnoremap - :DenoteTagRm + nnoremap dd :DenoteDelete + " TODO: Add visual maps for line ranges +/-/delete endif endfunction diff --git a/autoload/denote/notes.vim b/autoload/denote/notes.vim index 6fb7981..8524d2b 100644 --- a/autoload/denote/notes.vim +++ b/autoload/denote/notes.vim @@ -144,3 +144,27 @@ function denote#notes#copy(origfile) exe 'w' endif endfunction + +" Delete notes from denote directory +function denote#notes#rm(line1, line2) + let l:items = getloclist(0, {'items': 1})['items'] + if empty(l:items) + return + endif + for i in range(a:line1, a:line2) + let l:item = l:items[i-1] + let l:bufnr = l:item['bufnr'] + let l:filename = bufname(l:bufnr) + let l:title = denote#meta#noteTitleFromFile(l:filename) + let l:answer = confirm('Are you sure you want to delete the note "' .. l:title .. '"?', "&Yes\n&No\n", 2, 'Question') + if l:answer != 1 + continue + endif + " Wipe buffer, if it exists + if bufexists(l:filename) + exe 'silent bwipe ' .. fnameescape(l:filename) + endif + " Delete file + call delete(l:filename) + endfor +endfunction