Another Look At Counting Org Tags

Andrea over at Where parallels cross has decided to post some shorter tips in addition to the blog’s longer offerings. The first is some Elisp to count the number of tags in your agenda files. When I looked at the code, I thought it was a bit too complicated for what it was trying to do.

My first objection was the onetime use of the macro but it turned out that Andrea already had it so that wasn’t a problem. The real issue is that the code duplicated a lot of already existing functionality. I remembered writing a post a couple of years ago where I needed to list all my agenda tags. It turned out that org-global-tags-completion-table did just that. It also eliminates duplicates and nil entries. In fact, if you look at the code, it does pretty much what Andrea did.

Here, then, is my rendition of counting Org tags:

(require 'dash)

(->> (org-global-tags-completion-table)
     -flatten
     length)
715

One final note. The tags for each file begins with a property string such as

#("JOURNAL" 0 7
 (inherited t))

so you should really subtract the number of agenda files to get an exact count.

This entry was posted in General and tagged . Bookmark the permalink.