Function: sh-smie-sh-rules

sh-smie-sh-rules is a byte-compiled function defined in sh-script.el.gz.

Signature

(sh-smie-sh-rules KIND TOKEN)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/sh-script.el.gz
(defun sh-smie-sh-rules (kind token)
  (pcase (cons kind token)
    ('(:elem . basic) sh-basic-offset)
    ('(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt)
                             (sh-var-value 'sh-indent-for-case-label)))
    (`(:before . ,(or "(" "{" "[" "while" "if" "for" "case"))
     (cond
      ((and (equal token "{") (smie-rule-parent-p "for"))
       (let ((data (smie-backward-sexp "in")))
         (when (equal (nth 2 data) "for")
           `(column . ,(smie-indent-virtual)))))
      ((not (smie-rule-prev-p "&&" "||" "|"))
       (when (smie-rule-hanging-p)
         (smie-rule-parent)))
      (t
       (unless (smie-rule-bolp)
	 (while (equal "|" (nth 2 (smie-backward-sexp 'halfexp))))
	 `(column . ,(smie-indent-virtual))))))
    ;; FIXME: Maybe this handling of ;; should be made into
    ;; a smie-rule-terminator function that takes the substitute ";" as arg.
    (`(:before . ,(or ";;" ";&" ";;&"))
     (if (and (smie-rule-bolp) (looking-at ";;?&?[ \t]*\\(#\\|$\\)"))
         (cons 'column (smie-indent-keyword ";"))
       (smie-rule-separator kind)))
    (`(:after . ,(or ";;" ";&" ";;&"))
     (with-demoted-errors
       (smie-backward-sexp token)
       (cons 'column
             (if (or (smie-rule-bolp)
                     (save-excursion
                       (and (member (funcall smie-backward-token-function)
                                    '("in" ";;"))
                            (smie-rule-bolp))))
                 (current-column)
               (smie-indent-calculate)))))
    (`(:before . ,(or "|" "&&" "||"))
     (unless (smie-rule-parent-p token)
       (smie-backward-sexp token)
       `(column . ,(+ (funcall smie-rules-function :elem 'basic)
                      (smie-indent-virtual)))))

    ;; 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 "(" "{" "["))
     (if (not (looking-at ".[ \t]*[^\n \t#]"))
         (sh-var-value 'sh-indent-after-open)
       (goto-char (1- (match-end 0)))
       `(column . ,(current-column))))
    ;; sh-indent-after-function: we don't handle it differently.
    ))