【问题标题】:Emacs: one-line comments every time, everywhereEmacs:随时随地的一行注释
【发布时间】:2013-12-20 12:39:16
【问题描述】:

我想要一个交互式函数,它可以使用 仅使用模式的单行注释语法来评论或取消评论区域

目前,在 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 正是这样做的。如何在所有模式下获得这种行为?

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    试试这个:

    (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 "//") 形式。

    【讨论】:

    • 先生,你让我很开心;为新的 setq-local 语法 +1。
    • 上述comment-style 的设置应该是不必要的(它不一定有害,但它不是 yPhil 要求的一部分,AFAICT)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    相关资源
    最近更新 更多