aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2012-04-22 11:13:09 +0000
committerAlan Mackenzie2012-04-22 11:13:09 +0000
commit583e23bd57621892cce187359afd952f7850e7bc (patch)
tree31b922f0f1d97df56614a97834c5f039baf3afbd
parentac1ca7e94815497da2cb01d48b51faa68d0fe1cb (diff)
downloademacs-583e23bd57621892cce187359afd952f7850e7bc.tar.gz
emacs-583e23bd57621892cce187359afd952f7850e7bc.zip
CC Mode. Adding a ) can hide the resulting (..) from searches. Fix it.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/cc-engine.el44
2 files changed, 41 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2ffd9ce77a8..d5576370727 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-04-22 Alan Mackenzie <acm@muc.de>
2
3 * progmodes/cc-engine.el (c-append-lower-brace-pair-to-state-cache):
4 Adding a ) can hide the resulting (..) from searches. Fix it.
5 Bound the backward search to the position of the existing (.
6
12012-04-21 Juanma Barranquero <lekktu@gmail.com> 72012-04-21 Juanma Barranquero <lekktu@gmail.com>
2 8
3 * progmodes/verilog-mode.el (verilog-mode): Check whether 9 * progmodes/verilog-mode.el (verilog-mode): Check whether
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 65e28c11e21..82aee7bdbb9 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2612,13 +2612,24 @@ comment at the start of cc-engine.el for more info."
2612 (setq c-state-point-min (point-min))) 2612 (setq c-state-point-min (point-min)))
2613 2613
2614(defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim) 2614(defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim)
2615 ;; If there is a brace pair preceding FROM in the buffer (not necessarily 2615 ;; If there is a brace pair preceding FROM in the buffer, at the same level
2616 ;; immediately preceding), push a cons onto `c-state-cache' to represent it. 2616 ;; of nesting (not necessarily immediately preceding), push a cons onto
2617 ;; FROM must not be inside a literal. If UPPER-LIM is non-nil, we append 2617 ;; `c-state-cache' to represent it. FROM must not be inside a literal. If
2618 ;; the highest brace pair whose "}" is below UPPER-LIM. 2618 ;; UPPER-LIM is non-nil, we append the highest brace pair whose "}" is below
2619 ;; UPPER-LIM.
2619 ;; 2620 ;;
2620 ;; Return non-nil when this has been done. 2621 ;; Return non-nil when this has been done.
2621 ;; 2622 ;;
2623 ;; The situation it copes with is this transformation:
2624 ;;
2625 ;; OLD: { (.) {...........}
2626 ;; ^ ^
2627 ;; FROM HERE
2628 ;;
2629 ;; NEW: { {....} (.) {.........
2630 ;; ^ ^ ^
2631 ;; LOWER BRACE PAIR HERE or HERE
2632 ;;
2622 ;; This routine should be fast. Since it can get called a LOT, we maintain 2633 ;; This routine should be fast. Since it can get called a LOT, we maintain
2623 ;; `c-state-brace-pair-desert', a small cache of "failures", such that we 2634 ;; `c-state-brace-pair-desert', a small cache of "failures", such that we
2624 ;; reduce the time wasted in repeated fruitless searches in brace deserts. 2635 ;; reduce the time wasted in repeated fruitless searches in brace deserts.
@@ -2637,10 +2648,25 @@ comment at the start of cc-engine.el for more info."
2637 (unless (and c-state-brace-pair-desert 2648 (unless (and c-state-brace-pair-desert
2638 (eq cache-pos (car c-state-brace-pair-desert)) 2649 (eq cache-pos (car c-state-brace-pair-desert))
2639 (<= from (cdr c-state-brace-pair-desert))) 2650 (<= from (cdr c-state-brace-pair-desert)))
2640 ;; Only search what we absolutely need to: 2651 ;; DESERT-LIM. Only search what we absolutely need to,
2641 (if (and c-state-brace-pair-desert 2652 (let ((desert-lim
2642 (eq cache-pos (car c-state-brace-pair-desert))) 2653 (and c-state-brace-pair-desert
2643 (narrow-to-region (cdr c-state-brace-pair-desert) (point-max))) 2654 (eq cache-pos (car c-state-brace-pair-desert))
2655 (cdr c-state-brace-pair-desert)))
2656 ;; CACHE-LIM. This limit will be necessary when an opening
2657 ;; paren at `cache-pos' has just had its matching close paren
2658 ;; inserted. `cache-pos' continues to be a search bound, even
2659 ;; though the algorithm below would skip over the new paren
2660 ;; pair.
2661 (cache-lim (and cache-pos (< cache-pos from) cache-pos)))
2662 (narrow-to-region
2663 (cond
2664 ((and desert-lim cache-lim)
2665 (max desert-lim cache-lim))
2666 (desert-lim)
2667 (cache-lim)
2668 ((point-min)))
2669 (point-max)))
2644 2670
2645 ;; In the next pair of nested loops, the inner one moves back past a 2671 ;; In the next pair of nested loops, the inner one moves back past a
2646 ;; pair of (mis-)matching parens or brackets; the outer one moves 2672 ;; pair of (mis-)matching parens or brackets; the outer one moves
@@ -2674,7 +2700,7 @@ comment at the start of cc-engine.el for more info."
2674 (cons new-cons (cdr c-state-cache)))) 2700 (cons new-cons (cdr c-state-cache))))
2675 (t (setq c-state-cache (cons new-cons c-state-cache))))) 2701 (t (setq c-state-cache (cons new-cons c-state-cache)))))
2676 2702
2677 ;; We haven't found a brace pair. Record this. 2703 ;; We haven't found a brace pair. Record this in the cache.
2678 (setq c-state-brace-pair-desert (cons cache-pos from)))))))) 2704 (setq c-state-brace-pair-desert (cons cache-pos from))))))))
2679 2705
2680(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here) 2706(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here)