Finish fixing a cacheing bug in CC Mode (see 2016-03-09)

* lisp/progmodes/cc-cmds.el: (c-beginning-of-defun, c-end-of-defun): Remove
superfluous invocations of c-self-bind-state-cache.

* lisp/progmodes/cc-defs.el: (c-self-bind-state-cache): Copy and terminate
markers correctly.

* lisp/progmodes/cc-engine.el (c-record-parse-state-state): Terminate stale
markers.
This commit is contained in:
Alan Mackenzie 2016-03-30 17:14:03 +00:00
parent ed19f20744
commit 2244331218
3 changed files with 144 additions and 128 deletions

View file

@ -1594,7 +1594,6 @@ defun."
(c-region-is-active-p)
(push-mark))
(c-self-bind-state-cache ; We must not share with other users of c-state-cache.
(c-save-buffer-state
(beginning-of-defun-function
end-of-defun-function
@ -1657,7 +1656,7 @@ defun."
(goto-char pos)))
(c-keep-region-active)
(= arg 0))))))
(= arg 0)))))
(defun c-forward-to-nth-EOF-} (n where)
;; Skip to the closing brace of the Nth function after point. If
@ -1719,8 +1718,6 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
(c-region-is-active-p)
(push-mark))
(c-self-bind-state-cache ; c-state-cache's list structure must not be shared
; with other users.
(c-save-buffer-state
(beginning-of-defun-function
end-of-defun-function
@ -1780,7 +1777,7 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
(goto-char pos))))
(c-keep-region-active)
(= arg 0)))))
(= arg 0))))
(defun c-defun-name ()
"Return the name of the current defun, or NIL if there isn't one.

View file

@ -1400,10 +1400,11 @@ been put there by c-put-char-property. POINT remains unchanged."
(c-set-cpp-delimiters ,beg ,end)))))
(defmacro c-self-bind-state-cache (&rest forms)
;; Bind the state cache to itself and execute the FORMS. It is assumed that no
;; buffer changes will happen in FORMS, and no hidden buffer changes which could
;; affect the parsing will be made by FORMS.
`(let ((c-state-cache (copy-tree c-state-cache))
;; Bind the state cache to itself and execute the FORMS. Return the result
;; of the last FORM executed. It is assumed that no buffer changes will
;; happen in FORMS, and no hidden buffer changes which could affect the
;; parsing will be made by FORMS.
`(let* ((c-state-cache (copy-tree c-state-cache))
(c-state-cache-good-pos c-state-cache-good-pos)
;(c-state-nonlit-pos-cache (copy-tree c-state-nonlit-pos-cache))
;(c-state-nonlit-pos-cache-limit c-state-nonlit-pos-cache-limit)
@ -1414,11 +1415,26 @@ been put there by c-put-char-property. POINT remains unchanged."
(c-state-point-min-lit-type c-state-point-min-lit-type)
(c-state-point-min-lit-start c-state-point-min-lit-start)
(c-state-min-scan-pos c-state-min-scan-pos)
(c-state-old-cpp-beg c-state-old-cpp-beg)
(c-state-old-cpp-end c-state-old-cpp-end))
,@forms))
(c-state-old-cpp-beg-marker (if (markerp c-state-old-cpp-beg-marker)
(copy-marker c-state-old-cpp-beg-marker)
c-state-old-cpp-beg-marker))
(c-state-old-cpp-beg (if (markerp c-state-old-cpp-beg)
c-state-old-cpp-beg-marker
c-state-old-cpp-beg))
(c-state-old-cpp-end-marker (if (markerp c-state-old-cpp-end-marker)
(copy-marker c-state-old-cpp-end-marker)
c-state-old-cpp-end-marker))
(c-state-old-cpp-end (if (markerp c-state-old-cpp-end)
c-state-old-cpp-end-marker
c-state-old-cpp-end))
(c-parse-state-state c-parse-state-state))
(prog1
(progn ,@forms)
(if (markerp c-state-old-cpp-beg-marker)
(move-marker c-state-old-cpp-beg-marker nil))
(if (markerp c-state-old-cpp-end-marker)
(move-marker c-state-old-cpp-end-marker nil)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The following macros are to be used only in `c-parse-state' and its
;; subroutines. Their main purpose is to simplify the handling of C++/Java

View file

@ -3472,6 +3472,9 @@ comment at the start of cc-engine.el for more info."
(make-variable-buffer-local 'c-parse-state-state)
(defun c-record-parse-state-state ()
(setq c-parse-state-point (point))
(when (markerp (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)))
(move-marker (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)) nil)
(move-marker (cdr (assq 'c-state-old-cpp-end c-parse-state-state)) nil))
(setq c-parse-state-state
(mapcar
(lambda (arg)