How to add tag completion to org mode capture?

I use the org mode capture function to do all my todo. It is clean and practical, and I can add consistent content to all my todo, including a hint for a title, a hint for tags, and an automatic insertion of the created date. Here is my code:

(setq org-capture-templates '(( "t" ; key "Todo" ; description entry ; type (file+headline "C:/.../org/notes.org" "tasks") ; target "* TODO [#B] %^{Todo} :%^{Tags}: \n:PROPERTIES:\n:Created: %U\n:END:\n\n%?" ; template :prepend t ; properties :empty-lines 1 ; properties :created t ; properties ))) 

However, my invitation for tags forces me to enter tags from memory. How can I add tags from the list of tags set by the following code:

 (setq org-tag-alist `( ("OFFICE" . ?o) ("HOME" . ?h) ("ERRAND" . ?e) )) 

When my point is in the title of an already created task, this list appears when I press Cc Cc and allow me to select tags by their short single letters "o", "h" or "e".

So my question is: is it possible to include this pop-up list of tags in the code for my capture?

+6
source share
1 answer

The built-in solution is to use %^g . Using org-capture-templates :

% ^ g Request tags, ending with the tags in the target file.

% ^ G Hint for tags with completion of all tags in all agenda files.

You can also do this "manually" by calling some function that adds tags. Adding tags is usually done with org-set-tags (this is what Cc Cc does). So, all we need to do is call this in our template with the syntax %(func) :

 (setq org-capture-templates '(( "t" ; key "Todo" ; description entry ; type (file+headline "C:/.../org/notes.org" "tasks") ; target "* TODO [#B] %^{Todo} %(org-set-tags) \n:PROPERTIES:\n:Created: %U\n:END:\n\n%?" ; template :prepend t ; properties :empty-lines 1 ; properties :created t ; properties ))) 

If you have a specific list of tags that you want to select (say org-tag-alist ), you can use completing-read to select it:

 (completing-read "Tag: " (mapcar #'first org-tag-persistent-alist) nil t) 
+7
source

All Articles