emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-24 r107993: CC Mode. Adding a ) can h


From: Alan Mackenzie
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-24 r107993: CC Mode. Adding a ) can hide the resulting (..) from searches. Fix it.
Date: Fri, 02 Nov 2012 02:17:29 -0000
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 107993
committer: Alan Mackenzie <address@hidden>
branch nick: trunk
timestamp: Sun 2012-04-22 11:13:09 +0000
message:
  CC Mode.  Adding a ) can hide the resulting (..) from searches.  Fix it.
modified:
  lisp/ChangeLog
  lisp/progmodes/cc-engine.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-04-21 16:57:49 +0000
+++ b/lisp/ChangeLog    2012-04-22 11:13:09 +0000
@@ -1,3 +1,9 @@
+2012-04-22  Alan Mackenzie  <address@hidden>
+
+       * progmodes/cc-engine.el (c-append-lower-brace-pair-to-state-cache):
+       Adding a ) can hide the resulting (..) from searches.  Fix it.
+       Bound the backward search to the position of the existing (.
+
 2012-04-21  Juanma Barranquero  <address@hidden>
 
        * progmodes/verilog-mode.el (verilog-mode): Check whether

=== modified file 'lisp/progmodes/cc-engine.el'
--- a/lisp/progmodes/cc-engine.el       2012-04-11 15:32:30 +0000
+++ b/lisp/progmodes/cc-engine.el       2012-04-22 11:13:09 +0000
@@ -2612,13 +2612,24 @@
   (setq c-state-point-min (point-min)))
 
 (defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim)
-  ;; If there is a brace pair preceding FROM in the buffer (not necessarily
-  ;; immediately preceding), push a cons onto `c-state-cache' to represent it.
-  ;; FROM must not be inside a literal.  If UPPER-LIM is non-nil, we append
-  ;; the highest brace pair whose "}" is below UPPER-LIM.
+  ;; If there is a brace pair preceding FROM in the buffer, at the same level
+  ;; of nesting (not necessarily immediately preceding), push a cons onto
+  ;; `c-state-cache' to represent it.  FROM must not be inside a literal.  If
+  ;; UPPER-LIM is non-nil, we append the highest brace pair whose "}" is below
+  ;; UPPER-LIM.
   ;;
   ;; Return non-nil when this has been done.
   ;;
+  ;; The situation it copes with is this transformation:
+  ;;
+  ;; OLD:   {                       (.)    {...........}
+  ;;                                       ^             ^
+  ;;                                     FROM          HERE
+  ;;                                     
+  ;; NEW:   {             {....}    (.)    {.........
+  ;;                         ^           ^           ^
+  ;;                LOWER BRACE PAIR   HERE   or   HERE
+  ;;                                       
   ;; This routine should be fast.  Since it can get called a LOT, we maintain
   ;; `c-state-brace-pair-desert', a small cache of "failures", such that we
   ;; reduce the time wasted in repeated fruitless searches in brace deserts.
@@ -2637,10 +2648,25 @@
        (unless (and c-state-brace-pair-desert
                     (eq cache-pos (car c-state-brace-pair-desert))
                     (<= from (cdr c-state-brace-pair-desert)))
-         ;; Only search what we absolutely need to:
-         (if (and c-state-brace-pair-desert
-                  (eq cache-pos (car c-state-brace-pair-desert)))
-             (narrow-to-region (cdr c-state-brace-pair-desert) (point-max)))
+         ;; DESERT-LIM.  Only search what we absolutely need to,
+         (let ((desert-lim
+                (and c-state-brace-pair-desert
+                     (eq cache-pos (car c-state-brace-pair-desert))
+                     (cdr c-state-brace-pair-desert)))
+               ;; CACHE-LIM.  This limit will be necessary when an opening
+               ;; paren at `cache-pos' has just had its matching close paren
+               ;; inserted.  `cache-pos' continues to be a search bound, even
+               ;; though the algorithm below would skip over the new paren
+               ;; pair.
+               (cache-lim (and cache-pos (< cache-pos from) cache-pos)))
+           (narrow-to-region
+               (cond
+                ((and desert-lim cache-lim)
+                 (max desert-lim cache-lim))
+                (desert-lim)
+                (cache-lim)
+                ((point-min)))
+               (point-max)))
 
          ;; In the next pair of nested loops, the inner one moves back past a
          ;; pair of (mis-)matching parens or brackets; the outer one moves
@@ -2674,7 +2700,7 @@
                          (cons new-cons (cdr c-state-cache))))
                 (t (setq c-state-cache (cons new-cons c-state-cache)))))
 
-           ;; We haven't found a brace pair.  Record this.
+           ;; We haven't found a brace pair.  Record this in the cache.
            (setq c-state-brace-pair-desert (cons cache-pos from))))))))
 
 (defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]