我为 Standard ML 编写了一个非常简单的 Emacs 模式:
;; sml syntax
(require 'generic-x)
(define-generic-mode
'sml-mode ;; name of the mode
'(("(*" . "*)")) ;; comments delimiter
'("fun" "fn" "let" "val" "datatype" "type" "case" "of" "end" "structure" "struct" "signature" "sig")
'(("=" . 'font-lock-builtin-face)
("|" . 'font-lock-builtin-face)
(">" . 'font-lock-builtin-face)
("<" . 'font-lock-builtin-face)
("-" . 'font-lock-builtin-face)
("+" . 'font-lock-builtin-face)
(";" . 'font-lock-builtin-face)
("," . 'font-lock-builtin-face)
("{" . 'font-lock-builtin-face)
("}" . 'font-lock-builtin-face)
("(" . 'font-lock-builtin-face)
(")" . 'font-lock-builtin-face)
(":" . 'font-lock-builtin-face)
("[" . 'font-lock-builtin-face)
("]" . 'font-lock-builtin-face)) ;; a built-in
'("\\.sml$") ;; files that trigger this mode
nil ;; any other functions to call
"SML highlighting mode" ;; doc string
)
但是,它不会一致地缩进。我无法准确描述它是如何缩进的,但它在制表符和空格以及空格长度之间的切换不一致。我能想到的最简单的规则是始终在同一列上开始一个新行,并且制表符总是将您带到下一列是 4 的倍数。制表符应该是空格。如何使用通用模式执行此操作?
作为模式定义的注释,我错误地使用了内置面,因为操作员面没有着色。不过现在看起来确实很丑。