Function: c-state-safe-place
c-state-safe-place is a byte-compiled function defined in
cc-engine.el.gz.
Signature
(c-state-safe-place HERE)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-state-safe-place (here)
;; Return a buffer position before HERE which is "safe", i.e. outside any
;; string, comment, or macro.
;;
;; NOTE: This function manipulates `c-state-nonlit-pos-cache'. This cache
;; MAY NOT contain any positions within macros, since macros are frequently
;; turned into comments by use of the `c-cpp-delimiter' category properties.
;; We cannot rely on this mechanism whilst determining a cache pos since
;; this function is also called from outwith `c-parse-state'.
(save-restriction
(widen)
(save-excursion
(let ((c c-state-nonlit-pos-cache)
pos npos high-pos lit macro-beg macro-end)
;; Trim the cache to take account of buffer changes.
(while (and c (> (car c) c-state-nonlit-pos-cache-limit))
(setq c (cdr c)))
(setq c-state-nonlit-pos-cache c)
(while (and c (> (car c) here))
(setq high-pos (car c))
(setq c (cdr c)))
(setq pos (or (car c) (point-min)))
(unless high-pos
(while
;; Add an element to `c-state-nonlit-pos-cache' each iteration.
(and
(setq npos
(when (<= (+ pos c-state-nonlit-pos-interval) here)
(+ pos c-state-nonlit-pos-interval)))
;; Test for being in a literal. If so, go to after it.
(progn
(setq lit (car (cddr (c-state-pp-to-literal pos npos))))
(or (null lit)
(prog1 (<= (cdr lit) here)
(setq npos (cdr lit)))))
;; Test for being in a macro. If so, go to after it.
(progn
(goto-char npos)
(setq macro-beg
(and (c-beginning-of-macro) (/= (point) npos) (point)))
(when macro-beg
(c-syntactic-end-of-macro)
(or (eobp) (forward-char))
(setq macro-end (point)))
(or (null macro-beg)
(prog1 (<= macro-end here)
(setq npos macro-end)))))
(setq pos npos)
(setq c-state-nonlit-pos-cache (cons pos c-state-nonlit-pos-cache)))
;; Add one extra element above HERE so as to avoid the previous
;; expensive calculation when the next call is close to the current
;; one. This is especially useful when inside a large macro.
(when npos
(setq c-state-nonlit-pos-cache
(cons npos c-state-nonlit-pos-cache))))
(if (> pos c-state-nonlit-pos-cache-limit)
(setq c-state-nonlit-pos-cache-limit pos))
pos))))