C Comment in Emacs - Linux Kernel Style

2019-04-10 13:46发布

问题:

I'm using

(setq-default comment-style 'multi-line)

and my region comments, when doing M-;, are:

/* void main()
 * {
 *  int i;
 *  int b;
 *  printf("format string");
 * } */

But I want them to look like this:

/* 
 * void main()
 * {
 *  int i;
 *  int b;
 *  printf("format string");
 * }
 */

What do I have to change?

回答1:

Try with:

(setq comment-style 'extra-line)


回答2:

Complementing the anler answer and answering my own question.

To use the Linux Kernel commenting Style [1] in emacs, just set this variable in your .emacs/init.el:

(setq comment-style 'extra-line)

To comment/uncomment use M-; after select the region.

To fix needless comment spaces when using tabs see C Comment in Emacs - Linux Kernel Style v2.

[1] https://www.kernel.org/doc/Documentation/CodingStyle