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.17.11 '
9
+ let g: xolox #notes#version = ' 0.18 '
10
10
let s: scriptdir = expand (' <sfile>:p:h' )
11
11
12
12
call xolox#misc#compat#check (' notes' , 2 )
@@ -87,8 +87,19 @@ endfunction
87
87
88
88
function ! xolox#notes#shortcut () " {{{1
89
89
" 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
92
103
endfunction
93
104
94
105
function ! xolox#notes#edit (bang , title ) abort " {{{1
@@ -98,6 +109,7 @@ function! xolox#notes#edit(bang, title) abort " {{{1
98
109
if title != ' '
99
110
let fname = xolox#notes#select (title )
100
111
if fname != ' '
112
+ call xolox#misc#msg#debug (" notes.vim %s: Editing existing note: %s" , g: xolox #notes#version , fname)
101
113
execute ' edit' . a: bang fnameescape (fname)
102
114
if ! xolox#notes#unicode_enabled () && xolox#misc#path#equals (fnamemodify (fname, ' :h' ), g: notes_shadowdir )
103
115
call s: transcode_utf8_latin1 ()
@@ -236,14 +248,18 @@ function! xolox#notes#select(filter) " {{{1
236
248
let filter = xolox#misc#str#trim (a: filter )
237
249
for [fname, title ] in items (xolox#notes#get_fnames_and_titles (1 ))
238
250
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 )
239
252
return fname
240
253
elseif title = ~? filter
241
254
let notes[fname] = title
242
255
endif
243
256
endfor
244
257
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
246
261
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))
247
263
let choices = [' Please select a note:' ]
248
264
let values = [' ' ]
249
265
for fname in sort (keys (notes), 1 )
@@ -252,7 +268,9 @@ function! xolox#notes#select(filter) " {{{1
252
268
endfor
253
269
let choice = inputlist (choices)
254
270
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
256
274
endif
257
275
endif
258
276
return ' '
0 commit comments