Function: opascal-section-indent-of
opascal-section-indent-of is a byte-compiled function defined in
opascal.el.gz.
Signature
(opascal-section-indent-of SECTION-TOKEN)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/opascal.el.gz
(defun opascal-section-indent-of (section-token)
;; Returns the indentation appropriate for begin/var/const/type/label
;; tokens.
(let* ((token section-token)
(last-token nil)
(nested-block-count 0)
(expr-delimited nil)
(last-terminator nil))
(catch 'done
(opascal--scan-non-whitespace-backward token last-token
;; Always stop at unmatched ( or [.
('open-group
(throw 'done (opascal-open-group-indent token last-token)))
;; Skip over any ()/[] groups.
('close-group (setq token (opascal-group-start token)))
((opascal--in opascal-end-block-statements)
(if (eq 'newline (opascal-token-kind (opascal-previous-token token)))
;; We can stop at an end token that is right up against the
;; margin.
(throw 'done 0)
;; Otherwise, skip over any nested blocks.
(setq token (opascal-block-start token)
nested-block-count (1+ nested-block-count))))
;; Remember if we have encountered any forward routine declarations.
('forward
(setq nested-block-count (1+ nested-block-count)))
;; Mark the completion of a nested routine traversal.
((and (opascal--in opascal-routine-statements)
(guard (> nested-block-count 0)))
(setq nested-block-count (1- nested-block-count)))
;; Remember if we have encountered any statement terminators.
('semicolon (setq last-terminator token))
;; Remember if we have encountered any expression delimiters.
((opascal--in opascal-expr-delimiters)
(setq expr-delimited token))
;; Enclosing body statements are delimiting. We indent the compound
;; bodies specially.
((and (guard (not last-terminator))
(opascal--in opascal-body-statements))
(throw 'done
(opascal-stmt-line-indent-of token
opascal-compound-block-indent)))
;; An enclosing ":" means a label.
((and 'colon
(guard (and (memq (opascal-token-kind section-token)
opascal-block-statements)
(not last-terminator)
(not expr-delimited)
(not (eq 'equals
(opascal-token-kind last-token))))))
(throw 'done
(opascal-stmt-line-indent-of token opascal-indent-level)))
;; Block and mid block tokens are always enclosing
((opascal--in opascal-begin-enclosing-tokens)
(throw 'done
(opascal-stmt-line-indent-of token opascal-indent-level)))
;; Declaration sections and routines are delimiters, unless they
;; are part of a nested routine.
((and (opascal--in opascal-decl-delimiters)
(guard (= 0 nested-block-count)))
(throw 'done (opascal-line-indent-of token 0)))
;; Unit statements mean we indent right to the left.
((opascal--in opascal-unit-statements) (throw 'done 0))
)
;; We ran out of tokens. Indent to column 0.
0)))