Emacs comment area in C mode

GNU Emacs has 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 tried

 (setq comment-multi-line t) 

but it doesn’t help. There is a multi-line comment section in the Emacs manual , but it does not mention anything.

+7
c emacs elisp
source share
2 answers

Starting with Emacs 21, a module called 'newcomment , which has different comment styles (see the variable 'comment-styles . 'comment-styles close to what you want:

 (setq comment-style 'multi-line) 

(Note: you should probably make this setting in the 'c-mode-hook ).

However, none of the settings makes the comments look like what you want.

The easiest way I've seen to get what you want is to add this hack:

 (defadvice comment-region-internal (before comment-region-internal-hack-ccs activate) "override 4th argument to be just spaces" (when (eq major-mode 'c-mode) ; some condition here (let ((arg (ad-get-arg 4))) (when arg (ad-set-arg 4 (make-string (length arg) ?\ )))))) 

The current settings for comment-style always the prefix of the comment line "*" (if not all "/ *").

If you don't have Emacs 21, I suppose you could just download newcomment.el from the repository. I don't know if it works in previous versions of Emacs, but it might be worth it if Emacs improved the solution.

My hack breaks the 'uncomment-region . The correct fix would be to change the 'comment-padright . This will require a little more research so as not to disturb other things. The aforementioned hacked mode changes the behavior in 'c-mode (adjust the condition to your liking).

+7
source share

Closest I can find built-in support for comments if you set comment-style to multi-line , which will lead to this:

 /* This is a comment which extends * over more than one line in C. */ 

If this is not close enough, take a look at newcomment.el and define your own comment functions.

+3
source share

All Articles