Function: c-safe-position
c-safe-position is a byte-compiled function defined in
cc-engine.el.gz.
Signature
(c-safe-position BUFPOS PAREN-STATE)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-safe-position (bufpos paren-state)
;; Return the closest "safe" position recorded on PAREN-STATE that
;; is higher up than BUFPOS. Return nil if PAREN-STATE doesn't
;; contain any. Return nil if BUFPOS is nil, which is useful to
;; find the closest limit before a given limit that might be nil.
;;
;; A "safe" position is a position at or after a recorded open
;; paren, or after a recorded close paren. The returned position is
;; thus either the first position after a close brace, or the first
;; position after an enclosing paren, or at the enclosing paren in
;; case BUFPOS is immediately after it.
(when bufpos
(let (elem)
(catch 'done
(while paren-state
(setq elem (car paren-state))
(if (consp elem)
(cond ((< (cdr elem) bufpos)
(throw 'done (cdr elem)))
((< (car elem) bufpos)
;; See below.
(throw 'done (min (1+ (car elem)) bufpos))))
(if (< elem bufpos)
;; elem is the position at and not after the opening paren, so
;; we can go forward one more step unless it's equal to
;; bufpos. This is useful in some cases avoid an extra paren
;; level between the safe position and bufpos.
(throw 'done (min (1+ elem) bufpos))))
(setq paren-state (cdr paren-state)))))))