summaryrefslogtreecommitdiff
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2021-02-23 11:16:24 +0000
committerAlan Mackenzie <acm@muc.de>2021-02-23 11:16:24 +0000
commit7ebdecfcdfc59f34b4751bcd69b4efabec7be48c (patch)
treea4903868675dbf61d12d70d3d102ac838a152039 /lisp/progmodes
parentb03d9d2c13085b23cf50cbb651ea2c592fe3739d (diff)
downloademacs-7ebdecfcdfc59f34b4751bcd69b4efabec7be48c.tar.gz
emacs-7ebdecfcdfc59f34b4751bcd69b4efabec7be48c.tar.bz2
emacs-7ebdecfcdfc59f34b4751bcd69b4efabec7be48c.zip
CC Mode: Fix bug in "state cache" invalidation function.
* lisp/progmodes/cc-engine.el (c-invalidate-state-cache-1): Rewrite part of it, following the code in c-parse-state-1, to get a proper setting of c-state-cache-good-pos.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-engine.el55
1 files changed, 23 insertions, 32 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 9038c7bd95a..4cf7af843b7 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -4319,38 +4319,29 @@ mhtml-mode."
(setq c-state-nonlit-pos-cache-limit (1- here)))
(c-truncate-lit-pos-cache here)
- ;; `c-state-cache':
- ;; Case 1: if `here' is in a literal containing point-min, everything
- ;; becomes (or is already) nil.
- (if (or (null c-state-cache-good-pos)
- (< here (c-state-get-min-scan-pos)))
- (setq c-state-cache nil
- c-state-cache-good-pos nil
- c-state-min-scan-pos nil)
-
- ;; Truncate `c-state-cache' and set `c-state-cache-good-pos' to a value
- ;; below `here'. To maintain its consistency, we may need to insert a new
- ;; brace pair.
- (let ((here-bol (c-point 'bol here))
- too-high-pa ; recorded {/(/[ next above or just below here, or nil.
- dropped-cons) ; was the last removed element a brace pair?
- ;; The easy bit - knock over-the-top bits off `c-state-cache'.
- (while (and c-state-cache
- (>= (c-state-cache-top-paren) here))
- (setq dropped-cons (consp (car c-state-cache))
- too-high-pa (c-state-cache-top-lparen)
- c-state-cache (cdr c-state-cache)))
-
- ;; Do we need to add in an earlier brace pair, having lopped one off?
- (if (and dropped-cons
- (<= too-high-pa here))
- (c-append-lower-brace-pair-to-state-cache too-high-pa here here-bol))
- (if (and c-state-cache-good-pos (< here c-state-cache-good-pos))
- (setq c-state-cache-good-pos
- (or (save-excursion
- (goto-char here)
- (c-literal-start))
- here)))))
+ (cond
+ ;; `c-state-cache':
+ ;; Case 1: if `here' is in a literal containing point-min, everything
+ ;; becomes (or is already) nil.
+ ((or (null c-state-cache-good-pos)
+ (< here (c-state-get-min-scan-pos)))
+ (setq c-state-cache nil
+ c-state-cache-good-pos nil
+ c-state-min-scan-pos nil))
+
+ ;; Case 2: `here' is below `c-state-cache-good-pos', so we need to amend
+ ;; the entire `c-state-cache' data.
+ ((< here c-state-cache-good-pos)
+ (let* ((res (c-remove-stale-state-cache-backwards here))
+ (good-pos (car res))
+ (scan-backward-pos (cadr res))
+ (scan-forward-p (car (cddr res))))
+ (if scan-backward-pos
+ (c-append-lower-brace-pair-to-state-cache scan-backward-pos here))
+ (setq c-state-cache-good-pos
+ (if scan-forward-p
+ (c-append-to-state-cache good-pos here)
+ good-pos)))))
;; The brace-pair desert marker:
(when (car c-state-brace-pair-desert)