如何在 Emacs 次要模式下设置注释开始和注释结束



我正在尝试为 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))))

最新更新