diff options
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 42 |
2 files changed, 46 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1d3c92c4468..778fe3dedd6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2013-01-09 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Fix bugs in the c-parse-state mechanism. Reuse some markers | ||
| 4 | instead of continually generating new ones. | ||
| 5 | |||
| 6 | * progmodes/cc-engine.el (c-state-old-cpp-beg-marker) | ||
| 7 | (c-state-old-cpp-end-marker): New variables. | ||
| 8 | (c-append-lower-brace-pair-to-state-cache): Start a backward | ||
| 9 | search for "}" definitively outside CPP constructs. | ||
| 10 | (c-remove-stale-state-cache): Inform the caller of a need to | ||
| 11 | search back for a brace pair in certain circumstances. | ||
| 12 | (c-state-maybe-marker): New macro. | ||
| 13 | (c-parse-state): Reuse markers when appropriate. | ||
| 14 | |||
| 1 | 2013-01-09 Glenn Morris <rgm@gnu.org> | 15 | 2013-01-09 Glenn Morris <rgm@gnu.org> |
| 2 | 16 | ||
| 3 | * simple.el (execute-extended-command): Doc fix. | 17 | * simple.el (execute-extended-command): Doc fix. |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 6ffa67f59c1..560b66bf3b0 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -2464,8 +2464,12 @@ comment at the start of cc-engine.el for more info." | |||
| 2464 | 2464 | ||
| 2465 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2465 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2466 | ;; Variables which keep track of preprocessor constructs. | 2466 | ;; Variables which keep track of preprocessor constructs. |
| 2467 | (defvar c-state-old-cpp-beg-marker nil) | ||
| 2468 | (make-variable-buffer-local 'c-state-old-cpp-beg-marker) | ||
| 2467 | (defvar c-state-old-cpp-beg nil) | 2469 | (defvar c-state-old-cpp-beg nil) |
| 2468 | (make-variable-buffer-local 'c-state-old-cpp-beg) | 2470 | (make-variable-buffer-local 'c-state-old-cpp-beg) |
| 2471 | (defvar c-state-old-cpp-end-marker nil) | ||
| 2472 | (make-variable-buffer-local 'c-state-old-cpp-end-marker) | ||
| 2469 | (defvar c-state-old-cpp-end nil) | 2473 | (defvar c-state-old-cpp-end nil) |
| 2470 | (make-variable-buffer-local 'c-state-old-cpp-end) | 2474 | (make-variable-buffer-local 'c-state-old-cpp-end) |
| 2471 | ;; These are the limits of the macro containing point at the previous call of | 2475 | ;; These are the limits of the macro containing point at the previous call of |
| @@ -2653,13 +2657,21 @@ comment at the start of cc-engine.el for more info." | |||
| 2653 | ;; reduce the time wasted in repeated fruitless searches in brace deserts. | 2657 | ;; reduce the time wasted in repeated fruitless searches in brace deserts. |
| 2654 | (save-excursion | 2658 | (save-excursion |
| 2655 | (save-restriction | 2659 | (save-restriction |
| 2656 | (let ((bra from) ce ; Positions of "{" and "}". | 2660 | (let* (new-cons |
| 2657 | new-cons | 2661 | (cache-pos (c-state-cache-top-lparen)) ; might be nil. |
| 2658 | (cache-pos (c-state-cache-top-lparen)) ; might be nil. | 2662 | (macro-start-or-from |
| 2659 | (macro-start-or-from | 2663 | (progn (goto-char from) |
| 2660 | (progn (goto-char from) | 2664 | (c-beginning-of-macro) |
| 2661 | (c-beginning-of-macro) | 2665 | (point))) |
| 2662 | (point)))) | 2666 | (bra ; Position of "{". |
| 2667 | ;; Don't start scanning in the middle of a CPP construct unless | ||
| 2668 | ;; it contains HERE - these constructs, in Emacs, are "commented | ||
| 2669 | ;; out" with category properties. | ||
| 2670 | (if (eq (c-get-char-property macro-start-or-from 'category) | ||
| 2671 | 'c-cpp-delimiter) | ||
| 2672 | macro-start-or-from | ||
| 2673 | from)) | ||
| 2674 | ce) ; Position of "}" | ||
| 2663 | (or upper-lim (setq upper-lim from)) | 2675 | (or upper-lim (setq upper-lim from)) |
| 2664 | 2676 | ||
| 2665 | ;; If we're essentially repeating a fruitless search, just give up. | 2677 | ;; If we're essentially repeating a fruitless search, just give up. |
| @@ -2899,7 +2911,9 @@ comment at the start of cc-engine.el for more info." | |||
| 2899 | (point-max) | 2911 | (point-max) |
| 2900 | (min (point-max) c-state-old-cpp-beg))) | 2912 | (min (point-max) c-state-old-cpp-beg))) |
| 2901 | (while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim)) | 2913 | (while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim)) |
| 2914 | (setq scan-back-pos (car-safe (car c-state-cache))) | ||
| 2902 | (setq c-state-cache (cdr c-state-cache))) | 2915 | (setq c-state-cache (cdr c-state-cache))) |
| 2916 | |||
| 2903 | ;; If `upper-lim' is inside the last recorded brace pair, remove its | 2917 | ;; If `upper-lim' is inside the last recorded brace pair, remove its |
| 2904 | ;; RBrace and indicate we'll need to search backwards for a previous | 2918 | ;; RBrace and indicate we'll need to search backwards for a previous |
| 2905 | ;; brace pair. | 2919 | ;; brace pair. |
| @@ -3324,6 +3338,13 @@ comment at the start of cc-engine.el for more info." | |||
| 3324 | (c-with-cpps-commented-out | 3338 | (c-with-cpps-commented-out |
| 3325 | (c-invalidate-state-cache-1 here))))) | 3339 | (c-invalidate-state-cache-1 here))))) |
| 3326 | 3340 | ||
| 3341 | (defmacro c-state-maybe-marker (place marker) | ||
| 3342 | ;; If PLACE is non-nil, return a marker marking it, otherwise nil. | ||
| 3343 | ;; We (re)use MARKER. | ||
| 3344 | `(and ,place | ||
| 3345 | (or ,marker (setq ,marker (make-marker))) | ||
| 3346 | (set-marker ,marker ,place))) | ||
| 3347 | |||
| 3327 | (defun c-parse-state () | 3348 | (defun c-parse-state () |
| 3328 | ;; This is a wrapper over `c-parse-state-1'. See that function for a | 3349 | ;; This is a wrapper over `c-parse-state-1'. See that function for a |
| 3329 | ;; description of the functionality and return value. | 3350 | ;; description of the functionality and return value. |
| @@ -3350,9 +3371,10 @@ comment at the start of cc-engine.el for more info." | |||
| 3350 | (c-parse-state-1)) | 3371 | (c-parse-state-1)) |
| 3351 | (c-with-cpps-commented-out | 3372 | (c-with-cpps-commented-out |
| 3352 | (c-parse-state-1)))) | 3373 | (c-parse-state-1)))) |
| 3353 | (setq c-state-old-cpp-beg (and here-cpp-beg (copy-marker here-cpp-beg t)) | 3374 | (setq c-state-old-cpp-beg |
| 3354 | c-state-old-cpp-end (and here-cpp-end (copy-marker here-cpp-end t))) | 3375 | (c-state-maybe-marker here-cpp-beg c-state-old-cpp-beg-marker) |
| 3355 | ))) | 3376 | c-state-old-cpp-end |
| 3377 | (c-state-maybe-marker here-cpp-end c-state-old-cpp-end-marker))))) | ||
| 3356 | 3378 | ||
| 3357 | ;; Debug tool to catch cache inconsistencies. This is called from | 3379 | ;; Debug tool to catch cache inconsistencies. This is called from |
| 3358 | ;; 000tests.el. | 3380 | ;; 000tests.el. |