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

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

[nongnu] elpa/iedit e5b51ac0af 278/301: Move hooks setup to iedit-lib to


From: ELPA Syncer
Subject: [nongnu] elpa/iedit e5b51ac0af 278/301: Move hooks setup to iedit-lib to reduce code duplication
Date: Mon, 10 Jan 2022 22:59:10 -0500 (EST)

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

    Move hooks setup to iedit-lib to reduce code duplication
---
 README.org    |  1 +
 iedit-lib.el  | 21 ++++++++++++++-------
 iedit-rect.el | 14 ++++----------
 iedit.el      | 13 ++++---------
 4 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/README.org b/README.org
index 5a54abca9a..7b66083f53 100644
--- a/README.org
+++ b/README.org
@@ -14,6 +14,7 @@ other occurrences changed in the same way, with visual 
feedback as you type.
  - A more intuitive way to alter all the occurrences at once
  - Visual feedback
  - Less keystrokes in most cases
+ - Preserve case optionally
 
 Normal work flow of Iedit mode is like:
 
diff --git a/iedit-lib.el b/iedit-lib.el
index c2b41cae1e..7d8b45a208 100755
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
 
 ;; Copyright (C) 2010 - 2019, 2020 Victor Ren
 
-;; Time-stamp: <2020-11-23 15:50:37 Victor Ren>
+;; Time-stamp: <2021-01-04 14:07:43 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.9.9.9
@@ -160,7 +160,7 @@ insertion against a zero-width occurrence.")
 (defvar iedit-aborting nil
   "This is buffer local variable which indicates Iedit mode is aborting.")
 
-(defvar iedit-aborting-hook nil
+(defvar iedit-lib-aborting-hook nil
   "Functions to call before iedit-abort.  Normally it should be mode exit 
function.")
 
 (defvar iedit-post-undo-hook-installed nil
@@ -206,6 +206,7 @@ It replaces `inhibit-modification-hooks' which prevents 
calling
 (make-variable-buffer-local 'iedit-post-undo-hook-installed)
 (make-variable-buffer-local 'iedit-occurrence-context-lines)
 (make-variable-buffer-local 'iedit-occurrence-index)
+(make-variable-buffer-local 'iedit-lib-aborting-hook)
 
 (defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
 (defconst iedit-invisible-overlay-name 'iedit-invisible-overlay-name)
@@ -267,7 +268,7 @@ cursors."
                  (goto-char (+ (overlay-start occurrence) offset))
                  (unless (= master (point))
                        (mc/create-fake-cursor-at-point))))
-      (run-hooks 'iedit-aborting-hook)
+      (run-hooks 'iedit-lib-aborting-hook)
       (multiple-cursors-mode 1)))
   ;; `multiple-cursors-mode' runs `post-command-hook' function on all the
   ;; cursors for updating them .  `iedit-switch-to-mc-mode' is not supposed to
@@ -297,7 +298,7 @@ It should be set before occurrence overlay is created.")
 (defun iedit-quit ()
   "Quit the current mode."
   (interactive)
-  (run-hooks 'iedit-aborting-hook))
+  (run-hooks 'iedit-lib-aborting-hook))
 
 (defun iedit-make-markers-overlays (markers)
   "Create occurrence overlays on a list of markers."
@@ -408,6 +409,9 @@ there are."
 (defun iedit-lib-start ()
   "Initialize the hooks."
   (add-hook 'post-command-hook 'iedit-update-occurrences-2 nil t)
+  (add-hook 'before-revert-hook 'iedit-quit nil t)
+  (add-hook 'kbd-macro-termination-hook 'iedit-quit nil t)
+  (add-hook 'change-major-mode-hook 'iedit-quit nil t)
   (setq iedit-after-change-list nil))
 
 (defun iedit-lib-cleanup ()
@@ -415,6 +419,9 @@ there are."
   (remove-hook 'post-command-hook 'iedit-update-occurrences-2 t)
   (remove-overlays nil nil iedit-occurrence-overlay-name t)
   (iedit-show-all)
+  (remove-hook 'before-revert-hook 'iedit-quit t)
+  (remove-hook 'kbd-macro-termination-hook 'iedit-quit t)
+  (remove-hook 'change-major-mode-hook 'iedit-quit t)
   (setq iedit-occurrences-overlays nil)
   (setq iedit-read-only-occurrences-overlays nil)
   (setq iedit-aborting nil)
@@ -463,7 +470,7 @@ This is added to `post-command-hook' when undo command is 
executed
 in occurrences."
   (if (iedit-same-length)
       nil
-    (run-hooks 'iedit-aborting-hook))
+    (run-hooks 'iedit-lib-aborting-hook))
   (remove-hook 'post-command-hook 'iedit-post-undo t)
   (setq iedit-post-undo-hook-installed nil))
 
@@ -471,10 +478,10 @@ in occurrences."
   "Turning Iedit mode off and reset `iedit-aborting'.
 
 This is added to `post-command-hook' when aborting Iedit mode is
-decided.  `iedit-aborting-hook' is postponed after the current
+decided.  `iedit-lib-aborting-hook' is postponed after the current
 command is executed for avoiding `iedit-update-occurrences'
 is called for a removed overlay."
-  (run-hooks 'iedit-aborting-hook)
+  (run-hooks 'iedit-lib-aborting-hook)
   (remove-hook 'post-command-hook 'iedit-reset-aborting t)
   (setq iedit-aborting nil))
 
diff --git a/iedit-rect.el b/iedit-rect.el
index c5e81b0c35..28be7c71f8 100644
--- a/iedit-rect.el
+++ b/iedit-rect.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010 - 2019, 2020 Victor Ren
 
-;; Time-stamp: <2020-11-21 21:09:14 Victor Ren>
+;; Time-stamp: <2021-01-04 14:10:02 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.9.9.9
@@ -146,12 +146,9 @@ Commands:
                  (number-to-string (length iedit-occurrences-overlays)))
          'face
          'font-lock-warning-face))
+  (add-hook 'iedit-aborting-hook 'iedit-rectangle-done nil t)
   (iedit-lib-start)
-  (force-mode-line-update)
-  (add-hook 'before-revert-hook 'iedit-rectangle-done nil t)
-  (add-hook 'kbd-macro-termination-hook 'iedit-rectangle-done nil t)
-  (add-hook 'change-major-mode-hook 'iedit-rectangle-done nil t)
-  (add-hook 'iedit-aborting-hook 'iedit-rectangle-done nil t))
+  (force-mode-line-update))
 
 (defun iedit-rectangle-done ()
   "Exit Iedit mode.
@@ -162,10 +159,7 @@ the initial string globally."
   (iedit-lib-cleanup)
   (setq iedit-rectangle-mode nil)
   (force-mode-line-update)
-  (remove-hook 'before-revert-hook 'iedit-rectangle-done t)
-  (remove-hook 'kbd-macro-termination-hook 'iedit-rectangle-done t)
-  (remove-hook 'change-major-mode-hook 'iedit-rectangle-done t)
-  (remove-hook 'iedit-aborting-hook 'iedit-rectangle-done t))
+  (remove-hook 'iedit-lib-aborting-hook 'iedit-rectangle-done t))
 
 (defun iedit-kill-rectangle(&optional fill)
   "Kill the rectangle.
diff --git a/iedit.el b/iedit.el
index e5efccc2d7..fd1a410850 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010 - 2019, 2020 Victor Ren
 
-;; Time-stamp: <2020-11-23 15:18:05 Victor Ren>
+;; Time-stamp: <2021-01-04 13:52:50 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous refactoring
 ;; Version: 0.9.9.9
@@ -483,12 +483,10 @@ Keymap used within overlays:
     (setq iedit-mode t))
   (when iedit-auto-buffering
        (iedit-start-buffering))
+  (add-hook 'iedit-lib-aborting-hook 'iedit-done nil t)
   (iedit-lib-start)
   (run-hooks 'iedit-mode-hook)
-  (add-hook 'before-revert-hook 'iedit-done nil t)
-  (add-hook 'kbd-macro-termination-hook 'iedit-done nil t)
-  (add-hook 'change-major-mode-hook 'iedit-done nil t)
-  (add-hook 'iedit-aborting-hook 'iedit-done nil t))
+ )
 
 (defun iedit-default-occurrence()
   "This function returns a string as occurrence candidate.
@@ -592,10 +590,7 @@ the initial string globally."
   (setq iedit-initial-string-local nil)
   (setq iedit-mode nil)
   (force-mode-line-update)
-  (remove-hook 'before-revert-hook 'iedit-done t)
-  (remove-hook 'kbd-macro-termination-hook 'iedit-done t)
-  (remove-hook 'change-major-mode-hook 'iedit-done t)
-  (remove-hook 'iedit-aborting-hook 'iedit-done t)
+  (remove-hook 'iedit-lib-aborting-hook 'iedit-done t)
   (run-hooks 'iedit-mode-end-hook))
 
 (defun iedit-mode-on-action (&optional arg)



reply via email to

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