Subject: bug#23004: 24.5; Why double intent do sh-script.el after "then" statement?

From: Oleksandr Gavenko <[email-masked]>
Date: Sun, 13 Mar 2016 11:34:07 +0200

In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.2)
 of 2015-10-24 on trouble, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11702000
System Description:	Debian GNU/Linux testing (stretch)

  $ emacs -q

  M-x sh-mode RET
  M-: (setq sh-basic-offset 2) RET

  if true; then
      <==TAB  4 spaces!!
  else
    <==TAB  2 spaces
  fi

  if true;
  then
      <==TAB  4 spaces!!
  fi

With default 4 offset indent proper after "then" and "else", but changing
`sh-basic-offset' doesn't effect on indent level after "then".

I check:

  /usr/share/emacs/24.5/lisp/progmodes/sh-script.el.gz

  (defun sh-smie-sh-rules (kind token)
    ....
    ;; Attempt at backward compatibility with the old config variables.
    (`(:before . "fi") (sh-var-value 'sh-indent-for-fi))
    (`(:before . "done") (sh-var-value 'sh-indent-for-done))
    (`(:after . "else") (sh-var-value 'sh-indent-after-else))
    (`(:after . "if") (sh-var-value 'sh-indent-after-if))
    (`(:before . "then") (sh-var-value 'sh-indent-for-then))
    (`(:before . "do") (sh-var-value 'sh-indent-for-do))
    (`(:after . "do")
     (sh-var-value (if (smie-rule-hanging-p)
                       'sh-indent-after-loop-construct 'sh-indent-after-do)))
    ;; sh-indent-after-done: aligned completely differently.
    (`(:after . "in") (sh-var-value 'sh-indent-for-case-label))
    ;; sh-indent-for-continuation: Line continuations are handled differently.
    (`(:after . ,(or `"(" `"{" `"[")) (sh-var-value 'sh-indent-after-open))

I see no (:after . "then") but:

    (`(:after . "else") (sh-var-value 'sh-indent-after-else))
    (`(:before . "then") (sh-var-value 'sh-indent-for-then))

I would like to control indenting after "then" statement. Please add
customisation:

  (defcustom sh-indent-after-then '+
    "How much to indent a statement after an `then' statement."
    :type `(choice ,@ sh-number-or-symbol-list )
    :group 'sh-indentation)

-- 
http://defun.work/