Emacs:每次都是一行评论

时间:2013-12-20 12:39:17

标签: emacs elisp

我想要一个互动功能,可以使用模式的仅一行注释语法对区域进行评论或取消注释。

目前,在PHP中,当我注释掉时(使用comment-or-uncomment-regioncomment-dwim

This
Block of
Code

我明白了:

/* 
 * This
 * Block of
 * Code
 */

但我需要的是:

// This
// Block of
// Code

我试过(不,让我改一点:我花了很多时间尝试每一种可能的组合)使用M-x customize-group RET comment,特别是变量comment-multi-linecomment-style,但无济于事。

请注意,当我编辑Javascript时,js-mode就是这样做的。如何在所有模式中获得此行为?

1 个答案:

答案 0 :(得分:4)

试试这个:

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

在Emacs 24.3中,您可以改为使用(setq-local comment-start "//")形式。