The following answer uses the org-mode built-in mechanisms. The variable org-tag-faces accepts a regular expression for the tag, which is the cons cell car . The org-set-tag-faces function sets the global variable org-tags-special-faces-re , which combines the tags of the above cons cell (s). The global variable org-tags-special-faces-re used by org-font-lock-add-tag-faces to re-search-forward through the org-mode buffer - placing the appropriate tags and applying the corresponding face based on the org-get-tag-face function org-get-tag-face . In the original version of the org-get-tag-face function, an exact match was found for the found tag (i.e., the key argument of the assoc function). The revised version of org-get-tag-face adds an additional key search @.* And returns the correct face if key is found - this is necessary because the tag itself will usually look something like @home or @office , while our contextual regexp is @.* .
(require 'org) (add-to-list 'org-tag-faces '("@.*" . (:foreground "cyan"))) ;; Reset the global variable to nil, just in case org-mode has already beeen used. (when org-tags-special-faces-re (setq org-tags-special-faces-re nil)) (defun org-get-tag-face (kwd) "Get the right face for a TODO keyword KWD. If KWD is a number, get the corresponding match group." (if (numberp kwd) (setq kwd (match-string kwd))) (let ((special-tag-face (or (cdr (assoc kwd org-tag-faces)) (and (string-match "^@.*" kwd) (cdr (assoc "@.*" org-tag-faces)))))) (or (org-face-from-face-or-color 'tag 'org-tag special-tag-face) 'org-tag)))
source share