我正在使用 org-mode
我希望我所有的标签都以 @
开头被染成蓝色。
有可能吗?怎么做?
此致
最佳答案
以下答案使用了 org-mode
的内置机制.变量 org-tag-faces
接受标签的正则表达式,即 car
的缺点细胞。函数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
buffer -- 根据函数org-get-tag-face
定位匹配的标签并应用适当的人脸.原版功能org-get-tag-face
寻找找到的标签的完全匹配(即 key
函数的参数 assoc
)。 org-get-tag-face
修订版添加一个额外的 key
搜索 @.*
如果 key
返回正确的面孔找到了——这是必要的,因为标签本身通常看起来像 @home
或 @office
,而我们的上下文正则表达式是 @.*
.
(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)))
关于emacs - 基于正则表达式 emacs 组织模式的颜色标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40876294/