Function: c-append-to-state-cache

c-append-to-state-cache is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-append-to-state-cache FROM HERE)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-append-to-state-cache (from here)
  ;; Scan the buffer from FROM to HERE, adding elements into `c-state-cache'
  ;; for braces etc.  Return a candidate for `c-state-cache-good-pos'.
  ;;
  ;; FROM must be after the latest brace/paren/bracket in `c-state-cache', if
  ;; any.  Typically, it is immediately after it.  It must not be inside a
  ;; literal.
  (let ((here-bol (c-point 'bol here))
	(macro-start-or-here
	 (save-excursion (goto-char here)
			 (if (c-beginning-of-macro)
			     (point)
			   here)))
	pa+1		      ; pos just after an opening PAren (or brace).
	(ren+1 from)	      ; usually a pos just after a closing paREN etc.
			      ; Is actually the pos. to scan for a (/{/[ from,
			      ; which sometimes is after a silly )/}/].
	paren+1		      ; Pos after some opening or closing paren.
	paren+1s	      ; A list of `paren+1's; used to determine a
			      ; good-pos.
	bra+1		      ; just after L bra-ce.
	mstart)		      ; start of a macro.

    (save-excursion
      (save-restriction
	(narrow-to-region (point-min) here)
	;; Each time round the following loop, we enter a successively deeper
	;; level of brace/paren nesting.  (Except sometimes we "continue at
	;; the existing level".)  `pa+1' is a pos inside an opening
	;; brace/paren/bracket, usually just after it.
	(while
	    (progn
	      ;; Each time round the next loop moves forward over an opening then
	      ;; a closing brace/bracket/paren.  This loop is white hot, so it
	      ;; plays ugly tricks to go fast.  DON'T PUT ANYTHING INTO THIS
	      ;; LOOP WHICH ISN'T ABSOLUTELY NECESSARY!!!  It terminates when a
	      ;; call of `scan-lists' signals an error, which happens when there
	      ;; are no more b/b/p's to scan.
	      (c-safe
		(while t
		  (setq pa+1 (c-sc-scan-lists ren+1 1 -1) ; Into (/{/[; might signal
			paren+1s (cons pa+1 paren+1s))
		  (setq ren+1 (c-sc-scan-lists pa+1 1 1)) ; Out of )/}/]; might signal
		  (if (and (eq (char-before pa+1) ?{)) ; Check for a macro later.
		      (setq bra+1 pa+1))
		  (setcar paren+1s ren+1)))

	      (if (and pa+1 (> pa+1 ren+1))
		  ;; We've just entered a deeper nesting level.
		  (progn
		    ;; Insert the brace pair (if present) and the single open
		    ;; paren/brace/bracket into `c-state-cache' It cannot be
		    ;; inside a macro, except one around point, because of what
		    ;; `c-neutralize-syntax-in-CPP' has done.
		    (c-state-push-any-brace-pair bra+1 macro-start-or-here)
		    ;; Insert the opening brace/bracket/paren position.
		    (setq c-state-cache (cons (1- pa+1) c-state-cache))
		    ;; Clear admin stuff for the next more nested part of the scan.
		    (setq ren+1 pa+1  pa+1 nil  bra+1 nil)
		    t)			; Carry on the loop

		;; All open p/b/b's at this nesting level, if any, have probably
		;; been closed by matching/mismatching ones.  We're probably
		;; finished - we just need to check for having found an
		;; unmatched )/}/], which we ignore.  Such a )/}/] can't be in a
		;; macro, due the action of `c-neutralize-syntax-in-CPP'.
		(c-safe (setq ren+1 (c-sc-scan-lists ren+1 1 1)))))) ; acts as loop control.

	;; Record the final, innermost, brace-pair if there is one.
	(c-state-push-any-brace-pair bra+1 macro-start-or-here)

	;; Determine a good pos
	(while (and (setq paren+1 (car paren+1s))
		    (> (if (> paren+1 macro-start-or-here)
			   paren+1
			 (goto-char paren+1)
			 (setq mstart (and (c-beginning-of-macro)
					   (point)))
			 (or mstart paren+1))
		       here-bol))
	  (setq paren+1s (cdr paren+1s)))
	(cond
	 ((and paren+1 mstart)
	  (min paren+1 mstart))
	 (paren+1)
	 (t from))))))