In GNU Emacs, is there a good way to change the comment-region command in C mode from
/* This is a comment which extends */
/* over more than one line in C. */
to
/* This is a comment which extends
over more than one line in C. */
? I have tried
(setq comment-multi-line t)
but this does not help. There is a section on multi-line comments in the Emacs manual, but it does not mention anything.
Since Emacs 21, there's been a module named
'newcomment
, which has different comment styles (see the variable'comment-styles
. This setting gets close to what you want:(Note: you should probably make that setting in
'c-mode-hook
).However, none of the settings make the comments look like what you want.
The easiest way I saw to get what you want is to add this hack:
The current settings for
comment-style
always prefix the comment lines with " * " (if not the whole " /* ").If you don't have Emacs 21, I suppose you could simply download
newcomment.el
from the repository. I don't know if it works as-is in earlier versions of Emacs, but it might be worth a shot, though upgrading Emacs would be a better solution.My hack breaks the
'uncomment-region
. A proper fix would be to change'comment-padright
. That would take a little more research so as not to break other things. The above hack only changes behavior in'c-mode
(adjust the condition to your liking).Closest I could find with the built-in commenting support is if you set
comment-style
tomulti-line
, which will produce this:If that isn't close enough, take a look at
newcomment.el
and define your own commenting functions as appropriate.