1
1
" Vim auto-load script
2
2
" Author: Peter Odding <peter@peterodding.com>
3
- " Last Change: April 30 , 2013
3
+ " Last Change: May 5 , 2013
4
4
" URL: http://peterodding.com/code/vim/notes/
5
5
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.10 '
9
+ let g: xolox #notes#version = ' 0.17.11 '
10
10
let s: scriptdir = expand (' <sfile>:p:h' )
11
11
12
12
call xolox#misc#compat#check (' notes' , 2 )
@@ -499,18 +499,14 @@ function! xolox#notes#related(bang) " {{{1
499
499
endfunction
500
500
501
501
function ! 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 )
502
503
" Show generated note listing all notes by last modified time.
503
504
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 )})
514
510
" Filter notes by pattern (argument)?
515
511
let notes = []
516
512
let title_filter = ' \v' . a: title_filter
@@ -519,7 +515,7 @@ function! xolox#notes#recent(bang, title_filter) " {{{1
519
515
call add (notes, [getftime (fname), title ])
520
516
endif
521
517
endfor
522
- " Start note with title and short description .
518
+ " Start note with "You have N note(s) [matching filter]" .
523
519
let readme = " You have "
524
520
if empty (notes)
525
521
let readme .= " no notes"
@@ -532,16 +528,19 @@ function! xolox#notes#recent(bang, title_filter) " {{{1
532
528
let quote_format = xolox#notes#unicode_enabled () ? ' ‘%s’' : " `%s'"
533
529
let readme .= " matching " . printf (quote_format, a: title_filter )
534
530
endif
531
+ " Explain the sorting of the notes.
535
532
if empty (notes)
536
533
let readme .= " ."
537
534
elseif len (notes) == 1
538
535
let readme .= " , it's listed below."
539
536
else
540
537
let readme .= " . They're listed below grouped by the day they were edited, starting with your most recently edited note."
541
538
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.
543
542
normal Ggqq
544
- " Sort, group and format list of (matching) notes.
543
+ " Sort, group and format the list of (matching) notes.
545
544
let last_date = ' '
546
545
let list_item_format = xolox#notes#unicode_enabled () ? ' • %s' : ' * %s'
547
546
call sort (notes)
@@ -556,8 +555,15 @@ function! xolox#notes#recent(bang, title_filter) " {{{1
556
555
endif
557
556
call add (lines , printf (list_item_format, title ))
558
557
endfor
558
+ " Add the formatted list of notes to the buffer.
559
559
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!
561
567
call xolox#misc#timer#stop (" notes.vim %s: Generated %s in %s." , g: xolox #notes#version , bufname , starttime)
562
568
endfunction
563
569
0 commit comments