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

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

[nongnu] elpa/iedit 27dbbdda0b 162/301: Split iedit-occurrence-update in


From: ELPA Syncer
Subject: [nongnu] elpa/iedit 27dbbdda0b 162/301: Split iedit-occurrence-update into two functions
Date: Mon, 10 Jan 2022 22:58:59 -0500 (EST)

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

    Split iedit-occurrence-update into two functions
---
 iedit-lib.el | 102 +++++++++++++++++++++++++++++++----------------------------
 1 file changed, 54 insertions(+), 48 deletions(-)

diff --git a/iedit-lib.el b/iedit-lib.el
index d52731f4ee..0b3d5e5de5 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
 
 ;; Copyright (C) 2010, 2011, 2012 Victor Ren
 
-;; Time-stamp: <2013-02-08 22:09:19 Victor Ren>
+;; Time-stamp: <2013-02-11 22:27:12 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.97
@@ -109,9 +109,8 @@ that is going to be changed.")
 (defvar iedit-before-modification-undo-list nil
   "This is buffer local variable which is the buffer undo list before 
modification.")
 
-;; `iedit-occurrence-update' gets called twice when change==0 and occurrence
-;; is zero-width (beg==end)
-;; -- for front and back insertion.
+;; `iedit-occurrence-update-hook' gets called twice when change==0 and
+;; occurrence is zero-width (beg==end) -- for front and back insertion.
 (defvar iedit-skip-modification-once t
   "Variable used to skip first modification hook run when
 insertion against a zero-width occurrence.")
@@ -207,6 +206,8 @@ Return the number of occurrences."
   (let ((counter 0)
         (case-fold-search (not iedit-case-sensitive)))
     (save-excursion
+      (goto-char end)
+      (recenter)
       (goto-char beg)
       (while (re-search-forward occurrence-regexp end t)
         (let ((beginning (match-beginning 0))
@@ -290,9 +291,9 @@ occurrences if the user starts typing."
     (overlay-put occurrence iedit-occurrence-overlay-name t)
     (overlay-put occurrence 'face 'iedit-occurrence)
     (overlay-put occurrence 'keymap iedit-occurrence-keymap)
-    (overlay-put occurrence 'insert-in-front-hooks '(iedit-occurrence-update))
-    (overlay-put occurrence 'insert-behind-hooks '(iedit-occurrence-update))
-    (overlay-put occurrence 'modification-hooks '(iedit-occurrence-update))
+    (overlay-put occurrence 'insert-in-front-hooks 
'(iedit-occurrence-update-hook))
+    (overlay-put occurrence 'insert-behind-hooks 
'(iedit-occurrence-update-hook))
+    (overlay-put occurrence 'modification-hooks 
'(iedit-occurrence-update-hook))
     (overlay-put occurrence 'priority iedit-overlay-priority)
     occurrence))
 
@@ -327,19 +328,20 @@ in occurrences."
 
 This is added to `post-command-hook' when aborting Iedit mode is
 decided.  `iedit-aborting-hook' is postponed after the current
-command is executed for avoiding `iedit-occurrence-update' is
-called for a removed overlay."
+command is executed for avoiding `iedit-occurrence-update-hook'
+is called for a removed overlay."
   (run-hooks 'iedit-aborting-hook)
   (remove-hook 'post-command-hook 'iedit-reset-aborting t)
   (setq iedit-aborting nil))
 
-;; There are two ways to update all occurrence.  One is to redefine all key
+;; There are two ways to update all occurrences.  One is to redefine all key
 ;; stroke map for overlay, the other is to figure out three basic modification
 ;; in the modification hook.  This function chooses the latter.
-(defun iedit-occurrence-update (occurrence after beg end &optional change)
+(defun iedit-occurrence-update-hook (occurrence after beg end &optional change)
   "Update all occurrences.
 This modification hook is triggered when a user edits any
-occurrence and is responsible for updating all other occurrences.
+occurrence and is responsible for updating all other
+occurrences. Refer to `modification-hooks' for more details.
 Current supported edits are insertion, yank, deletion and
 replacement.  If this modification is going out of the
 occurrence, it will abort Iedit mode."
@@ -349,7 +351,7 @@ occurrence, it will abort Iedit mode."
       (when (not iedit-post-undo-hook-installed)
         (add-hook 'post-command-hook 'iedit-post-undo-hook nil t)
         (setq iedit-post-undo-hook-installed t))
-    (when (and (not iedit-aborting ))
+    (when (not iedit-aborting)
     ;; before modification
     (if (null after)
         (if (or (< beg (overlay-start occurrence))
@@ -373,41 +375,45 @@ occurrence, it will abort Iedit mode."
                     (eq beg end)  ;; deletion
                     (not (string= iedit-before-modification-string
                                   (buffer-substring-no-properties beg end))))
-            (let ((inhibit-modification-hooks t) ; todo: extract this as a 
function
-                  (offset (- beg (overlay-start occurrence)))
-                  (value (buffer-substring-no-properties beg end)))
-              (save-excursion
-                ;; insertion or yank
-                (if (eq 0 change)
-                    (dolist (another-occurrence iedit-occurrences-overlays)
-                      (let* ((beginning (+ (overlay-start another-occurrence) 
offset))
-                             (ending (+ beginning (- end beg))))
-                        (when (not (eq another-occurrence occurrence))
-                          (goto-char beginning)
-                          (insert-and-inherit value)
-                          ;; todo: reconsider this change Quick fix for
-                          ;; multi-occur occur-edit-mode: multi-occur depend on
-                          ;; after-change-functions to update original
-                          ;; buffer. Since inhibit-modification-hooks is set to
-                          ;; non-nil, after-change-functions hooks are not 
going
-                          ;; to be called for the changes of other occurrences.
-                          ;; So run the hook here.
-                          (run-hook-with-args 'after-change-functions
-                                              beginning
-                                              ending
-                                              change))
-                        (iedit-move-conjoined-overlays another-occurrence)))
-                  ;; deletion
-                  (dolist (another-occurrence (remove occurrence 
iedit-occurrences-overlays))
-                    (let ((beginning (+ (overlay-start another-occurrence) 
offset)))
-                      (delete-region beginning (+ beginning change))
-                      (unless (eq beg end) ;; replacement
-                        (goto-char beginning)
-                        (insert-and-inherit value))
-                      (run-hook-with-args 'after-change-functions
-                                          beginning
-                                          (+ beginning (- beg end))
-                                          change)))))))))))))
+            (iedit-update-occurrences  occurrence after beg end change))))))))
+
+(defun iedit-update-occurrences (occurrence after beg end &optional change)
+  ""
+  (let ((inhibit-modification-hooks t)
+        (offset (- beg (overlay-start occurrence)))
+        (value (buffer-substring-no-properties beg end)))
+    (save-excursion
+      ;; insertion or yank
+      (if (= 0 change)
+          (dolist (another-occurrence iedit-occurrences-overlays)
+            (let* ((beginning (+ (overlay-start another-occurrence) offset))
+                   (ending (+ beginning (- end beg))))
+              (when (not (eq another-occurrence occurrence))
+                (goto-char beginning)
+                (insert-and-inherit value)
+                ;; todo: reconsider this change Quick fix for
+                ;; multi-occur occur-edit-mode: multi-occur depend on
+                ;; after-change-functions to update original
+                ;; buffer. Since inhibit-modification-hooks is set to
+                ;; non-nil, after-change-functions hooks are not going
+                ;; to be called for the changes of other occurrences.
+                ;; So run the hook here.
+                (run-hook-with-args 'after-change-functions
+                                    beginning
+                                    ending
+                                    change))
+              (iedit-move-conjoined-overlays another-occurrence)))
+        ;; deletion
+        (dolist (another-occurrence (remove occurrence 
iedit-occurrences-overlays))
+          (let ((beginning (+ (overlay-start another-occurrence) offset)))
+            (delete-region beginning (+ beginning change))
+            (unless (eq beg end) ;; replacement
+              (goto-char beginning)
+              (insert-and-inherit value))
+            (run-hook-with-args 'after-change-functions
+                                beginning
+                                (+ beginning (- beg end))
+                                change)))))))
 
 (defun iedit-next-occurrence ()
   "Move forward to the next occurrence in the `iedit'.



reply via email to

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