11" Vim auto-load script
22" Author: Peter Odding <peter@peterodding.com>
3- " Last Change: September 17 , 2011
3+ " Last Change: September 18 , 2011
44" URL: http://peterodding.com/code/vim/notes/
55
66if ! exists (' s:currently_tagged_notes' )
@@ -117,18 +117,43 @@ function! xolox#notes#tags#show_tags(minsize) " {{{1
117117 if empty (s: currently_tagged_notes )
118118 call add (lines , " You haven't used any tags yet!" )
119119 else
120- let bullet = xolox#notes#get_bullet (' *' )
120+ " Create a dictionary with note titles as keys.
121+ let unmatched = {}
122+ for title in xolox#notes#get_titles (0 )
123+ let unmatched[title ] = 1
124+ endfor
125+ " Group matching notes and remove them from the dictionary.
126+ let grouped_notes = []
121127 let numtags = 0
122128 for tagname in sort (keys (s: currently_tagged_notes ), 1 )
123- let friendly_name = xolox#notes#tags#friendly_name (tagname)
124129 let numnotes = len (s: currently_tagged_notes [tagname])
130+ if numnotes >= a: minsize
131+ let matched_notes = s: currently_tagged_notes [tagname]
132+ for title in matched_notes
133+ if has_key (unmatched, title )
134+ unlet unmatched[title ]
135+ endif
136+ endfor
137+ call add (grouped_notes, {' name' : tagname, ' notes' : matched_notes})
138+ let numtags += 1
139+ endif
140+ endfor
141+ " Add a "fake tag" with all unmatched notes.
142+ if ! empty (unmatched)
143+ call add (grouped_notes, {' name' : " Unmatched notes" , ' notes' : keys (unmatched)})
144+ endif
145+ " Format the results as a note.
146+ let bullet = xolox#notes#get_bullet (' *' )
147+ for group in grouped_notes
148+ let tagname = group[' name' ]
149+ let friendly_name = xolox#notes#tags#friendly_name (tagname)
150+ let numnotes = len (group[' notes' ])
125151 if numnotes >= a: minsize
126152 call extend (lines , [' ' , printf (' # %s (%i note%s)' , friendly_name, numnotes, numnotes == 1 ? ' ' : ' s' ), ' ' ])
127- for title in s: currently_tagged_notes [tagname ]
153+ for title in group[ ' notes ' ]
128154 let lastmodified = xolox#notes#friendly_date (getftime (xolox#notes#title_to_fname (title )))
129155 call add (lines , ' ' . bullet . ' ' . title . ' (last edited ' . lastmodified . ' )' )
130156 endfor
131- let numtags += 1
132157 endif
133158 endfor
134159 if a: minsize <= 1
@@ -140,9 +165,15 @@ function! xolox#notes#tags#show_tags(minsize) " {{{1
140165 \ numtags == 1 ? " tag" : " tags" ,
141166 \ numtags == 1 ? " has" : " have" , a: minsize )
142167 endif
143- let message .= " , "
144- let message .= numtags == 1 ? " it's" : " they're"
168+ let message .= " , " . (numtags == 1 ? " it's" : " they're" )
145169 let message .= " listed below. Tags and notes are sorted alphabetically and after each note is the date when it was last modified."
170+ if ! empty (unmatched)
171+ if a: minsize <= 1
172+ let message .= " At the bottom is a list of untagged notes."
173+ else
174+ let message .= " At the bottom is a list of unmatched notes."
175+ endif
176+ endif
146177 if numtags > 1 && ! (&foldmethod == ' expr' && &foldenable )
147178 let message .= " You can enable text folding to get an overview of just the tag names and how many times they've been used."
148179 endif
0 commit comments