|
6 | 6 | " Note: This file is encoded in UTF-8 including a byte order mark so |
7 | 7 | " that Vim loads the script using the right encoding transparently. |
8 | 8 |
|
9 | | -let g:xolox#notes#version = '0.11.4' |
| 9 | +let g:xolox#notes#version = '0.11.5' |
10 | 10 |
|
11 | 11 | function! xolox#notes#shortcut() " {{{1 |
12 | 12 | " The "note:" pseudo protocol is just a shortcut for the :Note command. |
@@ -225,15 +225,25 @@ function! xolox#notes#save() abort " {{{1 |
225 | 225 | endif |
226 | 226 | endfunction |
227 | 227 |
|
228 | | -function! xolox#notes#delete(bang) " {{{1 |
229 | | - " Delete the current note, close the associated buffer & window. |
230 | | - let filename = expand('%:p') |
231 | | - if filereadable(filename) && delete(filename) |
232 | | - call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s!", g:xolox#notes#version, filename) |
233 | | - return |
| 228 | +function! xolox#notes#delete(bang, title) " {{{1 |
| 229 | + " Delete the note {title} and close the associated buffer & window. |
| 230 | + " If no {title} is given the current note is deleted. |
| 231 | + let title = xolox#misc#str#trim(a:title) |
| 232 | + if title == '' |
| 233 | + " Try the current buffer. |
| 234 | + let title = xolox#notes#fname_to_title(expand('%:p')) |
| 235 | + endif |
| 236 | + if !xolox#notes#exists(title) |
| 237 | + call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s! (not a note)", g:xolox#notes#version, expand('%:p')) |
| 238 | + else |
| 239 | + let filename = xolox#notes#title_to_fname(title) |
| 240 | + if filereadable(filename) && delete(filename) |
| 241 | + call xolox#misc#msg#warn("notes.vim %s: Failed to delete %s!", g:xolox#notes#version, filename) |
| 242 | + else |
| 243 | + call xolox#notes#cache_del(filename) |
| 244 | + execute 'bdelete' . a:bang . ' ' . bufnr(filename) |
| 245 | + endif |
234 | 246 | endif |
235 | | - call xolox#notes#cache_del(filename) |
236 | | - execute 'bdelete' . a:bang |
237 | 247 | endfunction |
238 | 248 |
|
239 | 249 | function! xolox#notes#search(bang, input) " {{{1 |
@@ -549,6 +559,11 @@ function! xolox#notes#get_titles(include_shadow_notes) " {{{3 |
549 | 559 | return titles |
550 | 560 | endfunction |
551 | 561 |
|
| 562 | +function! xolox#notes#exists(title) " {{{3 |
| 563 | + " Return true if the note {title} exists. |
| 564 | + return index(xolox#notes#get_titles(0), a:title, 0, xolox#misc#os#is_win()) >= 0 |
| 565 | +endfunction |
| 566 | + |
552 | 567 | function! xolox#notes#get_fnames_and_titles(include_shadow_notes) " {{{3 |
553 | 568 | " Get dictionary of filename => title pairs of all existing notes. |
554 | 569 | if !s:have_cached_items |
|
0 commit comments