5

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?

1

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)))

  • 1
    Is there a way to set the default? - so toggling each time isn't needed. – ideasman42 Aug 30 '17 at 10:35
  • You still need a hook I think. See updated answer. – Toon Claes Sep 1 '17 at 9:21
6

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

  • You may also be interested in comment-start-skip for certain use cases within c-mode. – lawlist Aug 17 '17 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.