Emacs模式多行注释

Dav*_*hme 10 emacs elisp

在emacs模式中定义多行注释的正确方法是什么(如C的/**/)?我看到的elisp示例是用于以单个分隔符开头并以行尾结束的注释(如C++的//或perl的#).

Tom*_*ham 16

就像这样:

(define-derived-mode my-mode
    awk-mode "my"
    "My mode"
  (setq comment-multi-line nil) ; maybe
  (setq comment-start "/* ")
  (setq comment-end "*/"))
Run Code Online (Sandbox Code Playgroud)

但有一些微妙之处; 也许你想要

/*  line one   */
/*  line two   */
/*  line three */
Run Code Online (Sandbox Code Playgroud)

或许你想要

/*  
    line one
    line two
    line three
*/
Run Code Online (Sandbox Code Playgroud)

这受您的影响comment-style,您可以自定义(M-x customize-variable comment-style).对于类似第一个示例的选择indent,对于第二个示例,选择extra-line.

它都是定义的newcomment.el,你可以阅读它M-x describe-variable comment-start.