1
1
" Vim auto-load script
2
2
" Author: Peter Odding <peter@peterodding.com>
3
- " Last Change: September 17 , 2011
3
+ " Last Change: September 18 , 2011
4
4
" URL: http://peterodding.com/code/vim/notes/
5
5
6
6
if ! exists (' s:currently_tagged_notes' )
@@ -117,18 +117,43 @@ function! xolox#notes#tags#show_tags(minsize) " {{{1
117
117
if empty (s: currently_tagged_notes )
118
118
call add (lines , " You haven't used any tags yet!" )
119
119
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 = []
121
127
let numtags = 0
122
128
for tagname in sort (keys (s: currently_tagged_notes ), 1 )
123
- let friendly_name = xolox#notes#tags#friendly_name (tagname)
124
129
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' ])
125
151
if numnotes >= a: minsize
126
152
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 ' ]
128
154
let lastmodified = xolox#notes#friendly_date (getftime (xolox#notes#title_to_fname (title )))
129
155
call add (lines , ' ' . bullet . ' ' . title . ' (last edited ' . lastmodified . ' )' )
130
156
endfor
131
- let numtags += 1
132
157
endif
133
158
endfor
134
159
if a: minsize <= 1
@@ -140,9 +165,15 @@ function! xolox#notes#tags#show_tags(minsize) " {{{1
140
165
\ numtags == 1 ? " tag" : " tags" ,
141
166
\ numtags == 1 ? " has" : " have" , a: minsize )
142
167
endif
143
- let message .= " , "
144
- let message .= numtags == 1 ? " it's" : " they're"
168
+ let message .= " , " . (numtags == 1 ? " it's" : " they're" )
145
169
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
146
177
if numtags > 1 && ! (&foldmethod == ' expr' && &foldenable )
147
178
let message .= " You can enable text folding to get an overview of just the tag names and how many times they've been used."
148
179
endif
0 commit comments