我想要一个交互式函数,它只使用模式的单行注释语法来注释或取消注释区域.
目前,在PHP中,当我注释掉时(使用comment-or-uncomment-region或者comment-dwim)
This
Block of
Code
Run Code Online (Sandbox Code Playgroud)
我明白了:
/*
* This
* Block of
* Code
*/
Run Code Online (Sandbox Code Playgroud)
但我需要的是:
// This
// Block of
// Code
Run Code Online (Sandbox Code Playgroud)
我尝试过(不,让我重新说一下:我花了几个小时尝试每一种可能的组合)使用M-x customize-group RET comment,特别是变量comment-multi-line,comment-style但无济于事.
请注意,当我编辑Javascript时,js-mode就是这样做的.如何在所有模式下获得此行为?
尝试这个:
(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))
Run Code Online (Sandbox Code Playgroud)
在 Emacs 24.3 中,您可以改用该表单(setq-local comment-start "//")。