Where parallels cross

Interesting bits of life

How to count your Org Agenda tags

You may wonder how many tags are you using in your Org Mode agenda files.

This Elisp snippet does it for you:

(require 'dash)

(defmacro with-file (file &rest body)
  "Open FILE, execute BODY close FILE if it was not already open."
  `(let ((old-buffer (current-buffer))
         (kill-buffer-p (not (get-file-buffer ,file))))
     (unwind-protect
         (progn
           (find-file ,file)
           ,@body)
       (progn
         (when kill-buffer-p (kill-buffer))
         (switch-to-buffer old-buffer)))))

(--> org-agenda-files
     (--map (with-file it (org-get-buffer-tags)) it)
     -flatten
     -distinct
     length)

Just remove the last length to see the tags.

Update: at Irreal there is a simpler approach to do this :)

Comments