如何使switch语句中的case在Emacs中缩进

jcu*_*bic 12 php syntax emacs indentation

如何使Emacs缩进这样的情况

switch ($foo) {
    case "foo":
        $foo .= " bar";
        break
    case "bar":
        $foo .= " baz";
        break
    default:
        $foo .= " undefined";
}
Run Code Online (Sandbox Code Playgroud)

代替

switch ($foo) {
case "foo":
    $foo .= " bar";
    break
case "bar":
    $foo .= " baz";
    break
default:
    $foo .= " undefined";
}
Run Code Online (Sandbox Code Playgroud)

jta*_*orn 17

您需要在.emacs中添加这样的内容(作为常规设置或您关注的特定编程模式):

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

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