Emacs: подавить отступ после && в shell-script-mode

418
Lasse Kliemann

В режиме shell-script-mode, когда строка заканчивается &&, Emacs будет делать отступ для следующей строки. Есть ли способ выключить это? (Я объединяю большинство моих утверждений с &&. Это дает более точный контроль над обработкой ошибок, чем set -e.)

3

1 ответ на вопрос

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.

Похожие вопросы