如何在emacs次要模式中设置comment-start和comment-end?

时间:2013-01-07 17:00:50

标签: emacs lisp elisp

我正在尝试为Twig创建次要模式,语法与django非常相似,我想更改注释样式的值以使用{#和#}

如果我这样做

(setq comment-start "{#")
(setq comment-end "#}") 

正确运行,但当更改为lisp-mode时,注释结尾仍然是“#}”而不是“”

代码为here

由于

2 个答案:

答案 0 :(得分:3)

您需要添加以下内容buffer-local

(set (make-local-variable 'comment-start) "{#")
(set (make-local-variable 'comment-end) "#}")

define-minor-mode身体。

答案 1 :(得分:1)

您可以根据how to change the cursor based on a 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))))
相关问题