emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r112749: * lisp/replace.el (replace-s


From: Juri Linkov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112749: * lisp/replace.el (replace-search): New function with code moved out
Date: Tue, 28 May 2013 02:38:56 +0300
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 112749
fixes bug: http://debbugs.gnu.org/11746
committer: Juri Linkov <address@hidden>
branch nick: trunk
timestamp: Tue 2013-05-28 02:38:56 +0300
message:
  * lisp/replace.el (replace-search): New function with code moved out
  from `perform-replace'.
  (replace-highlight, replace-dehighlight): Move function definitions
  up closer to `replace-search'.
modified:
  lisp/ChangeLog
  lisp/replace.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-05-27 23:11:21 +0000
+++ b/lisp/ChangeLog    2013-05-27 23:38:56 +0000
@@ -1,5 +1,12 @@
 2013-05-27  Juri Linkov  <address@hidden>
 
+       * replace.el (replace-search): New function with code moved out
+       from `perform-replace'.
+       (replace-highlight, replace-dehighlight): Move function definitions
+       up closer to `replace-search'.  (Bug#11746)
+
+2013-05-27  Juri Linkov  <address@hidden>
+
        * replace.el (perform-replace): Ignore invisible matches.
        In addition to checking `query-replace-skip-read-only', also
        filter out matches by calling `run-hook-with-args-until-failure'

=== modified file 'lisp/replace.el'
--- a/lisp/replace.el   2013-05-27 23:02:37 +0000
+++ b/lisp/replace.el   2013-05-27 23:38:56 +0000
@@ -1838,6 +1838,68 @@
 It is called with three arguments, as if it were
 `re-search-forward'.")
 
+(defun replace-search (search-string limit regexp-flag delimited-flag
+                                    case-fold-search)
+  "Search for the next occurence of SEARCH-STRING to replace."
+  ;; Let-bind global isearch-* variables to values used
+  ;; to search the next replacement.  These let-bindings
+  ;; should be effective both at the time of calling
+  ;; `isearch-search-fun-default' and also at the
+  ;; time of funcalling `search-function'.
+  ;; These isearch-* bindings can't be placed higher
+  ;; outside of this function because then another I-search
+  ;; used after `recursive-edit' might override them.
+  (let* ((isearch-regexp regexp-flag)
+        (isearch-word delimited-flag)
+        (isearch-lax-whitespace
+         replace-lax-whitespace)
+        (isearch-regexp-lax-whitespace
+         replace-regexp-lax-whitespace)
+        (isearch-case-fold-search case-fold-search)
+        (isearch-adjusted nil)
+        (isearch-nonincremental t)     ; don't use lax word mode
+        (isearch-forward t)
+        (search-function
+         (or (if regexp-flag
+                 replace-re-search-function
+               replace-search-function)
+             (isearch-search-fun-default))))
+    (funcall search-function search-string limit t)))
+
+(defvar replace-overlay nil)
+
+(defun replace-highlight (match-beg match-end range-beg range-end
+                         search-string regexp-flag delimited-flag
+                         case-fold-search)
+  (if query-replace-highlight
+      (if replace-overlay
+         (move-overlay replace-overlay match-beg match-end (current-buffer))
+       (setq replace-overlay (make-overlay match-beg match-end))
+       (overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays
+       (overlay-put replace-overlay 'face 'query-replace)))
+  (if query-replace-lazy-highlight
+      (let ((isearch-string search-string)
+           (isearch-regexp regexp-flag)
+           (isearch-word delimited-flag)
+           (isearch-lax-whitespace
+            replace-lax-whitespace)
+           (isearch-regexp-lax-whitespace
+            replace-regexp-lax-whitespace)
+           (isearch-case-fold-search case-fold-search)
+           (isearch-forward t)
+           (isearch-other-end match-beg)
+           (isearch-error nil))
+       (isearch-lazy-highlight-new-loop range-beg range-end))))
+
+(defun replace-dehighlight ()
+  (when replace-overlay
+    (delete-overlay replace-overlay))
+  (when query-replace-lazy-highlight
+    (lazy-highlight-cleanup lazy-highlight-cleanup)
+    (setq isearch-lazy-highlight-last-string nil))
+  ;; Close overlays opened by `isearch-range-invisible' in `perform-replace'.
+  (isearch-clean-overlays))
+
 (defun perform-replace (from-string replacements
                        query-flag regexp-flag delimited-flag
                        &optional repeat-count map start end)
@@ -1925,62 +1987,40 @@
        ;; Loop finding occurrences that perhaps should be replaced.
        (while (and keep-going
                    (not (or (eobp) (and limit (>= (point) limit))))
-                   ;; Let-bind global isearch-* variables to values used
-                   ;; to search the next replacement.  These let-bindings
-                   ;; should be effective both at the time of calling
-                   ;; `isearch-search-fun-default' and also at the
-                   ;; time of funcalling `search-function'.
-                   ;; These isearch-* bindings can't be placed higher
-                   ;; outside of this loop because then another I-search
-                   ;; used after `recursive-edit' might override them.
-                   (let* ((isearch-regexp regexp-flag)
-                          (isearch-word delimited-flag)
-                          (isearch-lax-whitespace
-                           replace-lax-whitespace)
-                          (isearch-regexp-lax-whitespace
-                           replace-regexp-lax-whitespace)
-                          (isearch-case-fold-search case-fold-search)
-                          (isearch-adjusted nil)
-                          (isearch-nonincremental t) ; don't use lax word mode
-                          (isearch-forward t)
-                          (search-function
-                           (or (if regexp-flag
-                                   replace-re-search-function
-                                 replace-search-function)
-                               (isearch-search-fun-default))))
-                     ;; Use the next match if it is already known;
-                     ;; otherwise, search for a match after moving forward
-                     ;; one char if progress is required.
-                     (setq real-match-data
-                           (cond ((consp match-again)
-                                  (goto-char (nth 1 match-again))
-                                  (replace-match-data
-                                   t real-match-data match-again))
-                                 ;; MATCH-AGAIN non-nil means accept an
-                                 ;; adjacent match.
-                                 (match-again
-                                  (and
-                                   (funcall search-function search-string
-                                            limit t)
-                                   ;; For speed, use only integers and
-                                   ;; reuse the list used last time.
-                                   (replace-match-data t real-match-data)))
-                                 ((and (< (1+ (point)) (point-max))
-                                       (or (null limit)
-                                           (< (1+ (point)) limit)))
-                                  ;; If not accepting adjacent matches,
-                                  ;; move one char to the right before
-                                  ;; searching again.  Undo the motion
-                                  ;; if the search fails.
-                                  (let ((opoint (point)))
-                                    (forward-char 1)
-                                    (if (funcall
-                                         search-function search-string
-                                         limit t)
-                                        (replace-match-data
-                                         t real-match-data)
-                                      (goto-char opoint)
-                                      nil)))))))
+                   ;; Use the next match if it is already known;
+                   ;; otherwise, search for a match after moving forward
+                   ;; one char if progress is required.
+                   (setq real-match-data
+                         (cond ((consp match-again)
+                                (goto-char (nth 1 match-again))
+                                (replace-match-data
+                                 t real-match-data match-again))
+                               ;; MATCH-AGAIN non-nil means accept an
+                               ;; adjacent match.
+                               (match-again
+                                (and
+                                 (replace-search search-string limit
+                                                 regexp-flag delimited-flag
+                                                 case-fold-search)
+                                 ;; For speed, use only integers and
+                                 ;; reuse the list used last time.
+                                 (replace-match-data t real-match-data)))
+                               ((and (< (1+ (point)) (point-max))
+                                     (or (null limit)
+                                         (< (1+ (point)) limit)))
+                                ;; If not accepting adjacent matches,
+                                ;; move one char to the right before
+                                ;; searching again.  Undo the motion
+                                ;; if the search fails.
+                                (let ((opoint (point)))
+                                  (forward-char 1)
+                                  (if (replace-search search-string limit
+                                                      regexp-flag 
delimited-flag
+                                                      case-fold-search)
+                                      (replace-match-data
+                                       t real-match-data)
+                                    (goto-char opoint)
+                                    nil))))))
 
          ;; Record whether the match is nonempty, to avoid an infinite loop
          ;; repeatedly matching the same empty string.
@@ -2229,38 +2269,4 @@
                 (if (= replace-count 1) "" "s")))
     (or (and keep-going stack) multi-buffer)))
 
-(defvar replace-overlay nil)
-
-(defun replace-highlight (match-beg match-end range-beg range-end
-                         search-string regexp-flag delimited-flag
-                         case-fold-search)
-  (if query-replace-highlight
-      (if replace-overlay
-         (move-overlay replace-overlay match-beg match-end (current-buffer))
-       (setq replace-overlay (make-overlay match-beg match-end))
-       (overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays
-       (overlay-put replace-overlay 'face 'query-replace)))
-  (if query-replace-lazy-highlight
-      (let ((isearch-string search-string)
-           (isearch-regexp regexp-flag)
-           (isearch-word delimited-flag)
-           (isearch-lax-whitespace
-            replace-lax-whitespace)
-           (isearch-regexp-lax-whitespace
-            replace-regexp-lax-whitespace)
-           (isearch-case-fold-search case-fold-search)
-           (isearch-forward t)
-           (isearch-other-end match-beg)
-           (isearch-error nil))
-       (isearch-lazy-highlight-new-loop range-beg range-end))))
-
-(defun replace-dehighlight ()
-  (when replace-overlay
-    (delete-overlay replace-overlay))
-  (when query-replace-lazy-highlight
-    (lazy-highlight-cleanup lazy-highlight-cleanup)
-    (setq isearch-lazy-highlight-last-string nil))
-  ;; Close overlays opened by `isearch-range-invisible' in `perform-replace'.
-  (isearch-clean-overlays))
-
 ;;; replace.el ends here


reply via email to

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