[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit 768d89b60c 022/301: Merge remote-tracking branch 'le
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit 768d89b60c 022/301: Merge remote-tracking branch 'lewang/master' |
Date: |
Mon, 10 Jan 2022 22:58:46 -0500 (EST) |
branch: elpa/iedit
commit 768d89b60c15f5279ff04963342b0c791a3417ff
Merge: 7ed8e04557 ec765ee0c4
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>
Merge remote-tracking branch 'lewang/master'
Conflicts:
iedit.el
---
iedit.el | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 93 insertions(+), 16 deletions(-)
diff --git a/iedit.el b/iedit.el
index 7b6b3650f4..b52bf23201 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2012-01-21 14:12:53 Victor Ren>
+;; Time-stamp: <2012-01-24 21:40:20 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region replace simultaneous
;; Version: 0.91
@@ -270,34 +270,54 @@ You can also switch to iedit mode from isearch mode
directly. The
current search string is used as occurrence. All occurrences of
the current search string are highlighted.
-With a prefix argument, the occurrence when iedit is turned off
-last time is used as occurrence. This is intended to recover
-last iedit which is turned off by mistake.
+With a universal prefix argument and no active region, the
+occurrence when iedit is turned off last time is used as
+occurrence. This is intended to recover last iedit which is
+turned off by mistake.
+
+With a universal prefix argument and region active, interactively
+edit region as a string rectangle.
Commands:
\\{iedit-mode-map}"
- (interactive "P")
+ (interactive "*P")
(if iedit-mode
(iedit-done)
- (let ((occurrence nil))
- (cond ((and arg iedit-last-occurrence-in-history)
- (setq occurrence iedit-last-occurrence-in-history))
+ (let (occurrence rect-string)
+ (cond ((and arg
+ (or transient-mark-mode mark-active (not (equal (mark)
(point))))
+ iedit-last-occurrence-in-history)
+ (setq occurrence iedit-last-occurrence-in-history))
+ ;; todo: the simple information is missing
+ ((and arg
+ transient-mark-mode mark-active (not (equal
(mark) (point))))
+ (setq rect-string t))
((and transient-mark-mode mark-active (not (equal (mark) (point))))
- (setq occurrence (buffer-substring-no-properties (mark) (point))))
+ (setq occurrence (regexp-quote (buffer-substring-no-properties
+ (mark) (point)))))
((and isearch-mode (not (string= isearch-string "")))
- (setq occurrence (buffer-substring-no-properties (point)
isearch-other-end))
+ (setq occurrence (funcall (if isearch-regexp
+ 'eval
+ 'regexp-quote)
+ (buffer-substring-no-properties
+ (point) isearch-other-end)))
(isearch-exit))
((and iedit-current-symbol-default (current-word t))
- (setq occurrence (current-word))
+ (setq occurrence (regexp-quote (current-word)))
(when iedit-only-at-symbol-boundaries
(setq occurrence (concat "\\_<" (regexp-quote occurrence)
"\\_>"))))
(t (error "No candidate of the occurrence, cannot enable iedit
mode.")))
- (deactivate-mark)
- (iedit-start occurrence))))
+ (if rect-string
+ (let ((beg (region-beginning))
+ (end (region-end)))
+ (deactivate-mark)
+ (iedit-rectangle beg end))
+ (deactivate-mark)
+ (iedit-start occurrence)))))
(defun iedit-start (occurrence-exp)
"Start an iedit for the occurrence-exp in the current buffer."
- (setq iedit-mode " Iedit")
+ (setq iedit-mode (propertize " Iedit" 'face 'font-lock-warning-face))
(setq iedit-occurrences-overlays nil)
(setq iedit-unmatched-lines-invisible
iedit-unmatched-lines-invisible-default)
(setq iedit-case-sensitive iedit-case-sensitive-default)
@@ -323,6 +343,33 @@ Commands:
(concat (substring occurrence-exp 0 50) "...")
occurrence-exp)))))
+(defun iedit-rectangle (beg end)
+ "Start an iedit for the region as a rectangle"
+ (setq iedit-mode (propertize " Iedit-RECT" 'face 'font-lock-warning-face))
+ (setq iedit-occurrences-overlays nil)
+ (force-mode-line-update)
+ (run-hooks 'iedit-mode-hook)
+ ;; (add-hook 'mouse-leave-buffer-hook 'iedit-done)
+ (add-hook 'kbd-macro-termination-hook 'iedit-done)
+
+ (let ((orig-p (point-marker))
+ (beg-col (progn (goto-char beg) (current-column)))
+ (end-col (progn (goto-char end) (current-column))))
+ (when (< end-col beg-col)
+ (rotatef beg-col end-col))
+ (goto-char beg)
+ (loop do (progn
+ (push (iedit-make-occurrence-overlay (progn
+ (move-to-column beg-col
t)
+ (point))
+ (progn
+ (move-to-column end-col
t)
+ (point)))
+ iedit-occurrences-overlays)
+ (forward-line 1))
+ until (> (point) end))
+ (goto-char orig-p)))
+
(defun iedit-hide-unmatched-lines ()
"Hide unmatched lines using invisible overlay."
(let ((prev-occurrence-end 0)
@@ -377,6 +424,15 @@ occurrences if the user starts typing."
(overlay-put unmatched-lines-overlay 'intangible t)
unmatched-lines-overlay))
+;; `iedit-occurrence-update' gets called twice when change==0 and occurrence
+;; is zero-width
+;; -- for front and back insertion.
+(defvar iedit-last-overlay nil
+ "records processed overlay so they don't get processed multiple times. See
code.")
+(defun iedit-post-command-func ()
+ (remove-hook 'post-command-hook 'iedit-post-command-func t)
+ (setq iedit-last-overlay nil))
+
(defun iedit-occurrence-update (occurrence after beg end &optional change)
"Update all occurrences.
This modification hook is triggered when a user edits any
@@ -389,17 +445,21 @@ exit iedit mode."
(if (null after)
(if (or (< beg (overlay-start occurrence))
(> end (overlay-end occurrence)))
- (iedit-done) ;;
+ (let ((inhibit-modification-hooks t))
+ (iedit-done)) ;; todo: it is a problem to remove the overlays
(progn (setq iedit-before-modification-beg beg)
(setq iedit-before-modification-end end)
(unless (eq beg end)
(setq iedit-before-modification-string
(buffer-substring-no-properties beg end)))))
- ;; after modification
+ ;; after modification ;; todo more ellaborate on these conditions
(when (or (eq 0 change) ;; insertion
(eq beg end) ;; deletion
+ (not (eq occurrence iedit-last-overlay))
(not (string= iedit-before-modification-string
(buffer-substring-no-properties beg end))))
+ (setq iedit-last-overlay occurrence)
+ (add-hook 'post-command-hook 'iedit-post-command-func nil t)
(let ((inhibit-modification-hooks t)
(offset (- beg (overlay-start occurrence)))
(value (buffer-substring beg end)))
@@ -463,6 +523,23 @@ exit iedit mode."
;; (goto-char (point-min))
;; (while (re-search-forward iedit-before-modification-string
(overlay-start occurrence) t)
;; (replace-match value nil nil)))))))
+;; occurrence and is responsible for updating all other
+;; occurrences."
+;; (when (and after
+;; (not undo-in-progress) ; undo will do all the work
+;; (not (< beg (overlay-start occurrence)))
+;; (not (eq occurrence iedit-last-overlay)))
+;; (setq iedit-last-overlay occurrence)
+;; (add-hook 'post-command-hook 'iedit-post-command-func nil t)
+;; (let ((replacement-str (buffer-substring-no-properties beg end))
+;; (index (- beg (overlay-start occurrence)))
+;; (inhibit-modification-hooks t))
+;; (save-excursion
+;; (dolist (like-occurrence iedit-occurrences-overlays)
+;; (when (not (eq like-occurrence occurrence))
+;; (goto-char (+ index (overlay-start like-occurrence)))
+;; (delete-region (point) (+ (point) change))
+;; (insert replacement-str)))))))
(defun iedit-next-occurrence ()
"Move forward to the next occurrence in the `iedit'.
- [nongnu] elpa/iedit 69d6c03e06 009/301: Fix syntax error, (continued)
- [nongnu] elpa/iedit 69d6c03e06 009/301: Fix syntax error, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 9a891d7abf 002/301: updates, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit ec6785b0d2 008/301: host on git, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f808bf1ce9 012/301: Merge from lewang/master and update comments, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 02946e07b6 013/301: Update contributors and spell check, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit af6d0ef70b 007/301: host on github, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 17e8fca7e6 011/301: Merge from tsdh/master, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6d96992291 015/301: Remove duplicated comments, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 011e8d354c 016/301: Performance optimization of iedit-occurrence-update, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c8dac6bee8 020/301: exit iedit mode when change is not inside of occurrence., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 768d89b60c 022/301: Merge remote-tracking branch 'lewang/master',
ELPA Syncer <=
- [nongnu] elpa/iedit 0edc86ff41 024/301: Fix the last occurrence problem when it is a complete symbol., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit dd7d2f95f8 027/301: fix org-mode text-property compatibility (use insert-and-inherit), ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d5d4027a33 030/301: fix `iedit-toggle-unmatched-lines-visible' for rectangles, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 652087d63c 036/301: fix warning: the function `make-sparse-key-map' is not known to be, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit da47784c8d 038/301: Add iedit mode easy access keys, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c53a885fe5 040/301: Add bufferring modification functionalities, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 9bc57d2a30 041/301: make iedit-skipped-modification-once buffer local, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit e99e65fccb 044/301: Fix current point move problem when call iedit-replace-occurrences., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 4e31d50327 052/301: Add a prefix arg handling to iedit-toggle-unmatched-lines-visible, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 87053a3d44 054/301: Remove two buffer local variables for rectangle., ELPA Syncer, 2022/01/10