Function: lua-calculate-indentation-override
lua-calculate-indentation-override is a byte-compiled function defined
in lua-mode.el.gz.
Signature
(lua-calculate-indentation-override &optional PARSE-START)
Documentation
Return overriding indentation amount for special cases.
If there's a sequence of block-close tokens starting at the beginning of the line, calculate indentation according to the line containing block-open token for the last block-close token in the sequence.
If not, return nil.
Optional PARSE-START is a position to which the point should be moved first.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/lua-mode.el.gz
(defun lua-calculate-indentation-override (&optional parse-start)
"Return overriding indentation amount for special cases.
If there's a sequence of block-close tokens starting at the beginning of
the line, calculate indentation according to the line containing
block-open token for the last block-close token in the sequence.
If not, return nil.
Optional PARSE-START is a position to which the point should be moved
first."
(let (case-fold-search rightmost-closer-info opener-info opener-pos)
(save-excursion
(when (and (setq rightmost-closer-info (lua--goto-line-beginning-rightmost-closer parse-start))
(setq opener-info (lua--backward-up-list-noerror))
;; Ensure opener matches closer.
(string-match (lua-get-token-match-re rightmost-closer-info 'backward)
(car opener-info)))
;; Special case: "middle" tokens like for/do, while/do, if/then,
;; elseif/then: corresponding "end" or corresponding "else" must
;; be unindented to the beginning of the statement, which is not
;; necessarily the same as beginning of string that contains
;; "do", e.g.
;;
;; while (
;; foo and
;; bar) do
;; hello_world()
;; end
(setq opener-pos (point))
(when (/= (- opener-pos (line-beginning-position)) (current-indentation))
(unless (or
(and (string-equal (car opener-info) "do")
(member (car (lua--backward-up-list-noerror))
'("while" "for")))
(and (string-equal (car opener-info) "then")
(member (car (lua--backward-up-list-noerror))
'("if" "elseif"))))
(goto-char opener-pos)))
;; (let (cont-stmt-pos)
;; (while (setq cont-stmt-pos (lua-is-continuing-statement-p))
;; (goto-char cont-stmt-pos)))
;; Exception cases: when the start of the line is an assignment,
;; go to the start of the assignment instead of the matching
;; item
(if (and lua-indent-close-paren-align
(member (car opener-info) '("{" "(" "["))
(not (lua-point-is-after-left-shifter-p)))
(current-column)
(current-indentation))))))