如何在Emacs中不突出显示注释中的值?

问题描述 投票:3回答:2

我想在某些配置文件中突出显示true和false值。我有这样做:

(defun my/highlight-in-properties-files ()
  "Highlight regexps in PROPERTIES files."
  (when (string-match-p ".properties" (file-name-nondirectory buffer-file-name))
    (highlight-regexp "true" 'hi-green)
    (highlight-regexp "false" 'hi-pink)))

但是它也会在注释中突出显示这些值:

enter image description here

是否可以排除那些突出显示?

UPDATE-highlight-regexp是“ hi-lock.el”中“ hi-lock-face-buffer”的别名。 string-match-p是“ subr.el”中已编译的Lisp函数。

regex emacs comments syntax-highlighting
2个回答
1
投票

一种方法是在正则表达式的末尾简单地添加一个$以不匹配注释,因为对/总是在末尾,而注释中的总是在句子的中间] >

(defun my/highlight-in-properties-files ()
  "Highlight regexps in PROPERTIES files."
  (when (string-match-p ".properties" (file-name-nondirectory buffer-file-name))
    (highlight-regexp "true$" 'hi-green)
    (highlight-regexp "false$" 'hi-pink)))

1
投票

您可以仅通过font-lock-add-keywords添加正则表达式,这已经说明了缓冲区中的注释语法,例如。

© www.soinside.com 2019 - 2024. All rights reserved.