以下答案使用了内置机制org-mode.变量org-tag-faces接受标记的正则表达式,该标记是carcons单元格.该函数org-set-tag-faces设置一个全局变量org-tags-special-faces-re,该变量组合了上述cons单元的标签.全局变量org-tags-special-faces-re被用于通过org-font-lock-add-tag-faces对re-search-forward通过所述org-mode缓冲器-定位所述匹配的标签和应用基于该函数的适当的面org-get-tag-face.该函数的原始版本org-get-tag-face查找找到的标记的完全匹配(即key函数的参数assoc).修改后的版本org-get-tag-face添加了一个额外的key搜索@.*并返回正确的面,如果key找到 - 这是必要的,因为标签本身通常看起来像@home或@office,而我们的上下文regexp是@.*.
(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)))
Run Code Online (Sandbox Code Playgroud)