emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/iedit 3c305620ae 250/301: Optimize iedit-mode-from-isearch


From: ELPA Syncer
Subject: [nongnu] elpa/iedit 3c305620ae 250/301: Optimize iedit-mode-from-isearch
Date: Mon, 10 Jan 2022 22:59:07 -0500 (EST)

branch: elpa/iedit
commit 3c305620ae7638c0152e7ead74ca68f484052ae5
Author: victor <victorhge@gmail.com>
Commit: Victor <victorhge@gmail.com>

    Optimize iedit-mode-from-isearch
    
    Jump back if the length of the next occurrence is different.
    Remove an old TODO item :)
---
 iedit-lib.el   |  8 ++++++--
 iedit-tests.el | 30 +++++++++++++++++++++++++++++-
 iedit.el       | 12 +++++++-----
 3 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/iedit-lib.el b/iedit-lib.el
index 21a7b36df5..ea1f87b385 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2018-09-19 11:09:54 Victor Ren>
+;; Time-stamp: <2018-11-16 14:49:24 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.9.9.9
@@ -275,7 +275,8 @@ Return the number of occurrences."
   (setq iedit-read-only-occurrences-overlays nil)
   ;; Find and record each occurrence's markers and add the overlay to the 
occurrences
   (let ((counter 0)
-        (case-fold-search (not iedit-case-sensitive)))
+        (case-fold-search (not iedit-case-sensitive))
+       (length 0))
     (save-excursion
       (save-window-excursion
         (goto-char end)
@@ -285,6 +286,9 @@ Return the number of occurrences."
         (while (re-search-forward occurrence-regexp end t)
           (let ((beginning (match-beginning 0))
                 (ending (match-end 0)))
+           (if (and (> length 0) (/= (- ending beginning) length))
+               (throw 'not-same-length 'not-same-length)
+             (setq length (- ending beginning)))
             (if (text-property-not-all beginning ending 'read-only nil)
                 (push (iedit-make-read-only-occurrence-overlay beginning 
ending)
                       iedit-read-only-occurrences-overlays)
diff --git a/iedit-tests.el b/iedit-tests.el
index 6b90e20078..bfcd860e4d 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2018-11-14 17:48:26 Victor Ren>
+;; Time-stamp: <2018-11-16 14:55:04 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Version: 0.9.9.9
 ;; X-URL: https://www.emacswiki.org/emacs/Iedit
@@ -221,6 +221,34 @@ fob")))))
      (iedit-mode)
      (should (null iedit-occurrences-overlays)))))
 
+(ert-deftest iedit-mode-start-from-isearch-regexp-test ()
+  (with-iedit-test-fixture
+"foo
+  fobar
+  foobar
+  fooobar
+   barfoo
+   foo"
+   (lambda ()
+     (iedit-mode)
+     (call-interactively 'isearch-forward-regexp)
+     (isearch-process-search-char ?f)
+     (isearch-process-search-char ?o)
+     (isearch-process-search-char ?*)
+     (isearch-process-search-char ?b)
+     (call-interactively 'iedit-mode-from-isearch)
+     (should (null iedit-occurrences-overlays))
+     (should (string= (current-message) "Matches are not the same length."))
+     (goto-char (point-min))
+     (call-interactively 'isearch-forward-regexp)
+     (isearch-process-search-char ?f)
+     (isearch-process-search-char ?o)
+     (isearch-process-search-char ?.)
+     (isearch-process-search-char ?b)
+     (call-interactively 'iedit-mode-from-isearch)
+     (should (= 1 (length iedit-occurrences-overlays)))
+    )))
+
 (ert-deftest iedit-mode-last-local-occurrence-test ()
   (with-iedit-test-fixture
 "foo
diff --git a/iedit.el b/iedit.el
index 8612abfcc4..d9097e87c7 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2018-11-14 17:49:13 Victor Ren>
+;; Time-stamp: <2018-11-16 12:11:48 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous refactoring
 ;; Version: 0.9.9.9
@@ -441,18 +441,20 @@ Keymap used within overlays:
   (if (or isearch-regexp isearch-regexp-function)
       nil
     (setq iedit-initial-string-local isearch-string))
-  (let ((iedit-case-sensitive (not isearch-case-fold-search)))
+  (let ((iedit-case-sensitive (not isearch-case-fold-search))
+       result)
     (isearch-exit)
     (setq mark-active nil)
     (run-hooks 'deactivate-mark-hook)
     (when iedit-mode
       (iedit-cleanup))
-    (iedit-start regexp (point-min) (point-max))
-    ;; TODO: reconsider how to avoid the loop in iedit-same-length
+    (setq result
+         (catch 'not-same-length
+           (iedit-start regexp (point-min) (point-max))))
     (cond ((not iedit-occurrences-overlays)
            (message "No matches found for %s" regexp)
            (iedit-done))
-          ((not (iedit-same-length))
+          ((equal result 'not-same-length)
            (message "Matches are not the same length.")
            (iedit-done)))))
 



reply via email to

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