For the indentation after the |
you should be able to get the right result by going to the incorrect line (i.e. the one that starts with grep
) and then do M-x smie-config-set-indent RET before "|" RET nil RET
.
But smie-config is not up to the task when it comes to tweaking the behavior of the close paren in the way you want. For that you'll need actual code. One possible approach could look like:
(defun my-sh-indent-rules ()
(when (eq ?= (char-before))
(skip-chars-backward "[:alnum:]_=")
(current-column)))
(add-hook 'sh-mode-hook
(lambda ()
(add-hook 'smie-indent-functions
#'my-sh-indent-rules
nil 'local)))
BTW, if you want to handle the |
alignment "by hand" rather than via smie-config
, you could do it this way:
(defun my-sh-smie-rules (orig-fun kind token)
(pcase (cons kind token)
(`(:before . "|") nil)
(_ (funcall orig-fun kind token))))
(advice-add 'sh-smie-sh-rules :around #'my-sh-smie-rules)
wef: This is the final bit of the puzzle that Stefan gave me in my muddle below - how to save the customisations for next time. As he said, I needed to teach smie
about my preferences eg with M-x smie-config-set-indent
then run M-x smie-config-save
and look at the variable smie-config
. Finally, I copied those rules (in my case, just one rule) into .emacs
:
(defun my-sh-indent-rules ()
(smie-config-local '((nil :before "|" (column . 8)))))
(add-hook 'smie-indent-functions #'my-sh-indent-rules)
There may be other ways to do this eg with the commands in sh-mode
eg M-x sh-learn-line-indent
- but I wasn't able to get it to work.