11" Vim auto-load script
22" Author: Peter Odding <peter@peterodding.com>
3- " Last Change: April 30 , 2013
3+ " Last Change: May 5 , 2013
44" URL: http://peterodding.com/code/vim/notes/
55
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.10 '
9+ let g: xolox #notes#version = ' 0.17.11 '
1010let s: scriptdir = expand (' <sfile>:p:h' )
1111
1212call xolox#misc#compat#check (' notes' , 2 )
@@ -499,18 +499,14 @@ function! xolox#notes#related(bang) " {{{1
499499endfunction
500500
501501function ! xolox#notes#recent (bang , title_filter) " {{{1
502+ call xolox#misc#msg#info (" notes.vim %s: Generating overview of recent notes .." , g: xolox #notes#version )
502503 " Show generated note listing all notes by last modified time.
503504 let starttime = xolox#misc#timer#start ()
504- let bufname = ' [All Notes]'
505- " Open buffer that holds list of notes.
506- if ! bufexists (bufname )
507- execute ' hide edit' fnameescape (bufname )
508- setlocal buftype = nofile nospell
509- else
510- execute ' hide buffer' fnameescape (bufname )
511- setlocal noreadonly modifiable
512- silent % delete
513- endif
505+ let bufname = ' [Recent Notes]'
506+ " Prepare a buffer to hold the list of recent notes.
507+ call xolox#misc#buffer#prepare ({
508+ \ ' name' : bufname ,
509+ \ ' path' : xolox#misc#path#merge ($HOME , bufname )})
514510 " Filter notes by pattern (argument)?
515511 let notes = []
516512 let title_filter = ' \v' . a: title_filter
@@ -519,7 +515,7 @@ function! xolox#notes#recent(bang, title_filter) " {{{1
519515 call add (notes, [getftime (fname), title ])
520516 endif
521517 endfor
522- " Start note with title and short description .
518+ " Start note with "You have N note(s) [matching filter]" .
523519 let readme = " You have "
524520 if empty (notes)
525521 let readme .= " no notes"
@@ -532,16 +528,19 @@ function! xolox#notes#recent(bang, title_filter) " {{{1
532528 let quote_format = xolox#notes#unicode_enabled () ? ' ‘%s’' : " `%s'"
533529 let readme .= " matching " . printf (quote_format, a: title_filter )
534530 endif
531+ " Explain the sorting of the notes.
535532 if empty (notes)
536533 let readme .= " ."
537534 elseif len (notes) == 1
538535 let readme .= " , it's listed below."
539536 else
540537 let readme .= " . They're listed below grouped by the day they were edited, starting with your most recently edited note."
541538 endif
542- call setline (1 , [" All notes" , " " , readme])
539+ " Add the generated text to the buffer.
540+ call setline (1 , [" Recent notes" , " " , readme])
541+ " Reformat the text in the buffer to auto-wrap.
543542 normal Ggqq
544- " Sort, group and format list of (matching) notes.
543+ " Sort, group and format the list of (matching) notes.
545544 let last_date = ' '
546545 let list_item_format = xolox#notes#unicode_enabled () ? ' • %s' : ' * %s'
547546 call sort (notes)
@@ -556,8 +555,15 @@ function! xolox#notes#recent(bang, title_filter) " {{{1
556555 endif
557556 call add (lines , printf (list_item_format, title ))
558557 endfor
558+ " Add the formatted list of notes to the buffer.
559559 call setline (line (' $' ) + 1 , lines )
560- setlocal readonly nomodifiable nomodified filetype = notes
560+ " Load the notes file type.
561+ setlocal filetype = notes
562+ let &l: statusline = bufname
563+ " Change the status line
564+ " Lock the buffer contents.
565+ call xolox#misc#buffer#lock ()
566+ " And we're done!
561567 call xolox#misc#timer#stop (" notes.vim %s: Generated %s in %s." , g: xolox #notes#version , bufname , starttime)
562568endfunction
563569
0 commit comments