How to Get Org-Mode Filetags

I recently needed to change the behavior of a library (org-download) based on the tags of the current buffer. Most of the answers I found online are incorrect (and so was ChatGPT) for Org version 9.5.

Here’s how to get the filetags of an org-mode buffer or file programatically:

(org-collect-keywords '("FILETAGS"))

I used this to write a function to check whether or not the org-mode file was private or not.

(defun my/org-file-is-private ()
    (let ((tags (car (cdr (car (org-collect-keywords '("FILETAGS")))))))
      (if (stringp tags)
          (member "private" (split-string tags))
        nil)))
  • Show All Buffer Local Variables in an Emacs Buffer

    Sometimes using Emacs you want to know what variables are being set in the current buffer. C-h v lists all the variables, including buffer-local variables in the minibuffer which you can then search and refine just like any other minibuffer session. This is really handy when you customized some settings using hooks and want to verify they took. For example, setting the org-download directory based on filetags.