2

org-mode has the org-file-tags variable which is populated by the #+FILETAGS cookie at the file level.

Would it be possible to specify file tags at directory level and still be able to specify additional file level tags inside the individual files?

For example, to have this in .dir-locals.el, to mark all files in the "work" folder as "work":

(("work" . ((org-mode . ((org-file-tags . '("work")))))))

and have in work/project1.org:

#+FILETAGS: :project1:

* Header
This header has both tags 'work' and 'project1'.

The problem with this setup is that the value in .dir-locals.el overwrites the local file tags, while I would like to have them merged.

1
  • 1
    I don't have an answer for this, but when I tried to reproduce, I found out that (org-file-tags . "work") should be (org-file-tags . '("work")). Note the s of "tags". Jul 27 at 15:03
1

You could try this advice solution. It seems to work for me.

The idea is get the filetags line and read it in a temp buffer, and then combine them with the original tags.

The cadr line is a little odd, but the tags sometimes came out as quoted list, and that is how I unquoted it.

(defun get-buffer-filetags-advice (orig-func &rest args)
  (let ((orig-tags (apply orig-func args))
    (ft (cadr (assoc "FILETAGS"
             (org-collect-keywords
              '("FILETAGS"))))))
    (when (eq 'quote (car orig-tags)) (setq orig-tags (cadr orig-tags)))
    (delete-dups
     (apply #'append orig-tags
        (with-temp-buffer
          (insert "#+filetags: " ft)
          (org-mode)
          (org-get-buffer-tags))))))

(advice-add 'org-get-tags :around 'get-buffer-filetags-advice)

;; to remove the advice
;; (advice-remove 'org-get-tags 'get-buffer-filetags-advice)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.