6

In c-mode comment-region is adding /* */ style comments.

Is there a way to default to using C++ style // prefix in C source files instead?

ideasman42
  • 8,375
  • 1
  • 28
  • 105

2 Answers2

7

This can be done by changing comment-start & comment-end.

(add-hook 'c-mode-hook (lambda () (setq comment-start "//"
                                        comment-end   "")))

Found the answer after further searching here

ideasman42
  • 8,375
  • 1
  • 28
  • 105
2

Support for toggling between block-style and line-style comments was added a few months ago, and should be included in the next release.

If you have a snapshot of the development version of emacs (from master after June 15, 2017), you can use (c-toggle-comment-style) to toggle the comment style.

See http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=7a2038d7c887e4fa08a91950a7494d1dd20c39e1

And the related conversation on emacs-devel: http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=7a2038d7c887e4fa08a91950a7494d1dd20c39e1

EDIT:

To enable them by default:

(add-hook 'c-mode-hook (lambda () (c-toggle-comment-style -1)))

T. Verron
  • 4,233
  • 1
  • 22
  • 55
Toon Claes
  • 246
  • 1
  • 7