aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-11-14 19:51:01 +0000
committerAlan Mackenzie2019-11-14 19:51:01 +0000
commitc455e609bdf065c3177eec29234348809cdc372c (patch)
tree2012a06e37d6d269dcd1600c8fb40ccf6746ceaf
parent30e944b66b24254e007381c80237e96c721a127c (diff)
downloademacs-c455e609bdf065c3177eec29234348809cdc372c.tar.gz
emacs-c455e609bdf065c3177eec29234348809cdc372c.zip
CC Mode: Fix two bugs in the "state cache".
This (along with a suggestion to the OP to set open-paren-in-column-0-is-defun-start to nil) fixes bug #37910. It may also have fixed bug #5490 and bug #18072. * lisp/progmodes/cc-engine.el (c-state-cache-non-literal-place): Remove thi non-sensical function, replacing it with .... (c-state-cache-lower-good-pos): New function. (c-renarrow-state-cache, c-append-lower-brace-pair-to-state-cache) (c-remove-stale-state-cache, c-remove-stale-state-cache-backwards): Instead of altering the state-cache list structure with setcar and setcdr, use setq and consing. (c-parse-state-1): Call c-state-cache-lower-good-pos rather than c-state-cache-non-literal-place.
-rw-r--r--lisp/progmodes/cc-engine.el61
1 files changed, 42 insertions, 19 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 15b23bb2e6a..e2f822951c8 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -3366,19 +3366,35 @@ comment at the start of cc-engine.el for more info."
3366 (or (car (c-state-literal-at pos)) 3366 (or (car (c-state-literal-at pos))
3367 pos)) 3367 pos))
3368 3368
3369(defsubst c-state-cache-non-literal-place (pos state) 3369(defun c-state-cache-lower-good-pos (here pos state)
3370 ;; Return a position outside of a string/comment/macro at or before POS. 3370 ;; Return a good pos (in the sense of `c-state-cache-good-pos') at the
3371 ;; STATE is the parse-partial-sexp state at POS. 3371 ;; lowest[*] position between POS and HERE which is syntactically equivalent
3372 (let ((res (if (or (nth 3 state) ; in a string? 3372 ;; to HERE. This position may be HERE itself. POS is before HERE in the
3373 (and (nth 4 state) 3373 ;; buffer.
3374 (not (eq (nth 7 state) 'syntax-table)))) ; in a comment? 3374 ;; [*] We don't actually always determine this exact position, since this
3375 (nth 8 state) 3375 ;; would require a disproportionate amount of work, given that this function
3376 pos))) 3376 ;; deals only with a corner condition, and POS and HERE are typically on
3377 ;; adjacent lines. We actually return either POS, when POS is a good
3378 ;; position, HERE otherwise. Exceptionally, when POS is in a comment, but
3379 ;; HERE not, we can return the position of the end of the comment.
3380 (let (s)
3377 (save-excursion 3381 (save-excursion
3378 (goto-char res) 3382 (goto-char pos)
3379 (if (c-beginning-of-macro) 3383 (when (nth 8 state) ; POS in a comment or string. Move out of it.
3380 (point) 3384 (setq s (parse-partial-sexp pos here nil nil state 'syntax-table))
3381 res)))) 3385 (when (< (point) here)
3386 (setq pos (point)
3387 state s)))
3388 (if (eq (point) here) ; HERE is in the same literal as POS
3389 pos
3390 (setq s (parse-partial-sexp pos here (1+ (car state)) nil state nil))
3391 (cond
3392 ((> (car s) (car state)) ; Moved into a paren between POS and HERE
3393 here)
3394 ((not (eq (nth 6 s) (car state))) ; Moved out of a paren between POS
3395 ; and HERE
3396 here)
3397 (t pos))))))
3382 3398
3383;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3399;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3384;; Stuff to do with point-min, and coping with any literal there. 3400;; Stuff to do with point-min, and coping with any literal there.
@@ -3685,7 +3701,13 @@ comment at the start of cc-engine.el for more info."
3685 ; brace pair. 3701 ; brace pair.
3686 (setq c-state-cache nil 3702 (setq c-state-cache nil
3687 c-state-cache-good-pos c-state-min-scan-pos) 3703 c-state-cache-good-pos c-state-min-scan-pos)
3688 (setcdr ptr nil) 3704 ;; Do not alter the original `c-state-cache' structure, since there
3705 ;; may be a loop suspended which is looping through that structure.
3706 ;; This may have been the cause of bug #37910.
3707 (let ((cdr-ptr (cdr ptr)))
3708 (setcdr ptr nil)
3709 (setq c-state-cache (copy-sequence c-state-cache))
3710 (setcdr ptr cdr-ptr))
3689 (setq c-state-cache-good-pos (1+ (c-state-cache-top-lparen)))) 3711 (setq c-state-cache-good-pos (1+ (c-state-cache-top-lparen))))
3690 ))) 3712 )))
3691 3713
@@ -3788,11 +3810,12 @@ comment at the start of cc-engine.el for more info."
3788 (setq new-cons (cons bra (1+ ce))) 3810 (setq new-cons (cons bra (1+ ce)))
3789 (cond 3811 (cond
3790 ((consp (car c-state-cache)) 3812 ((consp (car c-state-cache))
3791 (setcar c-state-cache new-cons)) 3813 (setq c-state-cache (cons new-cons (cdr c-state-cache))))
3792 ((and (numberp (car c-state-cache)) ; probably never happens 3814 ((and (numberp (car c-state-cache)) ; probably never happens
3793 (< ce (car c-state-cache))) 3815 (< ce (car c-state-cache)))
3794 (setcdr c-state-cache 3816 (setq c-state-cache
3795 (cons new-cons (cdr c-state-cache)))) 3817 (cons (car c-state-cache)
3818 (cons new-cons (cdr c-state-cache)))))
3796 (t (setq c-state-cache (cons new-cons c-state-cache))))) 3819 (t (setq c-state-cache (cons new-cons c-state-cache)))))
3797 3820
3798 ;; We haven't found a brace pair. Record this in the cache. 3821 ;; We haven't found a brace pair. Record this in the cache.
@@ -3993,7 +4016,7 @@ comment at the start of cc-engine.el for more info."
3993 (when (and c-state-cache 4016 (when (and c-state-cache
3994 (consp (car c-state-cache)) 4017 (consp (car c-state-cache))
3995 (> (cdar c-state-cache) upper-lim)) 4018 (> (cdar c-state-cache) upper-lim))
3996 (setcar c-state-cache (caar c-state-cache)) 4019 (setq c-state-cache (cons (caar c-state-cache) (cdr c-state-cache)))
3997 (setq scan-back-pos (car c-state-cache) 4020 (setq scan-back-pos (car c-state-cache)
3998 cons-separated t)) 4021 cons-separated t))
3999 4022
@@ -4130,7 +4153,7 @@ comment at the start of cc-engine.el for more info."
4130 ;; knowledge of what's inside these braces, we have no alternative but 4153 ;; knowledge of what's inside these braces, we have no alternative but
4131 ;; to direct the caller to scan the buffer from the opening brace. 4154 ;; to direct the caller to scan the buffer from the opening brace.
4132 (setq pos (caar c-state-cache)) 4155 (setq pos (caar c-state-cache))
4133 (setcar c-state-cache pos) 4156 (setq c-state-cache (cons pos (cdr c-state-cache)))
4134 (list (1+ pos) pos t)) ; return value. We've just converted a brace pair 4157 (list (1+ pos) pos t)) ; return value. We've just converted a brace pair
4135 ; entry into a { entry, so the caller needs to 4158 ; entry into a { entry, so the caller needs to
4136 ; search for a brace pair before the {. 4159 ; search for a brace pair before the {.
@@ -4380,7 +4403,7 @@ comment at the start of cc-engine.el for more info."
4380 (setq c-state-cache-good-pos 4403 (setq c-state-cache-good-pos
4381 (if (and bopl-state 4404 (if (and bopl-state
4382 (< good-pos (- here c-state-cache-too-far))) 4405 (< good-pos (- here c-state-cache-too-far)))
4383 (c-state-cache-non-literal-place here-bopl bopl-state) 4406 (c-state-cache-lower-good-pos here here-bopl bopl-state)
4384 good-pos))) 4407 good-pos)))
4385 4408
4386 ((eq strategy 'backward) 4409 ((eq strategy 'backward)