Emacs: Einrückung nach && im Shell-Script-Modus unterdrücken

478
Lasse Kliemann

Wenn im Shell-Script-Modus eine Zeile endet &&, wird Emacs die folgende Zeile einrücken. Gibt es eine Möglichkeit, das auszuschalten? (Die meisten meiner Aussagen werden mit verkettet &&. Dies gibt eine genauere Kontrolle über die Fehlerbehandlung als set -e.)

3

1 Antwort auf die Frage

1
Stefan

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.
  • type M-x smie-config-show-indent which 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

Sadly the (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 smie-config-set-indent).

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.