Skip to content

Commit

Permalink
Include untagged notes in :ShowTaggedNotes output (suggested by Jacob…
Browse files Browse the repository at this point in the history
…o de Vera in issue #7)
  • Loading branch information
xolox committed Sep 17, 2011
1 parent 1021528 commit 60526a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions autoload/xolox/notes.vim
@@ -1,12 +1,12 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: September 17, 2011
" Last Change: September 18, 2011
" 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.11.2'
let g:xolox#notes#version = '0.11.3'

function! xolox#notes#shortcut() " {{{1
" The "note:" pseudo protocol is just a shortcut for the :Note command.
Expand Down
45 changes: 38 additions & 7 deletions autoload/xolox/notes/tags.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: September 17, 2011
" Last Change: September 18, 2011
" URL: http://peterodding.com/code/vim/notes/

if !exists('s:currently_tagged_notes')
Expand Down Expand Up @@ -117,18 +117,43 @@ function! xolox#notes#tags#show_tags(minsize) " {{{1
if empty(s:currently_tagged_notes)
call add(lines, "You haven't used any tags yet!")
else
let bullet = xolox#notes#get_bullet('*')
" Create a dictionary with note titles as keys.
let unmatched = {}
for title in xolox#notes#get_titles(0)
let unmatched[title] = 1
endfor
" Group matching notes and remove them from the dictionary.
let grouped_notes = []
let numtags = 0
for tagname in sort(keys(s:currently_tagged_notes), 1)
let friendly_name = xolox#notes#tags#friendly_name(tagname)
let numnotes = len(s:currently_tagged_notes[tagname])
if numnotes >= a:minsize
let matched_notes = s:currently_tagged_notes[tagname]
for title in matched_notes
if has_key(unmatched, title)
unlet unmatched[title]
endif
endfor
call add(grouped_notes, {'name': tagname, 'notes': matched_notes})
let numtags += 1
endif
endfor
" Add a "fake tag" with all unmatched notes.
if !empty(unmatched)
call add(grouped_notes, {'name': "Unmatched notes", 'notes': keys(unmatched)})
endif
" Format the results as a note.
let bullet = xolox#notes#get_bullet('*')
for group in grouped_notes
let tagname = group['name']
let friendly_name = xolox#notes#tags#friendly_name(tagname)
let numnotes = len(group['notes'])
if numnotes >= a:minsize
call extend(lines, ['', printf('# %s (%i note%s)', friendly_name, numnotes, numnotes == 1 ? '' : 's'), ''])
for title in s:currently_tagged_notes[tagname]
for title in group['notes']
let lastmodified = xolox#notes#friendly_date(getftime(xolox#notes#title_to_fname(title)))
call add(lines, ' ' . bullet . ' ' . title . ' (last edited ' . lastmodified . ')')
endfor
let numtags += 1
endif
endfor
if a:minsize <= 1
Expand All @@ -140,9 +165,15 @@ function! xolox#notes#tags#show_tags(minsize) " {{{1
\ numtags == 1 ? "tag" : "tags",
\ numtags == 1 ? "has" : "have", a:minsize)
endif
let message .= ", "
let message .= numtags == 1 ? "it's" : "they're"
let message .= ", " . (numtags == 1 ? "it's" : "they're")
let message .= " listed below. Tags and notes are sorted alphabetically and after each note is the date when it was last modified."
if !empty(unmatched)
if a:minsize <= 1
let message .= " At the bottom is a list of untagged notes."
else
let message .= " At the bottom is a list of unmatched notes."
endif
endif
if numtags > 1 && !(&foldmethod == 'expr' && &foldenable)
let message .= " You can enable text folding to get an overview of just the tag names and how many times they've been used."
endif
Expand Down

0 comments on commit 60526a3

Please sign in to comment.