简体   繁体   中英

Automatically assigning tags in org-mode

I hate assigning tags when the tag already exists in the headline. I'd like to figure out a way to have org-mode evaluate a headline (preferably right after I hit "enter") and, if it contains any words that match tags in my org-tag-alist, have those tags created for the headline.

As an example:

If I have various individual's names and various project names and possibly even terms like "today", "tomorrow", and "next week" already in my org-tag-alist then, when I type something like:

"TODO Remember to ask Joe tomorrow about the due dates for the XYZ project." and hit enter, then the headline would be evaluated and the tags :Joe:XYZ:Tomorrow: would be generated for the item.

Has anyone seen something like this or have a suggestion as to how I could go about it myself?

This function gets the headline of the entry the point is one, splits it into words and adds as a tag any word it finds in either org-tag-alist or org-tag-persistent-alist

(defun org-auto-tag ()
  (interactive)
  (let ((alltags (append org-tag-persistent-alist org-tag-alist))
        (headline-words (split-string (org-get-heading t t)))
        )
    (mapcar (lambda (word) (if (assoc word alltags)
                             (org-toggle-tag word 'on)))
            headline-words))
    )

It might be useful to add a function like this to org-capture-before-finalize-hook to automatically tag newly captured entries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM