Permalink
Browse files

DeleteNote accepts a note title as an argument

This way you can delete notes without having to first open them.

Also allows completion of note titles.

Also prevent deleting and clearing the current (file, buffer) pair if
its not a `vim-note`

xolox#notes#exists : returns true if a given note exists
  • Loading branch information...
1 parent 60526a3 commit 57b7168b474d07c949db68d81b910e890a5067e0 Perry Hargrave committed Sep 20, 2011
Showing with 29 additions and 5 deletions.
  1. +28 −4 autoload/xolox/notes.vim
  2. +1 −1 plugin/notes.vim
@@ -225,15 +225,28 @@ 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')
+function! xolox#notes#delete(bang, title) " {{{1
+ " Delete the note `title` and closes the associated buffer & window.
+ " If no `title` is given then use the current note.
+ let title = xolox#misc#str#trim(a:title)
+ if title == ''
+ " Try the current buffer.
+ let title = xolox#notes#fname_to_title(expand('%:p'))
+ end
+
+ if xolox#notes#exists(title) == 0
+ call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s! (not a note)",
+ \ g:xolox#notes#version, expand('%:p'))
+ return
+ end
+
+ 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)
return
endif
call xolox#notes#cache_del(filename)
- execute 'bdelete' . a:bang
+ execute 'bdelete' . a:bang . bufnr(filename)
endfunction
function! xolox#notes#search(bang, input) " {{{1
@@ -549,6 +562,17 @@ function! xolox#notes#get_titles(include_shadow_notes) " {{{3
return titles
endfunction
+function! xolox#notes#exists(title) " {{{3
+ " Return true if a note `title` exists
+ let titles = xolox#notes#get_titles(0)
+ for note in titles
+ if note == a:title
+ return 1
+ end
+ endfor
+ return 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
View
@@ -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(<q-bang>, <q-args>)
command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>)
-command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
+command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(<q-bang>, <q-args>)
command! -bang -nargs=? SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)

0 comments on commit 57b7168

Please sign in to comment.