Skip to content

Commit 57d1c61

Browse files
committed
:RecentNotes command to list (matching) notes by modification date
1 parent a7a3d26 commit 57d1c61

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The notes.vim plug-in for the [Vim text editor] [vim] makes it easy to manage yo
1111
* **Smart defaults:** Without an argument `:SearchNotes` searches for the word under the cursor (if the word starts with `@` that character will be included in the search, this means you can easily search for *@tagged* notes)
1212
* **Back-references:** The `:RelatedNotes` command find all notes referencing the current file
1313
* A [Python 2] [python] script is included that accelerates keyword searches using an [SQLite] [sqlite] database
14+
* The `:RecentNotes` command lists your notes by modification date, starting with the most recently edited note
1415
* **Navigating between notes:** The included file type plug-in redefines [gf] [gf] to jump between notes and the syntax script highlights note names as hyper links
1516
* **Writing aids:** The included file type plug-in contains mappings for automatic curly quotes, arrows and list bullets and supports completion of note titles using Control-X Control-U
1617
* **Embedded file types:** The included syntax script supports embedded highlighting using blocks marked with `{{{type … }}}` which allows you to embed highlighted code and configuration snippets in your notes

autoload/xolox/notes.vim

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: June 8, 2011
3+
" Last Change: June 11, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Note: This file is encoded in UTF-8 including a byte order mark so
@@ -309,6 +309,78 @@ function! xolox#notes#related(bang) " {{{1
309309
endif
310310
endfunction
311311

312+
function! xolox#notes#recent(bang, title_filter) " {{{1
313+
let start = xolox#misc#timer#start()
314+
let bufname = '[All Notes]'
315+
" Open buffer that holds list of notes.
316+
if !bufexists(bufname)
317+
execute 'hide edit' fnameescape(bufname)
318+
setlocal buftype=nofile nospell
319+
else
320+
execute 'hide buffer' fnameescape(bufname)
321+
setlocal noreadonly modifiable
322+
silent %delete
323+
endif
324+
" Filter notes by pattern (argument)?
325+
let notes = []
326+
let title_filter = '\v' . a:title_filter
327+
for [fname, title] in items(xolox#notes#get_fnames_and_titles())
328+
if title =~? title_filter
329+
call add(notes, [getftime(fname), title])
330+
endif
331+
endfor
332+
" Start note with title and short description.
333+
let readme = "You have "
334+
if empty(notes)
335+
let readme .= "no notes"
336+
elseif len(notes) == 1
337+
let readme .= "one note"
338+
else
339+
let readme .= len(notes) . " notes"
340+
endif
341+
if a:title_filter != ''
342+
let quote_format = xolox#notes#unicode_enabled() ? '‘%s’' : "`%s'"
343+
let readme .= " matching " . printf(quote_format, a:title_filter)
344+
endif
345+
if empty(notes)
346+
let readme .= "."
347+
elseif len(notes) == 1
348+
let readme .= ", it's listed below."
349+
else
350+
let readme .= ". They're listed below grouped by the day they were edited, starting with your most recently edited note."
351+
endif
352+
call setline(1, ["All notes", "", readme])
353+
normal Ggqq
354+
" Sort, group and format list of (matching) notes.
355+
let last_date = ''
356+
let list_item_format = xolox#notes#unicode_enabled() ? ' • %s' : ' * %s'
357+
let date_format = '%A, %B %d:'
358+
let today = strftime(date_format, localtime())
359+
let yesterday = strftime(date_format, localtime() - 60*60*24)
360+
call sort(notes)
361+
call reverse(notes)
362+
let lines = []
363+
for [ftime, title] in notes
364+
let date = strftime(date_format, ftime)
365+
" Add date heading because date changed?
366+
if date != last_date
367+
call add(lines, '')
368+
if date == today
369+
call add(lines, "Today:")
370+
elseif date == yesterday
371+
call add(lines, "Yesterday:")
372+
else
373+
call add(lines, date)
374+
endif
375+
let last_date = date
376+
endif
377+
call add(lines, printf(list_item_format, title))
378+
endfor
379+
call setline(line('$') + 1, lines)
380+
setlocal readonly nomodifiable nomodified filetype=notes
381+
call xolox#misc#timer#stop("%s: Created list of notes in %s.", s:script, start)
382+
endfunction
383+
312384
" Miscellaneous functions. {{{1
313385

314386
function! s:is_empty_buffer() " {{{2

doc/notes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ notes in Vim:
3434
- A Python 2 [1] script is included that accelerates keyword searches using an
3535
SQLite [2] database
3636

37+
- The ':RecentNotes' command lists your notes by modification date, starting
38+
with the most recently edited note
39+
3740
- Navigating between notes: The included file type plug-in redefines |gf| to
3841
jump between notes and the syntax script highlights note names as hyper
3942
links

misc/notes/shadow/Note taking commands

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ updates and searches should be more or less instantaneous.
8484
This command makes it easy to find all notes related to the current file: If
8585
you are currently editing a note then a search for the note’s title is done,
8686
otherwise this searches for the absolute path of the current file.
87+
88+
# :RecentNotes lists notes by modification date
89+
90+
If you execute the :RecentNotes command it will open a Vim buffer that lists
91+
all your notes grouped by the day they were edited, starting with your most
92+
recently edited note. If you pass an argument to :RecentNotes it will filter
93+
the list of notes by matching the title of each note against the argument which
94+
is interpreted as a Vim pattern.

plugin/notes.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" Vim plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: June 8, 2011
3+
" Last Change: June 11, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55
" License: MIT
6-
" Version: 0.8.11
6+
" Version: 0.8.12
77

88
" Support for automatic update using the GLVS plug-in.
99
" GetLatestVimScripts: 3375 1 :AutoInstall: notes.zip
@@ -42,6 +42,7 @@ command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(
4242
command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
4343
command! -bar -bang -nargs=? SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
4444
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
45+
command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)
4546

4647
" Automatic commands to enable the :edit note:… shortcut and load the notes file type.
4748

0 commit comments

Comments
 (0)