我正在尝试为 Twig 创建一个次要模式,语法与 django 非常相似,我想更改注释样式的值以使用 {# 和 #}
如果我这样做
(setq comment-start "{#")
(setq comment-end "#}")
正确运行,但是当更改为 Lisp 模式时,注释结束仍然是"#}"而不是 ">
代码在这里
谢谢
您需要
通过添加以下内容来使它们buffer-local
:
(set (make-local-variable 'comment-start) "{#")
(set (make-local-variable 'comment-end) "#}")
到define-minor-mode
身体。
您可以按照有关如何根据次要模式更改光标的答案进行操作:
(defvar twig-mode-previous-comments nil
"Storage for comment start/end that was before twig mode was enabled")
(define-minor-mode twig-mode "twig" :lighter ""
(unless twig-mode-previous-comments
(set (make-local-variable 'twig-mode-previous-comments) (cons comment-start comment-end)))
(if twig-mode
(progn
(set (make-local-variable 'comment-start) "{#")
(set (make-local-variable 'comment-end) "#}"))
(setq comment-start (car twig-mode-previous-comments))
(setq comment-end (cdr twig-mode-previous-comments))))