Merge changes from emacs-23 branch
[bpt/emacs.git] / lisp / isearch.el
index 89d50d6..6f89e0e 100644 (file)
@@ -2581,6 +2581,7 @@ since they have special meaning in a regexp."
 (defvar isearch-lazy-highlight-case-fold-search nil)
 (defvar isearch-lazy-highlight-regexp nil)
 (defvar isearch-lazy-highlight-space-regexp nil)
+(defvar isearch-lazy-highlight-forward nil)
 
 (defun lazy-highlight-cleanup (&optional force)
   "Stop lazy highlighting and remove extra highlighting from current buffer.
@@ -2620,7 +2621,9 @@ by other Emacs features."
                  (not (= (window-start)
                          isearch-lazy-highlight-window-start))
                  (not (= (window-end)   ; Window may have been split/joined.
-                         isearch-lazy-highlight-window-end))))
+                        isearch-lazy-highlight-window-end))
+                (not (eq isearch-forward
+                         isearch-lazy-highlight-forward))))
     ;; something important did indeed change
     (lazy-highlight-cleanup t) ;kill old loop & remove overlays
     (when (not isearch-error)
@@ -2635,7 +2638,8 @@ by other Emacs features."
            isearch-lazy-highlight-case-fold-search isearch-case-fold-search
            isearch-lazy-highlight-regexp       isearch-regexp
             isearch-lazy-highlight-wrapped      nil
-           isearch-lazy-highlight-space-regexp search-whitespace-regexp)
+           isearch-lazy-highlight-space-regexp search-whitespace-regexp
+           isearch-lazy-highlight-forward      isearch-forward)
       (unless (equal isearch-string "")
        (setq isearch-lazy-highlight-timer
              (run-with-idle-timer lazy-highlight-initial-delay nil
@@ -2651,7 +2655,8 @@ Attempt to do the search exactly the way the pending Isearch would."
            (search-invisible nil)      ; don't match invisible text
            (retry t)
            (success nil)
-           (bound (if isearch-forward
+           (isearch-forward isearch-lazy-highlight-forward)
+           (bound (if isearch-lazy-highlight-forward
                       (min (or isearch-lazy-highlight-end-limit (point-max))
                            (if isearch-lazy-highlight-wrapped
                                isearch-lazy-highlight-start
@@ -2687,7 +2692,7 @@ Attempt to do the search exactly the way the pending Isearch would."
            (select-window isearch-lazy-highlight-window))
        (save-excursion
          (save-match-data
-           (goto-char (if isearch-forward
+           (goto-char (if isearch-lazy-highlight-forward
                           isearch-lazy-highlight-end
                         isearch-lazy-highlight-start))
            (while looping
@@ -2700,7 +2705,7 @@ Attempt to do the search exactly the way the pending Isearch would."
                    (let ((mb (match-beginning 0))
                          (me (match-end 0)))
                      (if (= mb me)     ;zero-length match
-                         (if isearch-forward
+                         (if isearch-lazy-highlight-forward
                              (if (= mb (if isearch-lazy-highlight-wrapped
                                            isearch-lazy-highlight-start
                                          (window-end)))
@@ -2720,7 +2725,7 @@ Attempt to do the search exactly the way the pending Isearch would."
                          (overlay-put ov 'priority 1000)
                          (overlay-put ov 'face lazy-highlight-face)
                          (overlay-put ov 'window (selected-window))))
-                     (if isearch-forward
+                     (if isearch-lazy-highlight-forward
                          (setq isearch-lazy-highlight-end (point))
                        (setq isearch-lazy-highlight-start (point)))))
 
@@ -2730,7 +2735,7 @@ Attempt to do the search exactly the way the pending Isearch would."
                        (setq looping nil
                              nomore  t)
                      (setq isearch-lazy-highlight-wrapped t)
-                     (if isearch-forward
+                     (if isearch-lazy-highlight-forward
                          (progn
                            (setq isearch-lazy-highlight-end (window-start))
                            (goto-char (max (or isearch-lazy-highlight-start-limit (point-min))