emacs - 基于正则表达式 emacs 组织模式的颜色标签

标签 emacs org-mode

我正在使用 org-mode我希望我所有的标签都以 @ 开头被染成蓝色。
有可能吗?怎么做?

此致

最佳答案

以下答案使用了 org-mode 的内置机制.变量 org-tag-faces接受标签的正则表达式,即 car的缺点细胞。函数org-set-tag-faces设置全局变量 org-tags-special-faces-re ,它结合了上述 cons 单元的标签。全局变量 org-tags-special-faces-reorg-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/

相关文章:

emacs - 我可以在 org-mode 中重新定位省略号 (...)

emacs - 我可以为我现在的位置创建一个稀疏树 - 即制作一个指向路径的组织模式稀疏树吗?

emacs - 是否可以在 org-mode 中使用 Babel 来评估涉及 "cin"的代码块?

emacs - 每周重复任务 emacs org-mode

emacs - 如何让 Emacs 使用 OpenVMS Files-11 样式文件名和版本号创建备份文件?

macos - Emacs 中的 Vim

emacs - 自动创建可重复命令

list - 获取所有 Emacs 缓冲区的列表

emacs - Shift-Tab 在 Emacs 中产生神秘错误

javascript - 在 Javascript 中解析 org-mode 文件