[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'.
- [nongnu] elpa/iedit f707cce0b8 193/301: Remove the key binding to M-[, (continued)
- [nongnu] elpa/iedit f707cce0b8 193/301: Remove the key binding to M-[, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f9f87a0dd9 212/301: Add key bindings for iedit-quit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b4c7e41049 209/301: More doc for iedit-switch-to-mc-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 18b99c1fb4 169/301: Fix compile warning and test case, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit bd3fd44691 173/301: Added the default value for iedit-replace-occurrences, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b73b977839 204/301: Merge branch 'default-occurrence', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6e6d4bc478 151/301: Merge branch 'master' of https://github.com/mbneedham/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 06bdb68bbf 203/301: Add iedit-switch-to-mc-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b2bffd978c 184/301: Merge pull request #54 from Vifon/iedit-replace-occurences_default-case, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d2f08e8862 163/301: Provide functions to narrow around current-line, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 27dbbdda0b 162/301: Split iedit-occurrence-update into two functions,
ELPA Syncer <=
- [nongnu] elpa/iedit 9a40f6fa36 205/301: check if mc present, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 97ad9d0600 254/301: removed downcasing the from-string in iedit-lib.el/iedit-replace-occurrences to allow case sensitivity., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7a3725cd04 267/301: Small optimizations, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 42654ba7ed 266/301: iedit-rect.el: Don't set iedit-initial-string-local, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d335d6842a 183/301: Check if the default keybinding of iedit-mode is taken, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit e575cbf569 256/301: Allow adding a incremented number in each occurence, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 796ee5298d 237/301: fix the key conflict with yas-minor-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit e1decb37e5 245/301: Fix verion numbers, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f09b675c67 249/301: Add an option 'iedit-auto-narrow', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 44601e01fa 269/301: fix an issue with electric pair, ELPA Syncer, 2022/01/10