Skip to content

Commit 7c0d08b

Browse files
committed
New command :MostRecentNote (suggested by Jonathan Reeve)
Issue (really feature request :-) #38 on GitHub: #38
1 parent a83b099 commit 7c0d08b

File tree

5 files changed

+26
-76
lines changed

5 files changed

+26
-76
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ This command makes it easy to find all notes related to the current file: If you
187187

188188
If you execute the `:RecentNotes` command it will open a Vim buffer that lists all your notes grouped by the day they were edited, starting with your most recently edited note. If you pass an argument to `:RecentNotes` it will filter the list of notes by matching the title of each note against the argument which is interpreted as a Vim pattern.
189189

190+
### The `:MostRecentNote` command
191+
192+
This command edits your most recently edited note (whether you just opened the note or made changes to it). The plug-in will remember the most recent note between restarts of Vim and is shared between all instances of Vim.
193+
190194
### The `:ShowTaggedNotes` command
191195

192196
To show a list of all notes that contains *@tags* you can use the `:ShowTaggedNotes` command. If you pass a count to this command it will limit the list of tags to those that have been used at least this many times. For example the following two commands show tags that have been used at least ten times:

autoload/xolox/notes.vim

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: May 14, 2013
3+
" Last Change: May 16, 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.20.1'
9+
let g:xolox#notes#version = '0.21'
1010
let s:scriptdir = expand('<sfile>:p:h')
1111

1212
call xolox#misc#compat#check('notes', 3)
@@ -57,6 +57,11 @@ function! xolox#notes#init() " {{{1
5757
if !exists('g:notes_tagsindex')
5858
let g:notes_tagsindex = xolox#misc#path#merge(localdir, 'tags.txt')
5959
endif
60+
" Define the default location for the file containing the most recent note's
61+
" filename.
62+
if !exists('g:notes_recentindex')
63+
let g:notes_recentindex = xolox#misc#path#merge(localdir, 'recent.txt')
64+
endif
6065
" Define the default action when a note's filename and title are out of sync.
6166
if !exists('g:notes_title_sync')
6267
" Valid values are "no", "change_title", "rename_file" and "prompt".
@@ -531,75 +536,6 @@ function! xolox#notes#related(bang) " {{{1
531536
call xolox#misc#timer#stop("notes.vim %s: Found related notes in %s.", g:xolox#notes#version, starttime)
532537
endfunction
533538

534-
function! xolox#notes#recent(bang, title_filter) " {{{1
535-
call xolox#misc#msg#info("notes.vim %s: Generating overview of recent notes ..", g:xolox#notes#version)
536-
" Show generated note listing all notes by last modified time.
537-
let starttime = xolox#misc#timer#start()
538-
let bufname = '[Recent Notes]'
539-
" Prepare a buffer to hold the list of recent notes.
540-
call xolox#misc#buffer#prepare({
541-
\ 'name': bufname,
542-
\ 'path': xolox#misc#path#merge($HOME, bufname)})
543-
" Filter notes by pattern (argument)?
544-
let notes = []
545-
let title_filter = '\v' . a:title_filter
546-
for [fname, title] in items(xolox#notes#get_fnames_and_titles(0))
547-
if title =~? title_filter
548-
call add(notes, [getftime(fname), title])
549-
endif
550-
endfor
551-
" Start note with "You have N note(s) [matching filter]".
552-
let readme = "You have "
553-
if empty(notes)
554-
let readme .= "no notes"
555-
elseif len(notes) == 1
556-
let readme .= "one note"
557-
else
558-
let readme .= len(notes) . " notes"
559-
endif
560-
if a:title_filter != ''
561-
let quote_format = xolox#notes#unicode_enabled() ? '‘%s’' : "`%s'"
562-
let readme .= " matching " . printf(quote_format, a:title_filter)
563-
endif
564-
" Explain the sorting of the notes.
565-
if empty(notes)
566-
let readme .= "."
567-
elseif len(notes) == 1
568-
let readme .= ", it's listed below."
569-
else
570-
let readme .= ". They're listed below grouped by the day they were edited, starting with your most recently edited note."
571-
endif
572-
" Add the generated text to the buffer.
573-
call setline(1, ["Recent notes", "", readme])
574-
" Reformat the text in the buffer to auto-wrap.
575-
normal Ggqq
576-
" Sort, group and format the list of (matching) notes.
577-
let last_date = ''
578-
let list_item_format = xolox#notes#unicode_enabled() ? ' • %s' : ' * %s'
579-
call sort(notes)
580-
call reverse(notes)
581-
let lines = []
582-
for [ftime, title] in notes
583-
let date = xolox#notes#friendly_date(ftime)
584-
if date != last_date
585-
call add(lines, '')
586-
call add(lines, substitute(date, '^\w', '\u\0', '') . ':')
587-
let last_date = date
588-
endif
589-
call add(lines, printf(list_item_format, title))
590-
endfor
591-
" Add the formatted list of notes to the buffer.
592-
call setline(line('$') + 1, lines)
593-
" Load the notes file type.
594-
call xolox#notes#set_filetype()
595-
let &l:statusline = bufname
596-
" Change the status line
597-
" Lock the buffer contents.
598-
call xolox#misc#buffer#lock()
599-
" And we're done!
600-
call xolox#misc#timer#stop("notes.vim %s: Generated %s in %s.", g:xolox#notes#version, bufname, starttime)
601-
endfunction
602-
603539
" Miscellaneous functions. {{{1
604540

605541
function! xolox#notes#find_directories(include_shadow_directory) " {{{2

doc/notes.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ Contents ~
3131
2. Accelerated searching with Python |notes-accelerated-searching-with-python|
3232
7. The |:RelatedNotes| command
3333
8. The |:RecentNotes| command
34-
9. The |:ShowTaggedNotes| command
35-
10. The |:IndexTaggedNotes| command
34+
9. The |:MostRecentNote| command
35+
10. The |:ShowTaggedNotes| command
36+
11. The |:IndexTaggedNotes| command
3637
5. Mappings |notes-mappings|
3738
1. Insert mode mappings |notes-insert-mode-mappings|
3839
6. Customizing the syntax highlighting of notes
@@ -421,6 +422,13 @@ recently edited note. If you pass an argument to |:RecentNotes| it will filter
421422
the list of notes by matching the title of each note against the argument
422423
which is interpreted as a Vim pattern.
423424

425+
-------------------------------------------------------------------------------
426+
The *:MostRecentNote* command
427+
428+
This command edits your most recently edited note (whether you just opened the
429+
note or made changes to it). The plug-in will remember the most recent note
430+
between restarts of Vim and is shared between all instances of Vim.
431+
424432
-------------------------------------------------------------------------------
425433
The *:ShowTaggedNotes* command
426434

ftplugin/notes.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim file type plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: May 5, 2013
3+
" Last Change: May 16, 2013
44
" URL: http://peterodding.com/code/vim/notes/
55

66
if exists('b:did_ftplugin')
@@ -135,6 +135,7 @@ let b:undo_ftplugin .= ' | execute "vunmap <buffer> <Leader>tn"'
135135
" This is currently the only place where a command is guaranteed to be
136136
" executed when the user edits a note. Maybe I shouldn't abuse this (it
137137
" doesn't feel right ;-) but for now it will do.
138+
call xolox#notes#recent#track()
138139
call xolox#notes#check_sync_title()
139140

140141
" vim: ts=2 sw=2 et

plugin/notes.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: May 12, 2013
3+
" Last Change: May 16, 2013
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Support for automatic update using the GLVS plug-in.
@@ -19,7 +19,8 @@ command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note
1919
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(<q-bang>, <q-args>)
2020
command! -bang -nargs=? -complete=customlist,xolox#notes#keyword_complete SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
2121
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
22-
command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)
22+
command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent#show(<q-bang>, <q-args>)
23+
command! -bar -bang MostRecentNote call xolox#notes#recent#edit(<q-bang>)
2324
command! -bar -count=1 ShowTaggedNotes call xolox#notes#tags#show_tags(<count>)
2425
command! -bar IndexTaggedNotes call xolox#notes#tags#create_index()
2526

0 commit comments

Comments
 (0)