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

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

[nongnu] elpa/iedit 8559638b9b 076/301: Fix C-u C-u iedit-last-inital-st


From: ELPA Syncer
Subject: [nongnu] elpa/iedit 8559638b9b 076/301: Fix C-u C-u iedit-last-inital-string-global problem
Date: Mon, 10 Jan 2022 22:58:52 -0500 (EST)

branch: elpa/iedit
commit 8559638b9be1f01d5a334397ddf1e844c2a51426
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>

    Fix C-u C-u iedit-last-inital-string-global problem
---
 iedit-tests.el | 99 ++++++++++++++++++++++++++++++++++++++++++----------------
 iedit.el       | 47 ++++++++++++++--------------
 2 files changed, 95 insertions(+), 51 deletions(-)

diff --git a/iedit-tests.el b/iedit-tests.el
index 2333b6bd64..187cb8dd0e 100755
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-03-03 14:43:39 Victor Ren>
+;; Time-stamp: <2012-03-03 17:27:58 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Version: 0.94
 ;; X-URL: http://www.emacswiki.org/emacs/Iedit
@@ -71,9 +71,31 @@
      (forward-line 2)
      (iedit-mode)
      (should (= 2 (length iedit-occurrences-overlays)))
+     (should (string= iedit-initial-string-local "foo"))
      (iedit-mode)
      (should (null iedit-occurrences-overlays)))))
 
+(ert-deftest iedit-mode-with-region-test ()
+  (with-iedit-test-fixture
+"foobar
+ foo
+ foo
+ bar
+foo"
+   (lambda ()
+     (iedit-mode)
+     (goto-char 1)
+     (set-mark-command nil)
+     (forward-char 3)
+     (iedit-mode)
+     (should (= 4 (length iedit-occurrences-overlays)))
+     (should (string= iedit-initial-string-local "foo"))
+     (should (null iedit-only-complete-symbol-local))
+     (goto-char 1)
+     (set-mark-command nil)
+     (forward-line 3)
+     (iedit-mode 4)
+     (should (= 1 (length iedit-occurrences-overlays))))))
 (ert-deftest iedit-mode-start-from-isearch-test ()
   (with-iedit-test-fixture
 "foo
@@ -95,6 +117,52 @@
      (iedit-mode)
      (should (null iedit-occurrences-overlays)))))
 
+(ert-deftest iedit-mode-last-local-occurrence-test ()
+  (with-iedit-test-fixture
+"foo
+  foo
+   barfoo
+   foo"
+   (lambda ()
+     (should (= 3 (length iedit-occurrences-overlays)))
+     (should (string= iedit-initial-string-local "foo"))
+     (iedit-mode)
+     (goto-char 15)
+     (iedit-mode 4) ; last local
+     (should (string= iedit-initial-string-local "foo"))
+     (should (= 3 (length iedit-occurrences-overlays))))))
+
+(ert-deftest iedit-mode-last-global-occurrence-test ()
+  (with-iedit-test-fixture
+"foo
+  foo
+   barfoo
+   foo"
+   (lambda ()
+     (should (= 3 (length iedit-occurrences-overlays)))
+     (should (string= iedit-initial-string-local "foo"))
+     (iedit-mode)
+     (with-temp-buffer
+       (insert "bar foo foo")
+       (goto-char 1)
+       (iedit-mode 16)
+     (should (string= iedit-initial-string-local "foo"))
+     (should (= 2 (length iedit-occurrences-overlays)))))))
+
+(ert-deftest iedit-execute-last-modification-test ()
+  (with-iedit-test-fixture
+"foo
+  foo
+   barfoo
+   foo"
+   (lambda ()
+     (should (= 3 (length iedit-occurrences-overlays)))
+     (should (string= iedit-initial-string-local "foo"))
+     (iedit-mode)
+     (with-temp-buffer
+       (insert "bar foo foo")
+       (should-error (iedit-execute-last-modification))))))
+
 (ert-deftest iedit-movement-test ()
   (with-iedit-test-fixture
 "foo
@@ -135,28 +203,6 @@
      (should (string= (current-message) "Located the last occurrence."))
      )))
 
-(ert-deftest iedit-mode-with-region-test ()
-  (with-iedit-test-fixture
-"foobar
- foo
- foo
- bar
-foo"
-   (lambda ()
-     (iedit-mode)
-     (goto-char 1)
-     (set-mark-command nil)
-     (forward-char 3)
-     (iedit-mode)
-     (should (= 4 (length iedit-occurrences-overlays)))
-     (should (string= iedit-initial-string-local "foo"))
-     (should (null iedit-only-complete-symbol-local))
-     (goto-char 1)
-     (set-mark-command nil)
-     (forward-line 3)
-     (iedit-mode 4)
-     (should (= 1 (length iedit-occurrences-overlays))))))
-
 (ert-deftest iedit-occurrence-update-test ()
   (with-iedit-test-fixture
 "foo
@@ -330,11 +376,11 @@ arfoo
       (emacs-lisp-mode)
       (goto-char 5)
       (iedit-mode)
-      (iedit-restrict-defun)
+      (iedit-restrict-function)
       (should (= 1 (length iedit-occurrences-overlays)))
       (iedit-mode)
       (goto-char 13)
-      (iedit-mode 0)
+      (iedit-mode-function)
       (should (= 4 (length iedit-occurrences-overlays)))
       (iedit-mode)
       (iedit-mode)
@@ -356,7 +402,7 @@ arfoo
       (transient-mark-mode -1)
       (goto-char 5)
       (iedit-mode)
-      (iedit-restrict-defun)
+      (iedit-restrict-function)
       (should (= 1 (length iedit-occurrences-overlays)))
       (iedit-mode)
       (goto-char 13)
@@ -368,7 +414,6 @@ arfoo
       (iedit-mode)
       (should (= 0 (length iedit-occurrences-overlays))))))
 
-
 (defvar iedit-printable-test-lists
   '(("" "")
     ("abc" "abc")
diff --git a/iedit.el b/iedit.el
index 00efa5499d..17d1a8528d 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2012-03-02 15:49:40 Victor Ren>
+;; Time-stamp: <2012-03-03 17:27:33 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region replace simultaneous
 ;; Version: 0.95
@@ -67,7 +67,7 @@
 ;; (define-key global-map (kbd "C-;") 'iedit-mode)
 ;; (define-key isearch-mode-map (kbd "C-;") 'iedit-mode)
 ;; (define-key esc-map (kbd "C-;") 'iedit-execute-last-modification)
-;; (define-key help-map (kbd "C-;") 'iedit-mode-defun)
+;; (define-key help-map (kbd "C-;") 'iedit-mode-function)
 ;; (define-key global-map [C-return] 'iedit-rectangle-mode)
 
 ;;; todo:
@@ -144,7 +144,7 @@ For example, when invoking `iedit-mode' on the \"in\" in the
 (define-key global-map (kbd "C-;") 'iedit-mode)
 (define-key isearch-mode-map (kbd "C-;") 'iedit-mode)
 (define-key esc-map (kbd "C-;") 'iedit-execute-last-modification)
-(define-key help-map (kbd "C-;") 'iedit-mode-defun)
+(define-key help-map (kbd "C-;") 'iedit-mode-function)
 (define-key global-map [C-return] 'iedit-rectangle-mode)
 
 (defvar iedit-last-initial-string-global nil
@@ -332,7 +332,7 @@ This is like `describe-bindings', but displays only Iedit 
keys."
     (define-key map (kbd "M-B") 'iedit-toggle-buffering)
     (define-key map (kbd "M-<") 'iedit-first-occurrence)
     (define-key map (kbd "M->") 'iedit-last-occurrence)
-    (define-key map (kbd "M-H") 'iedit-restrict-defun)
+    (define-key map (kbd "M-H") 'iedit-restrict-function)
     (define-key map (kbd "C-?") 'iedit-help-for-occurrences)
     map)
   "Keymap used within overlays in iedit mode.")
@@ -358,7 +358,7 @@ This is like `describe-bindings', but displays only Iedit 
keys."
                    (substitute-command-keys "\\[iedit-toggle-buffering]") 
":buffering "
                    (substitute-command-keys "\\[iedit-first-occurrence]") "/"
                    (substitute-command-keys "\\[iedit-last-occurrence]") 
":first/last "
-                   (substitute-command-keys "\\[iedit-restrict-defun]") 
":restrict "
+                   (substitute-command-keys "\\[iedit-restrict-function]") 
":restrict "
                    (if iedit-rectangle
                        (concat
                         (substitute-command-keys "\\[iedit-kill-rectangle]") 
":kill")))))
@@ -464,8 +464,8 @@ Commands:
       (iedit-start occurrence beg end))))
 
 ;;;###autoload
-(defun iedit-mode-defun ()
-  "Toggle `iedit-mode' on currenct defun."
+(defun iedit-mode-function ()
+  "Toggle `iedit-mode' on currenct function."
   (interactive)
   (iedit-mode 0))
 
@@ -501,7 +501,6 @@ Commands:
   (setq iedit-current-keymap iedit-occurrence-keymap)
   (iedit-refresh occurrence-exp beg end)
   (run-hooks 'iedit-mode-hook)
-  ;; (add-hook 'mouse-leave-buffer-hook 'iedit-done)
   (add-hook 'kbd-macro-termination-hook 'iedit-done))
 
 (defun iedit-refresh (occurrence-exp beg end)
@@ -527,8 +526,8 @@ Commands:
             (iedit-hide-unmatched-lines iedit-occurrence-context-lines)))
       (message "%d matches for \"%s\"" counter (iedit-printable 
occurrence-exp))
       (setq iedit-mode (propertize (concat " Iedit:" (number-to-string 
counter))
-                                   'face 'font-lock-warning-face))))
-  (force-mode-line-update))
+                                   'face 'font-lock-warning-face))
+      (force-mode-line-update))))
 
 (defun iedit-rectangle-start (beg end)
   "Start an iedit for the region as a rectangle."
@@ -563,16 +562,17 @@ Commands:
   (add-hook 'kbd-macro-termination-hook 'iedit-done))
 
 (defun iedit-done ()
-  "Exit iedit mode."
+  "Exit iedit mode.
+Save the current occurrence string locally and globally.  Save
+the initial string globally."
   (if iedit-buffering
       (iedit-stop-buffering))
   (when (null iedit-rectangle)
     (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
-    (when (not (string= iedit-initial-string-local 
iedit-last-occurrence-local))
-      (setq iedit-last-occurrence-global iedit-last-occurrence-local)
-      (setq iedit-only-complete-symbol-global iedit-only-complete-symbol-local)
-      (setq iedit-last-initial-string-global iedit-initial-string-local)
-      (setq iedit-case-sensitive-global iedit-case-sensitive-local)))
+    (setq iedit-last-occurrence-global iedit-last-occurrence-local)
+    (setq iedit-only-complete-symbol-global iedit-only-complete-symbol-local)
+    (setq iedit-last-initial-string-global iedit-initial-string-local)
+    (setq iedit-case-sensitive-global iedit-case-sensitive-local))
   (remove-overlays nil nil iedit-occurrence-overlay-name t)
   (iedit-show-all)
   (setq iedit-occurrences-overlays nil)
@@ -587,7 +587,8 @@ Commands:
 (defun iedit-execute-last-modification (&optional arg)
   "Apply last modification in iedit mode to the current buffer or an active 
region."
   (interactive "*P")
-  (or iedit-last-initial-string-global
+  (or (and iedit-last-initial-string-global
+           (not (string= iedit-last-initial-string-global 
iedit-last-occurrence-global)))
       (error "No modification available"))
   (let ((occurrence-exp (regexp-quote iedit-last-initial-string-global))
         (replacement  iedit-last-occurrence-global)
@@ -598,12 +599,9 @@ Commands:
       (setq replacement (downcase replacement)))
     (if iedit-only-complete-symbol-global
         (setq occurrence-exp (concat "\\_<"  occurrence-exp "\\_>")))
-    (if (iedit-region-active)
-        (progn
+    (when (iedit-region-active)
           (setq beg (region-beginning))
           (setq end (region-end)))
-      (setq beg (point-min))
-      (setq end (point-max)))
     (perform-replace occurrence-exp replacement t t nil nil nil beg end)))
 
 (defun iedit-make-occurrence-overlay (begin end)
@@ -849,7 +847,8 @@ value of `iedit-occurrence-context-lines' is used for this 
time."
   "Apply last global modification."
   (interactive "*")
   (if (and iedit-last-initial-string-global
-           (string= iedit-initial-string-local 
iedit-last-initial-string-global))
+           (string= iedit-initial-string-local 
iedit-last-initial-string-global)
+           (not (string= iedit-last-initial-string-global 
iedit-last-occurrence-global)))
       (iedit-replace-occurrences iedit-last-occurrence-global)
     (message "No global modification available.")))
 
@@ -997,8 +996,8 @@ The behavior is the same as `kill-rectangle' in rect mode."
                     (cadr iedit-rectangle)
                     fill)))
 
-(defun iedit-restrict-defun(&optional arg)
-  "Restricting iedit mode in current defun."
+(defun iedit-restrict-function(&optional arg)
+  "Restricting iedit mode in current function."
   (interactive "P")
   (save-excursion
     (mark-defun)



reply via email to

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