Skip to content

Commit ac3e0f5

Browse files
committed
Automatically cleanup old "note:..." buffers*
* Also added lots of debug logging to make it easier to debug** the expansion of the note: shortcut ** I was having some issues with a conflict between the note: shortcut & an unreleased plug-in of mine
1 parent ba73927 commit ac3e0f5

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

autoload/xolox/notes.vim

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.17.11'
9+
let g:xolox#notes#version = '0.18'
1010
let s:scriptdir = expand('<sfile>:p:h')
1111

1212
call xolox#misc#compat#check('notes', 2)
@@ -87,8 +87,19 @@ endfunction
8787

8888
function! xolox#notes#shortcut() " {{{1
8989
" The "note:" pseudo protocol is just a shortcut for the :Note command.
90-
let name = matchstr(expand('<afile>'), 'note:\zs.*')
91-
call xolox#notes#edit(v:cmdbang ? '!' : '', name)
90+
let expression = expand('<afile>')
91+
let bufnr_save = bufnr('%')
92+
call xolox#misc#msg#debug("notes.vim %s: Expanding shortcut %s ..", g:xolox#notes#version, string(expression))
93+
let substring = matchstr(expression, 'note:\zs.*')
94+
call xolox#misc#msg#debug("notes.vim %s: Editing note based on title substring %s ..", g:xolox#notes#version, string(substring))
95+
call xolox#notes#edit(v:cmdbang ? '!' : '', substring)
96+
" Clean up the buffer with the name "note:..."?
97+
let pathname = fnamemodify(bufname(bufnr_save), ':p')
98+
let basename = fnamemodify(pathname, ':t')
99+
if basename =~ '^note:'
100+
call xolox#misc#msg#debug("notes.vim %s: Cleaning up buffer #%i - %s", g:xolox#notes#version, bufnr_save, pathname)
101+
execute 'bwipeout' bufnr_save
102+
endif
92103
endfunction
93104

94105
function! xolox#notes#edit(bang, title) abort " {{{1
@@ -98,6 +109,7 @@ function! xolox#notes#edit(bang, title) abort " {{{1
98109
if title != ''
99110
let fname = xolox#notes#select(title)
100111
if fname != ''
112+
call xolox#misc#msg#debug("notes.vim %s: Editing existing note: %s", g:xolox#notes#version, fname)
101113
execute 'edit' . a:bang fnameescape(fname)
102114
if !xolox#notes#unicode_enabled() && xolox#misc#path#equals(fnamemodify(fname, ':h'), g:notes_shadowdir)
103115
call s:transcode_utf8_latin1()
@@ -236,14 +248,18 @@ function! xolox#notes#select(filter) " {{{1
236248
let filter = xolox#misc#str#trim(a:filter)
237249
for [fname, title] in items(xolox#notes#get_fnames_and_titles(1))
238250
if title ==? filter
251+
call xolox#misc#msg#debug("notes.vim %s: Filter %s exactly matches note: %s", g:xolox#notes#version, string(filter), title)
239252
return fname
240253
elseif title =~? filter
241254
let notes[fname] = title
242255
endif
243256
endfor
244257
if len(notes) == 1
245-
return keys(notes)[0]
258+
let fname = keys(notes)[0]
259+
call xolox#misc#msg#debug("notes.vim %s: Filter %s matched one note: %s", g:xolox#notes#version, string(filter), fname)
260+
return fname
246261
elseif !empty(notes)
262+
call xolox#misc#msg#debug("notes.vim %s: Filter %s matched %i notes.", g:xolox#notes#version, string(filter), len(notes))
247263
let choices = ['Please select a note:']
248264
let values = ['']
249265
for fname in sort(keys(notes), 1)
@@ -252,7 +268,9 @@ function! xolox#notes#select(filter) " {{{1
252268
endfor
253269
let choice = inputlist(choices)
254270
if choice > 0 && choice < len(choices)
255-
return values[choice]
271+
let fname = values[choice]
272+
call xolox#misc#msg#debug("notes.vim %s: User selected note: %s", g:xolox#notes#version, string(filter), fname)
273+
return fname
256274
endif
257275
endif
258276
return ''

0 commit comments

Comments
 (0)