Emacs: one-line comments every time, everywhere

I need an interactive function that will have comments or uncommentations using only a single-line comment of the mode syntax.

Currently in PHP, when I comment (using comment-or-uncomment-region or comment-dwim )

 This Block of Code 

I get this:

 /* * This * Block of * Code */ 

But I need the following:

 // This // Block of // Code 

I tried (no, let me rephrase this: I spent nights trying to use any possible combination) to use the Mx customize-group RET comment , in particular the comment-multi-line and comment-style variables, but to no avail.

Note that when I edit Javascript, js-mode does just that. How can I get this behavior in all modes?

+6
source share
1 answer

Try the following:

 (add-hook 'php-mode-hook 'my-php-mode-hook) (defun my-php-mode-hook () (set (make-local-variable 'comment-start) "//") (set (make-local-variable 'comment-padding) " ") (set (make-local-variable 'comment-end) "") (set (make-local-variable 'comment-style) 'indent)) 

In Emacs 24.3, you can use the form (setq-local comment-start "//") instead (setq-local comment-start "//") .

+4
source

All Articles