2

I use fixed tags for tasks and notes. These are tags either represent different physical places where I do my tasks (e.g. @home or @errands), or represent different areas of responsibility for me (e.g. %FAMILY, %HOME, %CAR). I define these tags by mean of org-tag-alist.

However, these tags are of little relevance when I want to tag my journal entries, which are mainly reflections of political, philosophical and ethical nature. Can I have another tag list for journal entries, or could I get a tag list to chose from which only consists of tags already used within the journal.org file? The %^g and %^G tools gives me all tasks used in my journal.org file AS WELL as those defined by org-tag-alist.

2

Refer to the Org manual section on Settings tags. It sounds like you have multiple org files, so you can specify a set of tags per file using the #+TAGS: option line.

If you want a defined set of tags in all files except your journal, you can use org-tag-alist but put an empty TAGS option in the journal file. Then you can use dynamic tags and %^g in that one file.

Update

As noted in the comments, using an empty #TAGS+: line to prevent the org-tag-alist from being used in a specific file does not seem to work, despite being described in the manual. I'll investigate a bit more and file a bug.

  • Thanks for your answer. I tried to put #+TAGS: in the toprow of my journal.org file, but it did not prevent the fixed tags definitions from org-tag-alist to show up. Your method should only get me the tags used locally in that file, right? – myotis Aug 19 '15 at 20:25
  • Did you try either re-loading the file or hitting C-c C-c on the TAGS line to apply the change? The org manual mentions this case directly: "If you have globally defined your preferred set of tags using the variable ‘org-tag-alist’, but would like to use a dynamic tag list in a specific file, add an empty TAGS option line to that file..." – glucas Aug 19 '15 at 20:29
  • yes, but what is the point of using the %^g mechanism in the capture code then? If I have to relocate the headline after I have made it to press C-c C-c? – myotis Aug 19 '15 at 20:33
  • Sorry, I was unclear. An options line like #+TAGS: is applied automatically when an org file is loaded, even if it is loaded via a capture template. However when you first type in the option line, it is not immediately applied. You need to close and re-visit the file, or you need to use C-c C-c to tell org that you want to read/apply that line. – glucas Aug 19 '15 at 20:35
  • Hm, I have #+TAGS: as the first line, and I have reloaded the whole emacs, but when adding entries to my journal file all predefined tags show up. and if I add tags afterwards, by using C-c C-c, the same set of tags show up.. – myotis Aug 19 '15 at 20:38
0

I was also looking for a way to set my tag alist in a different way on a per directory basis. There is no clean way but it's possible.

I will start with the negative results of my investigation:

  1. Setting org-tag-alist as a buffer-local on org-mode-hook has no effect.
  2. Setting org-tag-alist as a file/directory-local has no effect.

The underlying reason is that org-mode computes org-current-tag-alist from org-tag-alist almost immediately after starting and uses org-current-tag-alist afterwards. The extension points (1) and (2) above run too late to be useful.

Another option is to override org-current-tag-alist on org-mode-hook:

      (setq org-current-tag-alist
            (org--tag-add-to-alist my-org-tag-alist
                                   org-current-tag-alist))))

but be aware that this fails in some scenarios. For example, after calling the agenda org-current-tag-alist is recomputed for every agenda file.

The more robust option seems to be setting a before-advice. See the following example taken from my init.el that prepends a tag alist to the global one when under the ~/gtd/ directory:

(defun my-org-gtd-tag-advice (&rest _)
  (when (string-prefix-p (expand-file-name "~/gtd/") buffer-file-name)
    (setq-local org-tag-alist
                (org--tag-add-to-alist
                 '((:startgroup . nil)
                   ("@casa" . ?c) ("@oficina" . ?o) ("@viaje" . ?v)
                   (:endgroup . nil)
                   ("PROJECT" . ?p))
                 (default-value 'org-tag-alist)))))
(advice-add #'org-set-regexps-and-options :before #'my-org-gtd-tag-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.