在一个新的并且希望非常简单的 emacs 模式中,我希望每个“a”实例都是#0000FF,“b”是#DF0101。到目前为止,尽管进行了大量谷歌搜索,我还没有找到一种方法来做到这一点。理想情况下,它会在您键入时实时发生。
http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/emacs/Highlight-Interactively.html
http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/emacs/Font-Lock.html#Font-Lock
最佳答案
我将其用于我的 Navi 次要模式:
;; Adding Navi to the syntax highlighting of emacs mode.
首先用他们的颜色制作新面孔,在我的例子中,绿色代表字母“t”的成功字体,青色代表“Navi”和“navi”。
如果需要,请阅读 font-lock .
(make-face 'font-lock-Navi-face)
(set-face-foreground 'font-lock-Navi-face "cyan")
(make-face 'font-lock-success-face)
(set-face-attribute 'font-lock-success-face nil :foreground "green")
现在添加要附加的“关键字”(regexp):
(defun add-custom-keywords()
"adds a few keywords for emacs mode"
;
(font-lock-add-keywords nil
'(
("Navi\\|navi" . 'font-lock-Navi-face)
;; here you can see that I highlight the letter "t" in " t " when spaced,
;; or with a parenthesis\newline around it
("\\s-t\\s-\\|\\s-t)\\|\\s-t\n" . 'font-lock-success-face)
)
)
)
您可以用您的字母“a”或“b”替换 Navi(“or”在此处 “\\|”
)或 navi,因此 “a\\|” b"
然后把脸给它。
; This is the hook to activate when the mode is triggered
(add-hook 'emacs-lisp-mode-hook 'add-custom-keywords)
最后一部分确保此字体将是“实时的”,并且在您每次打开文件时都是如此。
关于emacs - 你如何在 emacs 中给特定的字母上色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14511111/