Function: c-parse-state-get-strategy
c-parse-state-get-strategy is a byte-compiled function defined in
cc-engine.el.gz.
Signature
(c-parse-state-get-strategy HERE GOOD-POS)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-parse-state-get-strategy (here good-pos)
;; Determine the scanning strategy for adjusting `c-parse-state', attempting
;; to minimize the amount of scanning. HERE is the pertinent position in
;; the buffer, GOOD-POS is a position where `c-state-cache' (possibly with
;; its head trimmed) is known to be good, or nil if there is no such
;; position.
;;
;; The return value is a list, one of the following:
;;
;; o - ('forward START-POINT) - scan forward from START-POINT,
;; which is not less than the highest position in `c-state-cache' below HERE,
;; which is after GOOD-POS.
;; o - ('backward nil) - scan backwards (from HERE).
;; o - ('back-and-forward START-POINT) - like 'forward, but when HERE is earlier
;; than GOOD-POS.
;; o - ('BOD START-POINT) - scan forwards from START-POINT, which is at the
;; top level.
;; o - ('IN-LIT nil) - point is inside the literal containing point-min.
(let* ((in-macro-start ; start of macro containing HERE or nil.
(save-excursion
(goto-char here)
(and (c-beginning-of-macro)
(point))))
(changed-macro-start
(and in-macro-start
(not (and c-state-old-cpp-beg
(= in-macro-start c-state-old-cpp-beg)))
in-macro-start))
(cache-pos (c-get-cache-scan-pos (if changed-macro-start
(min changed-macro-start here)
here))) ; highest suitable position in cache (or 1)
BOD-pos ; position of 2nd BOD before HERE.
strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT.
start-point
how-far) ; putative scanning distance.
(setq good-pos (or good-pos (c-state-get-min-scan-pos)))
(cond
((< here (c-state-get-min-scan-pos))
(setq strategy 'IN-LIT
start-point nil
cache-pos nil
how-far 0))
((<= good-pos here)
(setq strategy 'forward
start-point (max good-pos cache-pos)
how-far (- here start-point)))
((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting.
(setq strategy 'backward
how-far (- good-pos here)))
(t
(setq strategy 'back-and-forward
start-point cache-pos
how-far (- here start-point))))
;; Might we be better off starting from the top level, two defuns back,
;; instead? This heuristic no longer works well in C++, where
;; declarations inside namespace brace blocks are frequently placed at
;; column zero. (2015-11-10): Remove the condition on C++ Mode.
(when (and (or (not (memq 'col-0-paren c-emacs-features))
open-paren-in-column-0-is-defun-start)
;; (not (c-major-mode-is 'c++-mode))
(> how-far c-state-cache-too-far))
(setq BOD-pos (c-get-fallback-scan-pos here)) ; somewhat EXPENSIVE!!!
(if (and BOD-pos
(< (- here BOD-pos) how-far))
(setq strategy 'BOD
start-point BOD-pos)))
(list strategy start-point)))