Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

:DeleteNote {title} support by github.com/bioe007 (pull request #9)

  • Loading branch information...
commit 2f1229f90603785ac04350a068fa74bd76b10ec3 2 parents 3a5e573 + 57b7168
Peter Odding authored
2  README.md
View
@@ -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
33 autoload/xolox/notes.vim
View
@@ -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
9 doc/notes.txt
View
@@ -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
2  plugin/notes.vim
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>)
Please sign in to comment.
Something went wrong with that request. Please try again.