【问题标题】:How to make cases in switch statement to be indented in Emacs如何使 switch 语句中的 case 在 Emacs 中缩进
【发布时间】:2012-01-24 10:50:21
【问题描述】:

如何让 Emacs 像这样缩进大小写

switch ($foo) {
    case "foo":
        $foo .= " bar";
        break
    case "bar":
        $foo .= " baz";
        break
    default:
        $foo .= " undefined";
}

而不是

switch ($foo) {
case "foo":
    $foo .= " bar";
    break
case "bar":
    $foo .= " baz";
    break
default:
    $foo .= " undefined";
}

【问题讨论】:

    标签: php emacs syntax indentation


    【解决方案1】:

    您需要在 .emacs 中添加类似的内容(作为一般设置或您关心的特定编程模式):

    ;; set this in all c-based programming modes
    (add-hook 'c-mode-common-hook
              (lambda ()
                 (c-set-offset 'case-label '+)))
    

    要将其添加到另一个模式,请使用上述相同的模式,并将相关模式名称替换为钩子,例如:<mode-name>-hook

    【讨论】:

    • c-set-offset 绑定到 C-c C-o 如果您需要为特定文件动态调整某些内容。
    • 谢谢。我把 4 作为偏移量,它适用于 php-mode 和 C-mode。你也知道如何为 JavaScript 设置它吗?
    • @jcubic - 你使用什么 javascript 模式?
    • @jcubic - 所以你可以按照我上面添加的注释使用js-mode-hook
    • 是的,我尝试过(也有javascript-mode-hook),但它不适用于 JS。我也尝试在 JS 中设置 statement-case-intro 没有结果
    猜你喜欢
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2014-08-05
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多