emacs 主要模式字符之间的字体锁定(括号、引号等)

标签 emacs syntax lisp syntax-highlighting mode

我正在尝试设置一个 emacs 主要模式,它基本上只是以不同颜色突出显示许多不同字符之间的文本。我有方括号:

(font-lock-add-keywords nil '(("\\[\\(.*\\)\\]"
                             1 font-lock-keyword-face prepend)))

但是当我尝试用其他字符替换 [] 时,它停止工作。例如,圆括号“()不起作用:

(font-lock-add-keywords nil '(("\\(\\(.*\\)\\)"
                             1 font-lock-function-name-face prepend)))

尝试单引号、双引号或反引号等也不起作用。我完全不熟悉 lisp-syntax --- 我做错了什么?另外:有什么办法可以包含括在表达式中的字符吗?

最佳答案

您正在混合使用正则表达式和正则字符串。

试试这些:

;; square brackets - escape the first one so you don't get a [..] regexp
(font-lock-add-keywords nil '(("\\(\\[.*]\\)"
                         1 font-lock-keyword-face prepend)))

;; parentheses - don't escape the parentheses you want to match!
(font-lock-add-keywords nil '(("\\((.*)\\)"
                         1 font-lock-keyword-face prepend)))

;; quotes - single escape so you don't break your string:
(font-lock-add-keywords nil '(("\\(\".*\"\\)"
                         1 font-lock-keyword-face prepend)))

;; other characters - not regexps, so don't escape them:
(font-lock-add-keywords nil '(("\\('.*'\\)"
                         1 font-lock-keyword-face prepend)))
(font-lock-add-keywords nil '(("\\(<.*>\\)"
                         1 font-lock-keyword-face prepend)))

关于emacs 主要模式字符之间的字体锁定(括号、引号等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19499757/

相关文章:

recursion - 调试简单的 LISP 函数。

lisp - 具有更高级别功能的 lisp 中的二进制搜索

emacs - 在 emacs 中,如何引用物理屏幕?

emacs - 你对 Emacs 的包管理器有什么期望?

java - 新的 Java 8+ 分隔符(标点符号)——它们如何/在哪里使用?

oop - 为什么协议(protocol)的关联类型在 Swift 中不使用泛型语法?

syntax - 满足条件时在SPSS语法中强制错误

lisp - 方案:关于条件

emacs - 在 Emacs 中,如何在多个帧中打开相同的缓冲区(使用 ido/iswitch 时)?

javascript - Emacs 中的 Node REPL 打印我的输入