Skip to content

Commit

Permalink
:DeleteNote {title} support by github.com/bioe007 (pull request #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Sep 26, 2011
2 parents 3a5e573 + 57b7168 commit 2f1229f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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

Expand Down
33 changes: 24 additions & 9 deletions autoload/xolox/notes.vim
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions doc/notes.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/notes.vim
Expand Up @@ -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>)
Expand Down

0 comments on commit 2f1229f

Please sign in to comment.