Function: c-at-bracelist-p

c-at-bracelist-p is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-at-bracelist-p CONTAINING-SEXP PAREN-STATE)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-at-bracelist-p (containing-sexp paren-state)
  ;; Try to return the buffer position of the beginning of the brace list
  ;; statement whose brace block begins at CONTAINING-SEXP, otherwise return
  ;; nil.  If the code cannot determine whether we're at a brace block, return
  ;; nil.
  ;;
  ;; CONTAINING-SEXP must be at an open brace. [This function is badly
  ;; designed, and probably needs reformulating without its first argument,
  ;; and the critical position being at point.]
  ;;
  ;; PAREN-STATE is the state of enclosing braces at CONTAINING-SEXP (see
  ;; `c-parse-state').
  ;;
  ;; The "brace list" here is recognized solely by its context, not by
  ;; its contents.
  ;;
  ;; N.B.: This algorithm can potentially get confused by cpp macros
  ;; placed in inconvenient locations.  It's a trade-off we make for
  ;; speed.
  ;;
  ;; This function might do hidden buffer changes.
  ;; It will pick up array/aggregate init lists, even if they are nested.
  (save-excursion
    (let ((bufpos t)
	  next-containing non-brace-pos
	  (whole-paren-state (cons containing-sexp paren-state))
	  (current-brace containing-sexp))
      (while (and (eq bufpos t)
		  current-brace
		  (not (memq current-brace c-no-bracelist-cache)))
	(setq next-containing
	      (and paren-state (c-pull-open-brace paren-state)))
	(goto-char current-brace)
	(cond
	 ((c-looking-at-inexpr-block next-containing next-containing)
	  ;; We're in an in-expression block of some kind.  Do not
	  ;; check nesting.  We deliberately set the limit to the
	  ;; containing sexp, so that c-looking-at-inexpr-block
	  ;; doesn't check for an identifier before it.
	  (setq bufpos nil))
	 ((not (eq (char-after) ?{))
	  (setq non-brace-pos (point))
	  (setq bufpos nil))
	 ((eq (setq bufpos (c-looking-at-or-maybe-in-bracelist
			    next-containing next-containing))
	      t)
	  (setq current-brace next-containing))))
      (cond
       ((consp bufpos)
	(and (not (eq (cdr bufpos) 'in-paren))
	     (car bufpos)))
       (non-brace-pos
	;; We've encountered a ( or a [.  Remove the "middle part" of
	;; paren-state, the part that isn't non-brace-list braces, to get the
	;; new value of `c-no-bracelist-cache'.
	(setq whole-paren-state
	      ;; `c-whack-state-before' makes a copy of `whole-paren-state'.
	      (c-whack-state-before (1+ non-brace-pos) whole-paren-state))
	(while (and next-containing
		    (not (memq next-containing c-no-bracelist-cache)))
	  (setq next-containing (c-pull-open-brace paren-state)))
	(setq c-no-bracelist-cache
	      (nconc (c-strip-conses whole-paren-state)
		     (and next-containing (list next-containing))
		     paren-state))
	nil)
       ((not (memq containing-sexp c-no-bracelist-cache))
	;; Update `c-no-bracelist-cache'
	(setq c-no-bracelist-cache (c-strip-conses whole-paren-state))
	nil)))))