How to make Emacs to indent cases like this
switch ($foo) {
case "foo":
$foo .= " bar";
break
case "bar":
$foo .= " baz";
break
default:
$foo .= " undefined";
}
instead of
switch ($foo) {
case "foo":
$foo .= " bar";
break
case "bar":
$foo .= " baz";
break
default:
$foo .= " undefined";
}
You need to add something like this to your .emacs (either as a general setting or for the specific programming modes you care about):
;; set this in all c-based programming modes
(add-hook 'c-mode-common-hook
(lambda ()
(c-set-offset 'case-label '+)))
to add this to another mode, use the same pattern above with the relevant mode name substituted in for the hook, e.g.: <mode-name>-hook
.