Function: c-awk-after-if-for-while-condition-p
c-awk-after-if-for-while-condition-p is a byte-compiled function
defined in cc-awk.el.gz.
Signature
(c-awk-after-if-for-while-condition-p &optional DO-LIM)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-awk.el.gz
;; ACM, 2002/5/29:
;;
;; The next section of code is about determining whether or not an AWK
;; statement is complete or not. We use this to indent the following line.
;; The determination is pretty straightforward in C, where a statement ends
;; with either a ; or a }. Only "while" really gives any trouble there, since
;; it might be the end of a do-while. In AWK, on the other hand, semicolons
;; are rarely used, and EOLs _usually_ act as "virtual semicolons". In
;; addition, we have the complexity of escaped EOLs. The core of this
;; analysis is in the middle of the function
;; c-awk-calculate-NL-prop-prev-line, about 130 lines lower down.
;;
;; To avoid continually repeating this expensive analysis, we "cache" its
;; result in a text-property, c-awk-NL-prop, whose value for a line is set on
;; the EOL (if any) which terminates that line. Should the property be
;; required for the very last line (which has no EOL), it is calculated as
;; required but not cached. The c-awk-NL-prop property should be thought of
;; as only really valid immediately after a buffer change, not a permanently
;; set property. (By contrast, the syntax-table text properties (set by an
;; after-change function) must be constantly updated for the mode to work
;; properly).
;;
;; This text property is also used for "syntactic whitespace" movement, this
;; being where the distinction between the values '$' and '}' is significant.
;;
;; The valid values for c-awk-NL-prop are:
;;
;; nil The property is not currently set for this line.
;; '#' There is NO statement on this line (at most a comment), and no open
;; statement from a previous line which could have been completed on this
;; line.
;; '{' There is an unfinished statement on this (or a previous) line which
;; doesn't require \s to continue onto another line, e.g. the line ends
;; with {, or the && operator, or "if (condition)". Note that even if the
;; newline is redundantly escaped, it remains a '{' line.
;; '\' There is an escaped newline at the end of this line and this '\' is
;; essential to the syntax of the program. (i.e. if it had been a
;; frivolous \, it would have been ignored and the line been given one of
;; the other property values.)
;; '$' A non-empty statement is terminated on the line by an EOL (a "virtual
;; semicolon"). This might be a content-free line terminating a statement
;; from the preceding (continued) line (which has property \).
;; '}' A statement, being the last thing (aside from ws/comments) is
;; explicitly terminated on this line by a closing brace (or sometimes a
;; semicolon).
;;
;; This set of values has been chosen so that the property's value on a line
;; is completely determined by the contents of the line and the property on
;; the previous line, EXCEPT for where a "while" might be the closing
;; statement of a do-while.
(defun c-awk-after-if-for-while-condition-p (&optional do-lim)
;; Are we just after the ) in "if/for/while (<condition>)"?
;;
;; Note that the end of the ) in a do .... while (<condition>) doesn't
;; count, since the purpose of this routine is essentially to decide
;; whether to indent the next line.
;;
;; DO-LIM sets a limit on how far back we search for the "do" of a possible
;; do-while.
;;
;; This function might do hidden buffer changes.
(and
(eq (char-before) ?\))
(save-excursion
(let ((par-pos (c-safe (scan-lists (point) -1 0))))
(when par-pos
(goto-char par-pos) ; back over "(...)"
(c-backward-token-1) ; BOB isn't a problem.
(or (looking-at "\\(if\\|for\\)\\>\\([^_]\\|$\\)")
(and (looking-at "while\\>\\([^_]\\|$\\)") ; Ensure this isn't a do-while.
(not (eq (c-beginning-of-statement-1 do-lim)
'beginning)))))))))