如何为主模式定义注释语法?

Pat*_*ins 5 emacs comments dot-emacs

我想为我使用的主要模式添加注释,这些模式目前不支持它们.我在网上找到的唯一例子显示了如何编写单行注释,但我需要配对分隔符.

我需要改变什么?

Pat*_*ins 4

我最终深入研究了我正在使用的包的省略号。问题是如果你添加

(setq comment-start "FOO")
(setq comment-end "BAR")
Run Code Online (Sandbox Code Playgroud)

到your-mode-hook,然后,当您切换到另一种定义comment-start但不定义的语言时comment-end,您最终会坚持comment-end使用另一种模式。例如,您的python-mode评论如下:

# def my_func(): BAR
Run Code Online (Sandbox Code Playgroud)

这绝对不是你想要的。为了解决这个问题,请使用以下命令:

(add-hook 'your-mode-hook
          (lambda ()
            (set (make-local-variable 'comment-start) "FOO")
            (set (make-local-variable 'comment-end) "BAR")))
Run Code Online (Sandbox Code Playgroud)

而且它不会破坏其他模式comment-end。