Permalink
Browse files

New command :MostRecentNote (suggested by Jonathan Reeve)

Issue (really feature request :-) #38 on GitHub:
  #38
  • Loading branch information...
1 parent a83b099 commit 7c0d08b6c09f90145558b44539a476d7e9c99b86 @xolox committed May 15, 2013
Showing with 26 additions and 76 deletions.
  1. +4 −0 README.md
  2. +7 −71 autoload/xolox/notes.vim
  3. +10 −2 doc/notes.txt
  4. +2 −1 ftplugin/notes.vim
  5. +3 −2 plugin/notes.vim
View
@@ -187,6 +187,10 @@ This command makes it easy to find all notes related to the current file: If you
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.
+### The `:MostRecentNote` command
+
+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.
+
### The `:ShowTaggedNotes` command
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:
View
@@ -1,12 +1,12 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 14, 2013
+" Last Change: May 16, 2013
" URL: http://peterodding.com/code/vim/notes/
" Note: This file is encoded in UTF-8 including a byte order mark so
" that Vim loads the script using the right encoding transparently.
-let g:xolox#notes#version = '0.20.1'
+let g:xolox#notes#version = '0.21'
let s:scriptdir = expand('<sfile>:p:h')
call xolox#misc#compat#check('notes', 3)
@@ -57,6 +57,11 @@ function! xolox#notes#init() " {{{1
if !exists('g:notes_tagsindex')
let g:notes_tagsindex = xolox#misc#path#merge(localdir, 'tags.txt')
endif
+ " Define the default location for the file containing the most recent note's
+ " filename.
+ if !exists('g:notes_recentindex')
+ let g:notes_recentindex = xolox#misc#path#merge(localdir, 'recent.txt')
+ endif
" Define the default action when a note's filename and title are out of sync.
if !exists('g:notes_title_sync')
" Valid values are "no", "change_title", "rename_file" and "prompt".
@@ -531,75 +536,6 @@ function! xolox#notes#related(bang) " {{{1
call xolox#misc#timer#stop("notes.vim %s: Found related notes in %s.", g:xolox#notes#version, starttime)
endfunction
-function! xolox#notes#recent(bang, title_filter) " {{{1
- call xolox#misc#msg#info("notes.vim %s: Generating overview of recent notes ..", g:xolox#notes#version)
- " Show generated note listing all notes by last modified time.
- let starttime = xolox#misc#timer#start()
- let bufname = '[Recent Notes]'
- " Prepare a buffer to hold the list of recent notes.
- call xolox#misc#buffer#prepare({
- \ 'name': bufname,
- \ 'path': xolox#misc#path#merge($HOME, bufname)})
- " Filter notes by pattern (argument)?
- let notes = []
- let title_filter = '\v' . a:title_filter
- for [fname, title] in items(xolox#notes#get_fnames_and_titles(0))
- if title =~? title_filter
- call add(notes, [getftime(fname), title])
- endif
- endfor
- " Start note with "You have N note(s) [matching filter]".
- let readme = "You have "
- if empty(notes)
- let readme .= "no notes"
- elseif len(notes) == 1
- let readme .= "one note"
- else
- let readme .= len(notes) . " notes"
- endif
- if a:title_filter != ''
- let quote_format = xolox#notes#unicode_enabled() ? '‘%s’' : "`%s'"
- let readme .= " matching " . printf(quote_format, a:title_filter)
- endif
- " Explain the sorting of the notes.
- if empty(notes)
- let readme .= "."
- elseif len(notes) == 1
- let readme .= ", it's listed below."
- else
- let readme .= ". They're listed below grouped by the day they were edited, starting with your most recently edited note."
- endif
- " Add the generated text to the buffer.
- call setline(1, ["Recent notes", "", readme])
- " Reformat the text in the buffer to auto-wrap.
- normal Ggqq
- " Sort, group and format the list of (matching) notes.
- let last_date = ''
- let list_item_format = xolox#notes#unicode_enabled() ? ' • %s' : ' * %s'
- call sort(notes)
- call reverse(notes)
- let lines = []
- for [ftime, title] in notes
- let date = xolox#notes#friendly_date(ftime)
- if date != last_date
- call add(lines, '')
- call add(lines, substitute(date, '^\w', '\u\0', '') . ':')
- let last_date = date
- endif
- call add(lines, printf(list_item_format, title))
- endfor
- " Add the formatted list of notes to the buffer.
- call setline(line('$') + 1, lines)
- " Load the notes file type.
- call xolox#notes#set_filetype()
- let &l:statusline = bufname
- " Change the status line
- " Lock the buffer contents.
- call xolox#misc#buffer#lock()
- " And we're done!
- call xolox#misc#timer#stop("notes.vim %s: Generated %s in %s.", g:xolox#notes#version, bufname, starttime)
-endfunction
-
" Miscellaneous functions. {{{1
function! xolox#notes#find_directories(include_shadow_directory) " {{{2
View
@@ -31,8 +31,9 @@ Contents ~
2. Accelerated searching with Python |notes-accelerated-searching-with-python|
7. The |:RelatedNotes| command
8. The |:RecentNotes| command
- 9. The |:ShowTaggedNotes| command
- 10. The |:IndexTaggedNotes| command
+ 9. The |:MostRecentNote| command
+ 10. The |:ShowTaggedNotes| command
+ 11. The |:IndexTaggedNotes| command
5. Mappings |notes-mappings|
1. Insert mode mappings |notes-insert-mode-mappings|
6. Customizing the syntax highlighting of notes
@@ -422,6 +423,13 @@ the list of notes by matching the title of each note against the argument
which is interpreted as a Vim pattern.
-------------------------------------------------------------------------------
+The *:MostRecentNote* command
+
+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.
+
+-------------------------------------------------------------------------------
The *:ShowTaggedNotes* command
To show a list of all notes that contains @tags you can use the
View
@@ -1,6 +1,6 @@
" Vim file type plug-in
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 5, 2013
+" Last Change: May 16, 2013
" URL: http://peterodding.com/code/vim/notes/
if exists('b:did_ftplugin')
@@ -135,6 +135,7 @@ let b:undo_ftplugin .= ' | execute "vunmap <buffer> <Leader>tn"'
" This is currently the only place where a command is guaranteed to be
" executed when the user edits a note. Maybe I shouldn't abuse this (it
" doesn't feel right ;-) but for now it will do.
+call xolox#notes#recent#track()
call xolox#notes#check_sync_title()
" vim: ts=2 sw=2 et
View
@@ -1,6 +1,6 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 12, 2013
+" Last Change: May 16, 2013
" URL: http://peterodding.com/code/vim/notes/
" Support for automatic update using the GLVS plug-in.
@@ -19,7 +19,8 @@ command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(<q-bang>, <q-args>)
command! -bang -nargs=? -complete=customlist,xolox#notes#keyword_complete SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
-command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)
+command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent#show(<q-bang>, <q-args>)
+command! -bar -bang MostRecentNote call xolox#notes#recent#edit(<q-bang>)
command! -bar -count=1 ShowTaggedNotes call xolox#notes#tags#show_tags(<count>)
command! -bar IndexTaggedNotes call xolox#notes#tags#create_index()

0 comments on commit 7c0d08b

Please sign in to comment.