diff --git a/README.md b/README.md index f052fcd..61a8cc6 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ When you execute this command it will start a new note with the selected text as ### The `:DeleteNote` command -The `:DeleteNote` command deletes the current note, destroys the buffer and removes the note from the internal cache of filenames and note titles. This fails when changes have been made to the current buffer, unless you use `:DeleteNote!` which discards any changes. +The `:DeleteNote` command deletes a note file, destroys the buffer and removes the note from the internal cache of filenames and note titles. If you pass a note name as an argument to `:DeleteNote` it will delete the given note, otherwise it will delete the current note. This fails when changes have been made to the buffer, unless you use `:DeleteNote!` which discards any changes. ### The `:SearchNotes` command diff --git a/autoload/xolox/notes.vim b/autoload/xolox/notes.vim index 8c6b6ef..b62ccb4 100644 --- a/autoload/xolox/notes.vim +++ b/autoload/xolox/notes.vim @@ -6,7 +6,7 @@ " Note: This file is encoded in UTF-8 including a byte order mark so " that Vim loads the script using the right encoding transparently. -let g:xolox#notes#version = '0.11.4' +let g:xolox#notes#version = '0.11.5' function! xolox#notes#shortcut() " {{{1 " The "note:" pseudo protocol is just a shortcut for the :Note command. @@ -225,15 +225,25 @@ function! xolox#notes#save() abort " {{{1 endif endfunction -function! xolox#notes#delete(bang) " {{{1 - " Delete the current note, close the associated buffer & window. - let filename = expand('%:p') - if filereadable(filename) && delete(filename) - call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s!", g:xolox#notes#version, filename) - return +function! xolox#notes#delete(bang, title) " {{{1 + " Delete the note {title} and close the associated buffer & window. + " If no {title} is given the current note is deleted. + let title = xolox#misc#str#trim(a:title) + if title == '' + " Try the current buffer. + let title = xolox#notes#fname_to_title(expand('%:p')) + endif + if !xolox#notes#exists(title) + call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s! (not a note)", g:xolox#notes#version, expand('%:p')) + else + let filename = xolox#notes#title_to_fname(title) + if filereadable(filename) && delete(filename) + call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s!", g:xolox#notes#version, filename) + else + call xolox#notes#cache_del(filename) + execute 'bdelete' . a:bang . ' ' . bufnr(filename) + endif endif - call xolox#notes#cache_del(filename) - execute 'bdelete' . a:bang endfunction function! xolox#notes#search(bang, input) " {{{1 @@ -549,6 +559,11 @@ function! xolox#notes#get_titles(include_shadow_notes) " {{{3 return titles endfunction +function! xolox#notes#exists(title) " {{{3 + " Return true if the note {title} exists. + return index(xolox#notes#get_titles(0), a:title, 0, xolox#misc#os#is_win()) >= 0 +endfunction + function! xolox#notes#get_fnames_and_titles(include_shadow_notes) " {{{3 " Get dictionary of filename => title pairs of all existing notes. if !s:have_cached_items diff --git a/doc/notes.txt b/doc/notes.txt index db6a55e..36e9fac 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -163,10 +163,11 @@ as the title of the note. ------------------------------------------------------------------------------- The *:DeleteNote* command -The |:DeleteNote| command deletes the current note, destroys the buffer and -removes the note from the internal cache of filenames and note titles. This -fails when changes have been made to the current buffer, unless you use -':DeleteNote!' which discards any changes. +The |:DeleteNote| command deletes a note file, destroys the buffer and removes +the note from the internal cache of filenames and note titles. If you pass a +note name as an argument to |:DeleteNote| it will delete the given note, +otherwise it will delete the current note. This fails when changes have been +made to the buffer, unless you use ':DeleteNote!' which discards any changes. ------------------------------------------------------------------------------- The *:SearchNotes* command diff --git a/plugin/notes.vim b/plugin/notes.vim index 8dd76fc..910260f 100644 --- a/plugin/notes.vim +++ b/plugin/notes.vim @@ -47,7 +47,7 @@ endif " User commands to create, delete and search notes. command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(, ) command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection() -command! -bar -bang DeleteNote call xolox#notes#delete() +command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(, ) command! -bang -nargs=? SearchNotes call xolox#notes#search(, ) command! -bar -bang RelatedNotes call xolox#notes#related() command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(, )