[英]Derived mode sh-mode like macro variables
I am creating a major mode for some files I constantly use at work and am having some issues displaying macros in a different colour. 我正在为我经常在工作中使用的某些文件创建主要模式,并且在显示以不同颜色显示的宏时遇到了一些问题。 The issue is that the macros occur in strings and they are highlighted as strings even though I set the $ character as the expression character.
问题是,即使我将$字符设置为表达式字符,宏也以字符串形式出现并且被突出显示为字符串。 ie "$(macro1)" is highlighted like a string, not like a macro
即“ $(macro1)”像字符串一样突出显示,而不像宏一样突出显示
In here I try and set the $ character as syntax for an expression, and also sort out the comment syntax as well: 在这里,我尝试将$字符设置为表达式的语法,并且还对注释语法进行排序:
(defvar test-syntax-table nil)
(defvar my-highlights nil)
(setq test-syntax-table
(let ((synTable (make-syntax-table)))
;; bash style comment: “# …”
(modify-syntax-entry ?# "< b" synTable)
(modify-syntax-entry ?\n "> b" synTable)
(modify-syntax-entry ?$ "'" synTable)
synTable))
(setq my-highlights
'(("record" . font-lock-function-name-face)
("field" . font-lock-keyword-face)
("$" . font-lock-variable-name-face)))
In here I set the syntax table and the highlights: 在这里,我设置语法表和重点内容:
;;;###autoload
(define-derived-mode test-mode fundamental-mode
(setq font-lock-defaults '(my-highlights))
(set-syntax-table test-syntax-table)
(setq comment-start "#")
(visual-line-mode 0)
(setq truncate-lines t)
(setq mode-name "test"))
changes: 变化:
(defvar test-mode-syntax-table nil)
(defvar my-highlights nil)
(setq test-mode-syntax-table
(let ((synTable (make-syntax-table)))
;; bash style comment: “# …”
(modify-syntax-entry ?# "< b" synTable)
(modify-syntax-entry ?\n "> b" synTable)
(modify-syntax-entry ?$ "'" synTable)
synTable))
(setq my-highlights
'(
("record" . font-lock-function-name-face)
("field" . font-lock-keyword-face)
("\\$" . (0 font-lock-variable-name-face override))
))
;;;###autoload
(define-derived-mode test-mode fundamental-mode "test"
(setq font-lock-defaults '(my-highlights))
(setq comment-start "#")
(visual-line-mode 0)
(setq truncate-lines t))
You named your derived mode (setq font-lock-defaults '(my-highlights))
. 您将派生模式命名为
(setq font-lock-defaults '(my-highlights))
。 That's a rather quaint choice, I must say. 我必须说,这是一个相当古怪的选择。
So, try to rename test-syntax-table
to test-mode-syntax-table
as god intended, then remove the set-syntax-table
call since the renaming made it redundant, then remove the (setq mode-name "test")
and add "test"
between the parent mode argument and the setting of font-lock-defaults
. 因此,请按照上帝的意图将
test-syntax-table
重命名为test-mode-syntax-table
,然后删除set-syntax-table
调用,因为重命名使其变得多余,然后删除(setq mode-name "test")
并在父模式参数和font-lock-defaults
设置之间添加"test"
。
Then you can try and fix your $
highlighting by using something like ("\\\\$" (0 font-lock-variable-name-face override))
since $
matches the end of line rather than the $
character, and since by default faces are only applied where no other face was applied before (and strings/comments's faces are applied first). 然后,您可以尝试使用类似
("\\\\$" (0 font-lock-variable-name-face override))
的方法来修复$
高亮显示,因为$
匹配行尾而不是$
字符,并且默认情况下仅在之前未应用其他面孔的情况下应用面孔(并且首先应用字符串/注释的面孔)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.