Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs mode multiline comments

Tags:

emacs

elisp

What's the correct method for defining multi-line comments in an emacs mode (like C's /* */)? The elisp examples I see are for comments that start with a single delimiter and end at the end of the line (like C++'s // or perl's #).

like image 380
David Nehme Avatar asked Jan 31 '09 17:01

David Nehme


People also ask

How do I uncomment multiple lines in Emacs?

It is bound to menu-bar edit region comment-region. Comment or uncomment each line in the region. With just C-u prefix arg, uncomment each line in region BEG .. END .

Can comments also span multiple lines?

On the other hand, multi-line comments can span many lines or be placed within a code statement and only the content between the comment delimiters will be treated as the comment and ignored during compilation.

How do I comment multiple lines in terminal?

Using the up and down arrow key, highlight the lines you wish to comment out. Once you have the lines selected, press the SHIFT + I keys to enter insert mode. Enter your command symbol, for example, # sign, and press the ESC key. Vim will comment out all the highlighted lines.

What is the syntax of multi-line comments?

/* */ (multiline comment) Multiline comments are used for large text descriptions of code or to comment out chunks of code while debugging applications. Comments are ignored by the compiler.


3 Answers

It's like this:

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

But there are subtleties; maybe you want

/*  line one   */
/*  line two   */
/*  line three */

or maybe you want

/*  
    line one
    line two
    line three
*/

This is affected by your comment-style, which you can customize (M-x customize-variable comment-style). For something like the first example choose indent, for the second example, extra-line.

It's all defined in newcomment.el, which you can read about if you M-x describe-variable comment-start.

like image 94
Tom Dunham Avatar answered Oct 19 '22 05:10

Tom Dunham


Tom's answer covers creating comments; if you want your mode to be aware of comments, you need to fixup the syntax table.

Relevant reading:

http://www.gnu.org/software/emacs/elisp/html_node/Syntax-Tables.html#Syntax-Tables

like image 23
jrockway Avatar answered Oct 19 '22 05:10

jrockway


This is an excellent guide for adding comment goo to an emacs mode. Link

like image 40
josefwells Avatar answered Oct 19 '22 05:10

josefwells