我正在尝试为Twig创建一个次要模式,语法与 django 非常相似,我想更改注释样式的值以使用 {# 和 #}
如果我做
(setq comment-start "{#")
(setq comment-end "#}")
运行正确,但是当更改为 lisp 模式时,注释端仍然是“#}”而不是“”
代码在这里
谢谢
You need to make them buffer-local
by adding this:
(set (make-local-variable 'comment-start) "{#")
(set (make-local-variable 'comment-end) "#}")
to the define-minor-mode
body.
您可以按照有关如何根据次要模式更改光标的答案来做一些事情:
(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))))