diff options
| author | Alan Mackenzie | 2013-02-02 18:24:10 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2013-02-02 18:24:10 +0000 |
| commit | d23b0804fb3601e87762a1f2ea628949bb05f929 (patch) | |
| tree | 56d35c6d5569c9b37fa39989a28b9a38fbdc2163 | |
| parent | 970b321fd0033d883243a1240494ff9471435a34 (diff) | |
| download | emacs-d23b0804fb3601e87762a1f2ea628949bb05f929.tar.gz emacs-d23b0804fb3601e87762a1f2ea628949bb05f929.zip | |
Fix bug in the state cache mechanism. Remove 'BOD "strategy". Refactor.
cc-engine.el (c-get-fallback-scan-pos): Remove.
(c-parse-state-get-strategy): Don't return 'BOD any more.
(c-append-lower-brace-pair-to-state-cache): Extra parameter HERE instead
of narrowing. Widen to top of buffer before searching backwards for a
brace pair.
(c-state-push-any-brace-pair): Add HERE parameter to function call.
(c-append-to-state-cache): Extra parameter HERE in place of narrowing.
Narrow to parameter HERE, in place of being called narrowed.
(c-remove-stale-state-cache): Extra parameter HERE in place of narrowing.
Check there's an open brace in the cache before searching for its match.
(c-invalidate-state-cache-1): Add HERE parameter to function call.
(c-parse-state-1): Don't narrow here for 'forward strategy, instead
passing extra parameter HERE to several functions. Remove 'BOD strategy.
| -rw-r--r-- | lisp/ChangeLog | 21 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 317 |
2 files changed, 158 insertions, 180 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 344a8d772da..b3ffae1f8cf 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,24 @@ | |||
| 1 | 2013-02-02 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Fix bug in the state cache mechanism. Remove 'BOD "strategy". Refactor. | ||
| 4 | * progmodes/cc-engine.el (c-get-fallback-scan-pos): Remove. | ||
| 5 | (c-parse-state-get-strategy): Don't return 'BOD any more. | ||
| 6 | (c-append-lower-brace-pair-to-state-cache): Extra parameter HERE | ||
| 7 | instead of narrowing. Widen to top of buffer before searching | ||
| 8 | backwards for a brace pair. | ||
| 9 | (c-state-push-any-brace-pair): Add HERE parameter to function | ||
| 10 | call. | ||
| 11 | (c-append-to-state-cache): Extra parameter HERE in place of | ||
| 12 | narrowing. Narrow to parameter HERE, in place of being called | ||
| 13 | narrowed. | ||
| 14 | (c-remove-stale-state-cache): Extra parameter HERE in place of | ||
| 15 | narrowing. Check there's an open brace in the cache before | ||
| 16 | searching for its match. | ||
| 17 | (c-invalidate-state-cache-1): Add HERE parameter to function call. | ||
| 18 | (c-parse-state-1): Don't narrow here for 'forward strategy, | ||
| 19 | instead passing extra parameter HERE to several functions. Remove | ||
| 20 | 'BOD strategy. | ||
| 21 | |||
| 1 | 2013-02-01 Stefan Monnier <monnier@iro.umontreal.ca> | 22 | 2013-02-01 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 23 | ||
| 3 | * mouse.el (mouse-drag-track): Always deactivate the mark before | 24 | * mouse.el (mouse-drag-track): Always deactivate the mark before |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 1eac45d06e0..f23dfff9c2d 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -2477,20 +2477,6 @@ comment at the start of cc-engine.el for more info." | |||
| 2477 | 2477 | ||
| 2478 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2478 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2479 | ;; Defuns which analyze the buffer, yet don't change `c-state-cache'. | 2479 | ;; Defuns which analyze the buffer, yet don't change `c-state-cache'. |
| 2480 | (defun c-get-fallback-scan-pos (here) | ||
| 2481 | ;; Return a start position for building `c-state-cache' from | ||
| 2482 | ;; scratch. This will be at the top level, 2 defuns back. | ||
| 2483 | (save-excursion | ||
| 2484 | ;; Go back 2 bods, but ignore any bogus positions returned by | ||
| 2485 | ;; beginning-of-defun (i.e. open paren in column zero). | ||
| 2486 | (goto-char here) | ||
| 2487 | (let ((cnt 2)) | ||
| 2488 | (while (not (or (bobp) (zerop cnt))) | ||
| 2489 | (c-beginning-of-defun-1) ; Pure elisp BOD. | ||
| 2490 | (if (eq (char-after) ?\{) | ||
| 2491 | (setq cnt (1- cnt))))) | ||
| 2492 | (point))) | ||
| 2493 | |||
| 2494 | (defun c-state-balance-parens-backwards (here- here+ top) | 2480 | (defun c-state-balance-parens-backwards (here- here+ top) |
| 2495 | ;; Return the position of the opening paren/brace/bracket before HERE- which | 2481 | ;; Return the position of the opening paren/brace/bracket before HERE- which |
| 2496 | ;; matches the outermost close p/b/b between HERE+ and TOP. Except when | 2482 | ;; matches the outermost close p/b/b between HERE+ and TOP. Except when |
| @@ -2548,47 +2534,23 @@ comment at the start of cc-engine.el for more info." | |||
| 2548 | ;; o - ('forward START-POINT) - scan forward from START-POINT, | 2534 | ;; o - ('forward START-POINT) - scan forward from START-POINT, |
| 2549 | ;; which is not less than the highest position in `c-state-cache' below here. | 2535 | ;; which is not less than the highest position in `c-state-cache' below here. |
| 2550 | ;; o - ('backward nil) - scan backwards (from HERE). | 2536 | ;; o - ('backward nil) - scan backwards (from HERE). |
| 2551 | ;; o - ('BOD START-POINT) - scan forwards from START-POINT, which is at the | ||
| 2552 | ;; top level. | ||
| 2553 | ;; o - ('IN-LIT nil) - point is inside the literal containing point-min. | 2537 | ;; o - ('IN-LIT nil) - point is inside the literal containing point-min. |
| 2554 | (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1) | 2538 | (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1) |
| 2555 | BOD-pos ; position of 2nd BOD before HERE. | 2539 | strategy ; 'forward, 'backward, or 'IN-LIT. |
| 2556 | strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT. | 2540 | start-point) |
| 2557 | start-point | ||
| 2558 | how-far) ; putative scanning distance. | ||
| 2559 | (setq good-pos (or good-pos (c-state-get-min-scan-pos))) | 2541 | (setq good-pos (or good-pos (c-state-get-min-scan-pos))) |
| 2560 | (cond | 2542 | (cond |
| 2561 | ((< here (c-state-get-min-scan-pos)) | 2543 | ((< here (c-state-get-min-scan-pos)) |
| 2562 | (setq strategy 'IN-LIT | 2544 | (setq strategy 'IN-LIT)) |
| 2563 | start-point nil | ||
| 2564 | cache-pos nil | ||
| 2565 | how-far 0)) | ||
| 2566 | ((<= good-pos here) | 2545 | ((<= good-pos here) |
| 2567 | (setq strategy 'forward | 2546 | (setq strategy 'forward |
| 2568 | start-point (max good-pos cache-pos) | 2547 | start-point (max good-pos cache-pos))) |
| 2569 | how-far (- here start-point))) | ||
| 2570 | ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting. | 2548 | ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of weighting. |
| 2571 | (setq strategy 'backward | 2549 | (setq strategy 'backward)) |
| 2572 | how-far (- good-pos here))) | ||
| 2573 | (t | 2550 | (t |
| 2574 | (setq strategy 'forward | 2551 | (setq strategy 'forward |
| 2575 | how-far (- here cache-pos) | 2552 | start-point cache-pos))) |
| 2576 | start-point cache-pos))) | 2553 | (list strategy (and (eq strategy 'forward) start-point)))) |
| 2577 | |||
| 2578 | ;; Might we be better off starting from the top level, two defuns back, | ||
| 2579 | ;; instead? This heuristic no longer works well in C++, where | ||
| 2580 | ;; declarations inside namespace brace blocks are frequently placed at | ||
| 2581 | ;; column zero. | ||
| 2582 | (when (and (not (c-major-mode-is 'c++-mode)) | ||
| 2583 | (> how-far c-state-cache-too-far)) | ||
| 2584 | (setq BOD-pos (c-get-fallback-scan-pos here)) ; somewhat EXPENSIVE!!! | ||
| 2585 | (if (< (- here BOD-pos) how-far) | ||
| 2586 | (setq strategy 'BOD | ||
| 2587 | start-point BOD-pos))) | ||
| 2588 | |||
| 2589 | (list | ||
| 2590 | strategy | ||
| 2591 | (and (memq strategy '(forward BOD)) start-point)))) | ||
| 2592 | 2554 | ||
| 2593 | 2555 | ||
| 2594 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2556 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -2630,7 +2592,7 @@ comment at the start of cc-engine.el for more info." | |||
| 2630 | 2592 | ||
| 2631 | (setq c-state-point-min (point-min))) | 2593 | (setq c-state-point-min (point-min))) |
| 2632 | 2594 | ||
| 2633 | (defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim) | 2595 | (defun c-append-lower-brace-pair-to-state-cache (from here &optional upper-lim) |
| 2634 | ;; If there is a brace pair preceding FROM in the buffer, at the same level | 2596 | ;; If there is a brace pair preceding FROM in the buffer, at the same level |
| 2635 | ;; of nesting (not necessarily immediately preceding), push a cons onto | 2597 | ;; of nesting (not necessarily immediately preceding), push a cons onto |
| 2636 | ;; `c-state-cache' to represent it. FROM must not be inside a literal. If | 2598 | ;; `c-state-cache' to represent it. FROM must not be inside a literal. If |
| @@ -2654,8 +2616,7 @@ comment at the start of cc-engine.el for more info." | |||
| 2654 | ;; reduce the time wasted in repeated fruitless searches in brace deserts. | 2616 | ;; reduce the time wasted in repeated fruitless searches in brace deserts. |
| 2655 | (save-excursion | 2617 | (save-excursion |
| 2656 | (save-restriction | 2618 | (save-restriction |
| 2657 | (let* ((here (point-max)) | 2619 | (let* (new-cons |
| 2658 | new-cons | ||
| 2659 | (cache-pos (c-state-cache-top-lparen)) ; might be nil. | 2620 | (cache-pos (c-state-cache-top-lparen)) ; might be nil. |
| 2660 | (macro-start-or-from | 2621 | (macro-start-or-from |
| 2661 | (progn (goto-char from) | 2622 | (progn (goto-char from) |
| @@ -2690,7 +2651,6 @@ comment at the start of cc-engine.el for more info." | |||
| 2690 | ;; search bound, even though the algorithm below would skip | 2651 | ;; search bound, even though the algorithm below would skip |
| 2691 | ;; over the new paren pair. | 2652 | ;; over the new paren pair. |
| 2692 | (cache-lim (and cache-pos (< cache-pos from) cache-pos))) | 2653 | (cache-lim (and cache-pos (< cache-pos from) cache-pos))) |
| 2693 | (widen) | ||
| 2694 | (narrow-to-region | 2654 | (narrow-to-region |
| 2695 | (cond | 2655 | (cond |
| 2696 | ((and desert-lim cache-lim) | 2656 | ((and desert-lim cache-lim) |
| @@ -2698,7 +2658,9 @@ comment at the start of cc-engine.el for more info." | |||
| 2698 | (desert-lim) | 2658 | (desert-lim) |
| 2699 | (cache-lim) | 2659 | (cache-lim) |
| 2700 | ((point-min))) | 2660 | ((point-min))) |
| 2701 | (point-max))) | 2661 | ;; The top limit is EOB to ensure that `bra' is inside the |
| 2662 | ;; accessible part of the buffer at the next scan operation. | ||
| 2663 | (1+ (buffer-size)))) | ||
| 2702 | 2664 | ||
| 2703 | ;; In the next pair of nested loops, the inner one moves back past a | 2665 | ;; In the next pair of nested loops, the inner one moves back past a |
| 2704 | ;; pair of (mis-)matching parens or brackets; the outer one moves | 2666 | ;; pair of (mis-)matching parens or brackets; the outer one moves |
| @@ -2765,25 +2727,24 @@ comment at the start of cc-engine.el for more info." | |||
| 2765 | (if (consp (car c-state-cache)) | 2727 | (if (consp (car c-state-cache)) |
| 2766 | (cdr c-state-cache) | 2728 | (cdr c-state-cache) |
| 2767 | c-state-cache))) | 2729 | c-state-cache))) |
| 2768 | ;; N.B. This defsubst codes one method for the simple, normal case, | 2730 | ;; N.B. This defsubst codes one method for the simple, normal case, |
| 2769 | ;; and a more sophisticated, slower way for the general case. Don't | 2731 | ;; and a more sophisticated, slower way for the general case. Don't |
| 2770 | ;; eliminate this defsubst - it's a speed optimization. | 2732 | ;; eliminate this defsubst - it's a speed optimization. |
| 2771 | (c-append-lower-brace-pair-to-state-cache (1- bra+1))))) | 2733 | (c-append-lower-brace-pair-to-state-cache (1- bra+1) (point-max))))) |
| 2772 | 2734 | ||
| 2773 | (defun c-append-to-state-cache (from) | 2735 | (defun c-append-to-state-cache (from here) |
| 2774 | ;; Scan the buffer from FROM to (point-max), adding elements into | 2736 | ;; Scan the buffer from FROM to HERE, adding elements into `c-state-cache' |
| 2775 | ;; `c-state-cache' for braces etc. Return a candidate for | 2737 | ;; for braces etc. Return a candidate for `c-state-cache-good-pos'. |
| 2776 | ;; `c-state-cache-good-pos'. | ||
| 2777 | ;; | 2738 | ;; |
| 2778 | ;; FROM must be after the latest brace/paren/bracket in `c-state-cache', if | 2739 | ;; FROM must be after the latest brace/paren/bracket in `c-state-cache', if |
| 2779 | ;; any. Typically, it is immediately after it. It must not be inside a | 2740 | ;; any. Typically, it is immediately after it. It must not be inside a |
| 2780 | ;; literal. | 2741 | ;; literal. |
| 2781 | (let ((here-bol (c-point 'bol (point-max))) | 2742 | (let ((here-bol (c-point 'bol here)) |
| 2782 | (macro-start-or-here | 2743 | (macro-start-or-here |
| 2783 | (save-excursion (goto-char (point-max)) | 2744 | (save-excursion (goto-char here) |
| 2784 | (if (c-beginning-of-macro) | 2745 | (if (c-beginning-of-macro) |
| 2785 | (point) | 2746 | (point) |
| 2786 | (point-max)))) | 2747 | here))) |
| 2787 | pa+1 ; pos just after an opening PAren (or brace). | 2748 | pa+1 ; pos just after an opening PAren (or brace). |
| 2788 | (ren+1 from) ; usually a pos just after an closing paREN etc. | 2749 | (ren+1 from) ; usually a pos just after an closing paREN etc. |
| 2789 | ; Is actually the pos. to scan for a (/{/[ from, | 2750 | ; Is actually the pos. to scan for a (/{/[ from, |
| @@ -2796,75 +2757,77 @@ comment at the start of cc-engine.el for more info." | |||
| 2796 | mstart) ; start of a macro. | 2757 | mstart) ; start of a macro. |
| 2797 | 2758 | ||
| 2798 | (save-excursion | 2759 | (save-excursion |
| 2799 | ;; Each time round the following loop, we enter a successively deeper | 2760 | (save-restriction |
| 2800 | ;; level of brace/paren nesting. (Except sometimes we "continue at | 2761 | (narrow-to-region (point-min) here) |
| 2801 | ;; the existing level".) `pa+1' is a pos inside an opening | 2762 | ;; Each time round the following loop, we enter a successively deeper |
| 2802 | ;; brace/paren/bracket, usually just after it. | 2763 | ;; level of brace/paren nesting. (Except sometimes we "continue at |
| 2803 | (while | 2764 | ;; the existing level".) `pa+1' is a pos inside an opening |
| 2804 | (progn | 2765 | ;; brace/paren/bracket, usually just after it. |
| 2805 | ;; Each time round the next loop moves forward over an opening then | 2766 | (while |
| 2806 | ;; a closing brace/bracket/paren. This loop is white hot, so it | 2767 | (progn |
| 2807 | ;; plays ugly tricks to go fast. DON'T PUT ANYTHING INTO THIS | 2768 | ;; Each time round the next loop moves forward over an opening then |
| 2808 | ;; LOOP WHICH ISN'T ABSOLUTELY NECESSARY!!! It terminates when a | 2769 | ;; a closing brace/bracket/paren. This loop is white hot, so it |
| 2809 | ;; call of `scan-lists' signals an error, which happens when there | 2770 | ;; plays ugly tricks to go fast. DON'T PUT ANYTHING INTO THIS |
| 2810 | ;; are no more b/b/p's to scan. | 2771 | ;; LOOP WHICH ISN'T ABSOLUTELY NECESSARY!!! It terminates when a |
| 2811 | (c-safe | 2772 | ;; call of `scan-lists' signals an error, which happens when there |
| 2812 | (while t | 2773 | ;; are no more b/b/p's to scan. |
| 2813 | (setq pa+1 (scan-lists ren+1 1 -1) ; Into (/{/[; might signal | 2774 | (c-safe |
| 2814 | paren+1s (cons pa+1 paren+1s)) | 2775 | (while t |
| 2815 | (setq ren+1 (scan-lists pa+1 1 1)) ; Out of )/}/]; might signal | 2776 | (setq pa+1 (scan-lists ren+1 1 -1) ; Into (/{/[; might signal |
| 2816 | (if (and (eq (char-before pa+1) ?{)) ; Check for a macro later. | 2777 | paren+1s (cons pa+1 paren+1s)) |
| 2817 | (setq bra+1 pa+1)) | 2778 | (setq ren+1 (scan-lists pa+1 1 1)) ; Out of )/}/]; might signal |
| 2818 | (setcar paren+1s ren+1))) | 2779 | (if (and (eq (char-before pa+1) ?{)) ; Check for a macro later. |
| 2819 | 2780 | (setq bra+1 pa+1)) | |
| 2820 | (if (and pa+1 (> pa+1 ren+1)) | 2781 | (setcar paren+1s ren+1))) |
| 2821 | ;; We've just entered a deeper nesting level. | 2782 | |
| 2822 | (progn | 2783 | (if (and pa+1 (> pa+1 ren+1)) |
| 2823 | ;; Insert the brace pair (if present) and the single open | 2784 | ;; We've just entered a deeper nesting level. |
| 2824 | ;; paren/brace/bracket into `c-state-cache' It cannot be | 2785 | (progn |
| 2825 | ;; inside a macro, except one around point, because of what | 2786 | ;; Insert the brace pair (if present) and the single open |
| 2826 | ;; `c-neutralize-syntax-in-CPP' has done. | 2787 | ;; paren/brace/bracket into `c-state-cache' It cannot be |
| 2827 | (c-state-push-any-brace-pair bra+1 macro-start-or-here) | 2788 | ;; inside a macro, except one around point, because of what |
| 2828 | ;; Insert the opening brace/bracket/paren position. | 2789 | ;; `c-neutralize-syntax-in-CPP' has done. |
| 2829 | (setq c-state-cache (cons (1- pa+1) c-state-cache)) | 2790 | (c-state-push-any-brace-pair bra+1 macro-start-or-here) |
| 2830 | ;; Clear admin stuff for the next more nested part of the scan. | 2791 | ;; Insert the opening brace/bracket/paren position. |
| 2831 | (setq ren+1 pa+1 pa+1 nil bra+1 nil bra+1s nil) | 2792 | (setq c-state-cache (cons (1- pa+1) c-state-cache)) |
| 2832 | t) ; Carry on the loop | 2793 | ;; Clear admin stuff for the next more nested part of the scan. |
| 2833 | 2794 | (setq ren+1 pa+1 pa+1 nil bra+1 nil bra+1s nil) | |
| 2834 | ;; All open p/b/b's at this nesting level, if any, have probably | 2795 | t) ; Carry on the loop |
| 2835 | ;; been closed by matching/mismatching ones. We're probably | 2796 | |
| 2836 | ;; finished - we just need to check for having found an | 2797 | ;; All open p/b/b's at this nesting level, if any, have probably |
| 2837 | ;; unmatched )/}/], which we ignore. Such a )/}/] can't be in a | 2798 | ;; been closed by matching/mismatching ones. We're probably |
| 2838 | ;; macro, due the action of `c-neutralize-syntax-in-CPP'. | 2799 | ;; finished - we just need to check for having found an |
| 2839 | (c-safe (setq ren+1 (scan-lists ren+1 1 1)))))) ; acts as loop control. | 2800 | ;; unmatched )/}/], which we ignore. Such a )/}/] can't be in a |
| 2840 | 2801 | ;; macro, due the action of `c-neutralize-syntax-in-CPP'. | |
| 2841 | ;; Record the final, innermost, brace-pair if there is one. | 2802 | (c-safe (setq ren+1 (scan-lists ren+1 1 1)))))) ; acts as loop control. |
| 2842 | (c-state-push-any-brace-pair bra+1 macro-start-or-here) | 2803 | |
| 2843 | 2804 | ;; Record the final, innermost, brace-pair if there is one. | |
| 2844 | ;; Determine a good pos | 2805 | (c-state-push-any-brace-pair bra+1 macro-start-or-here) |
| 2845 | (while (and (setq paren+1 (car paren+1s)) | 2806 | |
| 2846 | (> (if (> paren+1 macro-start-or-here) | 2807 | ;; Determine a good pos |
| 2847 | paren+1 | 2808 | (while (and (setq paren+1 (car paren+1s)) |
| 2848 | (goto-char paren+1) | 2809 | (> (if (> paren+1 macro-start-or-here) |
| 2849 | (setq mstart (and (c-beginning-of-macro) | 2810 | paren+1 |
| 2850 | (point))) | 2811 | (goto-char paren+1) |
| 2851 | (or mstart paren+1)) | 2812 | (setq mstart (and (c-beginning-of-macro) |
| 2852 | here-bol)) | 2813 | (point))) |
| 2853 | (setq paren+1s (cdr paren+1s))) | 2814 | (or mstart paren+1)) |
| 2854 | (cond | 2815 | here-bol)) |
| 2855 | ((and paren+1 mstart) | 2816 | (setq paren+1s (cdr paren+1s))) |
| 2856 | (min paren+1 mstart)) | 2817 | (cond |
| 2857 | (paren+1) | 2818 | ((and paren+1 mstart) |
| 2858 | (t from))))) | 2819 | (min paren+1 mstart)) |
| 2820 | (paren+1) | ||
| 2821 | (t from)))))) | ||
| 2859 | 2822 | ||
| 2860 | (defun c-remove-stale-state-cache (start-point pps-point) | 2823 | (defun c-remove-stale-state-cache (start-point here pps-point) |
| 2861 | ;; Remove stale entries from the `c-cache-state', i.e. those which will | 2824 | ;; Remove stale entries from the `c-cache-state', i.e. those which will |
| 2862 | ;; not be in it when it is amended for position (point-max). | 2825 | ;; not be in it when it is amended for position HERE. Additionally, the |
| 2863 | ;; Additionally, the "outermost" open-brace entry before (point-max) | 2826 | ;; "outermost" open-brace entry before HERE will be converted to a cons if |
| 2864 | ;; will be converted to a cons if the matching close-brace is scanned. | 2827 | ;; the matching close-brace is scanned. |
| 2865 | ;; | 2828 | ;; |
| 2866 | ;; START-POINT is a "maximal" "safe position" - there must be no open | 2829 | ;; START-POINT is a "maximal" "safe position" - there must be no open |
| 2867 | ;; parens/braces/brackets between START-POINT and (point-max). | 2830 | ;; parens/braces/brackets between START-POINT and HERE. |
| 2868 | ;; | 2831 | ;; |
| 2869 | ;; As a second thing, calculate the result of parse-partial-sexp at | 2832 | ;; As a second thing, calculate the result of parse-partial-sexp at |
| 2870 | ;; PPS-POINT, w.r.t. START-POINT. The motivation here is that | 2833 | ;; PPS-POINT, w.r.t. START-POINT. The motivation here is that |
| @@ -2881,23 +2844,23 @@ comment at the start of cc-engine.el for more info." | |||
| 2881 | ;; last element to be removed from `c-state-cache', when that elt is a | 2844 | ;; last element to be removed from `c-state-cache', when that elt is a |
| 2882 | ;; cons, otherwise nil. | 2845 | ;; cons, otherwise nil. |
| 2883 | ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT. | 2846 | ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT. |
| 2884 | (save-restriction | 2847 | (save-excursion |
| 2885 | (narrow-to-region 1 (point-max)) | 2848 | (save-restriction |
| 2886 | (save-excursion | 2849 | (narrow-to-region 1 (point-max)) |
| 2887 | (let* ((in-macro-start ; start of macro containing (point-max) or nil. | 2850 | (let* ((in-macro-start ; start of macro containing HERE or nil. |
| 2888 | (save-excursion | 2851 | (save-excursion |
| 2889 | (goto-char (point-max)) | 2852 | (goto-char here) |
| 2890 | (and (c-beginning-of-macro) | 2853 | (and (c-beginning-of-macro) |
| 2891 | (point)))) | 2854 | (point)))) |
| 2892 | (start-point-actual-macro-start ; Start of macro containing | 2855 | (start-point-actual-macro-start ; Start of macro containing |
| 2893 | ; start-point or nil | 2856 | ; start-point or nil |
| 2894 | (and (< start-point (point-max)) | 2857 | (and (< start-point here) |
| 2895 | (save-excursion | 2858 | (save-excursion |
| 2896 | (goto-char start-point) | 2859 | (goto-char start-point) |
| 2897 | (and (c-beginning-of-macro) | 2860 | (and (c-beginning-of-macro) |
| 2898 | (point))))) | 2861 | (point))))) |
| 2899 | (start-point-actual-macro-end ; End of this macro, (maybe | 2862 | (start-point-actual-macro-end ; End of this macro, (maybe |
| 2900 | ; (point-max)), or nil. | 2863 | ; HERE), or nil. |
| 2901 | (and start-point-actual-macro-start | 2864 | (and start-point-actual-macro-start |
| 2902 | (save-excursion | 2865 | (save-excursion |
| 2903 | (goto-char start-point-actual-macro-start) | 2866 | (goto-char start-point-actual-macro-start) |
| @@ -2909,14 +2872,14 @@ comment at the start of cc-engine.el for more info." | |||
| 2909 | scan-back-pos | 2872 | scan-back-pos |
| 2910 | pair-beg pps-point-state target-depth) | 2873 | pair-beg pps-point-state target-depth) |
| 2911 | 2874 | ||
| 2912 | ;; Remove entries beyond (point-max). Also remove any entries inside | 2875 | ;; Remove entries beyond HERE. Also remove any entries inside |
| 2913 | ;; a macro, unless (point-max) is in the same macro. | 2876 | ;; a macro, unless HERE is in the same macro. |
| 2914 | (setq upper-lim | 2877 | (setq upper-lim |
| 2915 | (if (or (null c-state-old-cpp-beg) | 2878 | (if (or (null c-state-old-cpp-beg) |
| 2916 | (and (> (point-max) c-state-old-cpp-beg) | 2879 | (and (> here c-state-old-cpp-beg) |
| 2917 | (< (point-max) c-state-old-cpp-end))) | 2880 | (< here c-state-old-cpp-end))) |
| 2918 | (point-max) | 2881 | here |
| 2919 | (min (point-max) c-state-old-cpp-beg))) | 2882 | (min here c-state-old-cpp-beg))) |
| 2920 | (while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim)) | 2883 | (while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim)) |
| 2921 | (setq scan-back-pos (car-safe (car c-state-cache))) | 2884 | (setq scan-back-pos (car-safe (car c-state-cache))) |
| 2922 | (setq c-state-cache (cdr c-state-cache))) | 2885 | (setq c-state-cache (cdr c-state-cache))) |
| @@ -2934,7 +2897,7 @@ comment at the start of cc-engine.el for more info." | |||
| 2934 | ;; time round; the corresponding elements in `c-state-cache' are | 2897 | ;; time round; the corresponding elements in `c-state-cache' are |
| 2935 | ;; removed. `pos' is just after the brace-pair or the open paren at | 2898 | ;; removed. `pos' is just after the brace-pair or the open paren at |
| 2936 | ;; (car c-state-cache). There can be no open parens/braces/brackets | 2899 | ;; (car c-state-cache). There can be no open parens/braces/brackets |
| 2937 | ;; between `start-point'/`start-point-actual-macro-start' and (point-max), | 2900 | ;; between `start-point'/`start-point-actual-macro-start' and HERE, |
| 2938 | ;; due to the interface spec to this function. | 2901 | ;; due to the interface spec to this function. |
| 2939 | (setq pos (if (and start-point-actual-macro-end | 2902 | (setq pos (if (and start-point-actual-macro-end |
| 2940 | (not (eq start-point-actual-macro-start | 2903 | (not (eq start-point-actual-macro-start |
| @@ -2944,7 +2907,9 @@ comment at the start of cc-engine.el for more info." | |||
| 2944 | start-point)) | 2907 | start-point)) |
| 2945 | (goto-char pos) | 2908 | (goto-char pos) |
| 2946 | (while (and c-state-cache | 2909 | (while (and c-state-cache |
| 2947 | (< (point) (point-max))) | 2910 | (or (numberp (car c-state-cache)) ; Have we a { at all? |
| 2911 | (cdr c-state-cache)) | ||
| 2912 | (< (point) here)) | ||
| 2948 | (cond | 2913 | (cond |
| 2949 | ((null pps-state) ; first time through | 2914 | ((null pps-state) ; first time through |
| 2950 | (setq target-depth -1)) | 2915 | (setq target-depth -1)) |
| @@ -2956,7 +2921,7 @@ comment at the start of cc-engine.el for more info." | |||
| 2956 | ;; Scan! | 2921 | ;; Scan! |
| 2957 | (setq pps-state | 2922 | (setq pps-state |
| 2958 | (parse-partial-sexp | 2923 | (parse-partial-sexp |
| 2959 | (point) (if (< (point) pps-point) pps-point (point-max)) | 2924 | (point) (if (< (point) pps-point) pps-point here) |
| 2960 | target-depth | 2925 | target-depth |
| 2961 | nil pps-state)) | 2926 | nil pps-state)) |
| 2962 | 2927 | ||
| @@ -3209,7 +3174,7 @@ comment at the start of cc-engine.el for more info." | |||
| 3209 | ;; Do we need to add in an earlier brace pair, having lopped one off? | 3174 | ;; Do we need to add in an earlier brace pair, having lopped one off? |
| 3210 | (if (and dropped-cons | 3175 | (if (and dropped-cons |
| 3211 | (< too-high-pa (+ here c-state-cache-too-far))) | 3176 | (< too-high-pa (+ here c-state-cache-too-far))) |
| 3212 | (c-append-lower-brace-pair-to-state-cache too-high-pa here-bol)) | 3177 | (c-append-lower-brace-pair-to-state-cache too-high-pa here here-bol)) |
| 3213 | (setq c-state-cache-good-pos (or (c-state-cache-after-top-paren) | 3178 | (setq c-state-cache-good-pos (or (c-state-cache-after-top-paren) |
| 3214 | (c-state-get-min-scan-pos))))) | 3179 | (c-state-get-min-scan-pos))))) |
| 3215 | 3180 | ||
| @@ -3285,47 +3250,39 @@ comment at the start of cc-engine.el for more info." | |||
| 3285 | strategy (car res) | 3250 | strategy (car res) |
| 3286 | start-point (cadr res)) | 3251 | start-point (cadr res)) |
| 3287 | 3252 | ||
| 3288 | (when (eq strategy 'BOD) | ||
| 3289 | (setq c-state-cache nil | ||
| 3290 | c-state-cache-good-pos start-point)) | ||
| 3291 | |||
| 3292 | ;; SCAN! | 3253 | ;; SCAN! |
| 3293 | (save-restriction | 3254 | (cond |
| 3294 | (cond | 3255 | ((eq strategy 'forward) |
| 3295 | ((memq strategy '(forward BOD)) | 3256 | (setq res (c-remove-stale-state-cache start-point here here-bopl)) |
| 3296 | (narrow-to-region (point-min) here) | 3257 | (setq cache-pos (car res) |
| 3297 | (setq res (c-remove-stale-state-cache start-point here-bopl)) | 3258 | scan-backward-pos (cadr res) |
| 3298 | (setq cache-pos (car res) | 3259 | bopl-state (car (cddr res))) ; will be nil if (< here-bopl |
| 3299 | scan-backward-pos (cadr res) | ||
| 3300 | bopl-state (car (cddr res))) ; will be nil if (< here-bopl | ||
| 3301 | ; start-point) | 3260 | ; start-point) |
| 3302 | (if scan-backward-pos | 3261 | (if scan-backward-pos |
| 3303 | (c-append-lower-brace-pair-to-state-cache scan-backward-pos)) | 3262 | (c-append-lower-brace-pair-to-state-cache scan-backward-pos here)) |
| 3304 | (setq good-pos | 3263 | (setq good-pos |
| 3305 | (c-append-to-state-cache cache-pos)) | 3264 | (c-append-to-state-cache cache-pos here)) |
| 3306 | (setq c-state-cache-good-pos | 3265 | (setq c-state-cache-good-pos |
| 3307 | (if (and bopl-state | 3266 | (if (and bopl-state |
| 3308 | (< good-pos (- here c-state-cache-too-far))) | 3267 | (< good-pos (- here c-state-cache-too-far))) |
| 3309 | (c-state-cache-non-literal-place here-bopl bopl-state) | 3268 | (c-state-cache-non-literal-place here-bopl bopl-state) |
| 3310 | good-pos))) | 3269 | good-pos))) |
| 3311 | 3270 | ||
| 3312 | ((eq strategy 'backward) | 3271 | ((eq strategy 'backward) |
| 3313 | (setq res (c-remove-stale-state-cache-backwards here) | 3272 | (setq res (c-remove-stale-state-cache-backwards here) |
| 3314 | good-pos (car res) | 3273 | good-pos (car res) |
| 3315 | scan-backward-pos (cadr res) | 3274 | scan-backward-pos (cadr res) |
| 3316 | scan-forward-p (car (cddr res))) | 3275 | scan-forward-p (car (cddr res))) |
| 3317 | (if scan-backward-pos | 3276 | (if scan-backward-pos |
| 3318 | (c-append-lower-brace-pair-to-state-cache | 3277 | (c-append-lower-brace-pair-to-state-cache scan-backward-pos here)) |
| 3319 | scan-backward-pos)) | 3278 | (setq c-state-cache-good-pos |
| 3320 | (setq c-state-cache-good-pos | 3279 | (if scan-forward-p |
| 3321 | (if scan-forward-p | 3280 | (c-append-to-state-cache good-pos here) |
| 3322 | (progn (narrow-to-region (point-min) here) | 3281 | good-pos))) |
| 3323 | (c-append-to-state-cache good-pos)) | 3282 | |
| 3324 | good-pos))) | 3283 | (t ; (eq strategy 'IN-LIT) |
| 3325 | 3284 | (setq c-state-cache nil | |
| 3326 | (t ; (eq strategy 'IN-LIT) | 3285 | c-state-cache-good-pos nil)))) |
| 3327 | (setq c-state-cache nil | ||
| 3328 | c-state-cache-good-pos nil))))) | ||
| 3329 | 3286 | ||
| 3330 | c-state-cache) | 3287 | c-state-cache) |
| 3331 | 3288 | ||