In shell-script-mode, when a line ends in
&&, Emacs will indent the following line. Is there a way to switch that off? (I am concatenating most of my statements with
&&. This gives finer control over error handling than
The indentation code for shell scripts has been completely rewritten around the time of Emacs-24 to use SMIE, and SMIE itself has evolved during the life of Emacs-24, so the best solution may depend on your exact Emacs version, but with Emacs-24.5 you should be able to do:
- Go to the line with incorrect indentation.
M-x smie-config-show-indentwhich should show you the rules that were used to indent this line. It might say something like:
Rules used: :before "&&" -> (column . 19), :before "[" -> nil, :elem basic -> 4, :after "&&" -> nil
(column . 19) in there mostly implies that you won't be able to change this behavior in a "simple" way (i.e. you can't change it with
But I think the following should do it:
(defun my-sh-smie-sh-rules (origfun kind token) (pcase (cons kind token) (`(:before . "&&") nil) (_ (funcall origfun kind token)))) (advice-add 'sh-smie-sh-rules :around #'my-sh-smie-sh-rules)
You might like to
M-x report-emacs-bug and request that such a config be made easier, since it's probably a fairly common indentation style.