[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit e568677fe4 056/301: Add new functionality: restrict
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit e568677fe4 056/301: Add new functionality: restrict iedit-mode in region |
Date: |
Mon, 10 Jan 2022 22:58:50 -0500 (EST) |
branch: elpa/iedit
commit e568677fe46fcee90a1792016e9ef0c031537e4a
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>
Add new functionality: restrict iedit-mode in region
Fix iedit-toggle-case-sensitive with history problem
---
iedit.el | 99 ++++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 75 insertions(+), 24 deletions(-)
diff --git a/iedit.el b/iedit.el
index cc08438d5b..11e984f1bf 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2012-02-19 00:36:34 Victor Ren>
+;; Time-stamp: <2012-02-20 02:14:47 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region replace simultaneous
;; Version: 0.94
@@ -40,10 +40,12 @@
;;
;; - Finish - by pressing C-; again
-;; If you would like to operate on certain region, use "narrowing" first.
+;; If you would like to operate on certain region, just mark the region and
+;; press "C-;" again when iedit mode is active. Or use "narrowing" first when
+;; iedit mode is not active.
;; With several lines of additional code, the package also provides rectangle
-;; support with visible rectangle highlighting, which is simular with
`cua-rect'.
+;; support with visible rectangle highlighting, which is similar with
`cua-rect'.
;;; Suggested key bindings:
;;
@@ -51,12 +53,8 @@
;; (define-key isearch-mode-map (kbd "C-;") 'iedit-mode)
;;; todo:
-;; - profile to find bottleneck for huge file
;; - Add more easy access keys for whole occurrence
-;; - C-n,C-p is slow when unmatched lines are hided.
-;; - toggle blank line between matched lines?
;; - ert unit test
-;; - update documents for rectangle support
;;; Contributors
;; Adam Lindberg <eproxus@gmail.com> added a case sensitivity option that can
be toggled.
@@ -172,7 +170,7 @@ occurrence is not applied to other occurrences when it is
true.")
(car iedit-rectangle) is the top-left corner and
(cadr iedit-rectangle) is the bottom-right corner" )
-(defvar iedit-current-keymap)
+(defvar iedit-current-keymap nil)
(defvar iedit-occurrence-context-lines 0
"The number of lines before or after the occurrence.")
@@ -293,7 +291,7 @@ This is like `describe-bindings', but displays only Iedit
keys."
(defun iedit-help-for-occurrences ()
"Display `iedit-occurrence-local-map' or `iedit-rect-local-map'."
(interactive)
- (message (concat "M-u/l:up/downcase M-r:replace M-C:clear M-D:delete
M-n:number C-return:buffering"
+ (message (concat "M-u/l:up/downcase M-r:replace M-C:clear M-D:delete
M-N:number C-return:buffering"
(if iedit-rectangle
" M-k:kill"))))
@@ -304,7 +302,9 @@ This is like `describe-bindings', but displays only Iedit
keys."
;;;###autoload
(defun iedit-mode (&optional arg)
"Toggle iedit mode.
-If iedit mode is off, turn iedit mode on, off otherwise.
+If iedit mode is off, turn iedit mode on. If iedit mode is on and
+region is active, iedit mode is restricted in the
+region. Otherwise turn iedit mode off.
In Transient Mark mode, when iedit mode is turned on, all the
occurrences of the current region are highlighted. If one
@@ -336,7 +336,23 @@ Commands:
\\{iedit-current-keymap}"
(interactive "P")
(if iedit-mode
- (iedit-done)
+ (if (and transient-mark-mode mark-active (not (equal (mark) (point))))
+ ;; Restrict iedit-mode in this region todo: rethink the
implementation
+ (let* ((beg (region-beginning))
+ (end (region-end)))
+ (if (null (iedit-find-overlay-in-region beg end
'iedit-occurrence-overlay-name))
+ (iedit-done)
+ (when iedit-buffering
+ (iedit-stop-buffering))
+ (setq iedit-last-occurrence-in-history
(iedit-current-occurrence-string))
+ (if (null iedit-last-occurrence-in-history)
+ (iedit-done)
+ (deactivate-mark)
+ (remove-overlays (point-min) (point-max)
iedit-occurrence-overlay-name t)
+ (iedit-show-all)
+ (iedit-refresh iedit-last-occurrence-in-history beg end)
+ (iedit-first-occurrence))))
+ (iedit-done))
(let (occurrence complete-symbol rect-string)
(cond ((and arg
(or (not transient-mark-mode) (not mark-active)
@@ -375,12 +391,12 @@ Commands:
(setq iedit-aborting nil)
(setq iedit-rectangle nil)
(setq iedit-current-keymap iedit-occurrence-local-map)
- (iedit-refresh occurrence-exp)
+ (iedit-refresh occurrence-exp (point-min) (point-max))
(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)
+(defun iedit-refresh (occurrence-exp beg end)
"Refresh iedit-mode."
(setq iedit-occurrences-overlays nil)
(when iedit-occurrence-is-complete-symbol
@@ -389,8 +405,8 @@ Commands:
(let ((counter 0)
(case-fold-search (not iedit-case-sensitive)))
(save-excursion
- (goto-char (point-min))
- (while (re-search-forward occurrence-exp nil t)
+ (goto-char beg)
+ (while (re-search-forward occurrence-exp end t)
(push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
iedit-occurrences-overlays)
(setq counter (1+ counter)))
@@ -545,7 +561,6 @@ beginning of the buffer."
(when in-occurrence
(setq pos (next-single-char-property-change pos
'iedit-occurrence-overlay-name)))
(setq pos (next-single-char-property-change pos
'iedit-occurrence-overlay-name))
-
(if (/= pos (point-max))
(setq iedit-forward-success t)
(if (and iedit-forward-success in-occurrence)
@@ -591,6 +606,27 @@ the buffer."
(when iedit-forward-success
(goto-char pos))))
+(defun iedit-first-occurrence ()
+ "Move to the first occurrence."
+ (interactive)
+ (let ((pos (if (get-char-property (point-min) 'iedit-occurrence-overlay-name)
+ (point-min)
+ (next-single-char-property-change
+ (point-min)
+ 'iedit-occurrence-overlay-name))))
+ (setq iedit-forward-success t)
+ (goto-char pos)
+ (message "Located the first occurrence.")))
+
+(defun iedit-last-occurrence ()
+ "Move to the last occurrence."
+ (interactive)
+ (setq pos (previous-single-char-property-change (point-max)
'iedit-occurrence-overlay-name))
+ (if (not (get-char-property (- (point-max) 1)
'iedit-occurrence-overlay-name))
+ (setq pos (previous-single-char-property-change pos
'iedit-occurrence-overlay-name)))
+ (setq iedit-forward-success t)
+ (message "Located the last occurrence."))
+
(defun iedit-toggle-unmatched-lines-visible (&optional arg)
"Toggle whether to display unmatched lines.
A prefix ARG specifies how many lines before and after the
@@ -693,15 +729,14 @@ value of `iedit-occurrence-context-lines' is used for
this time."
(defun iedit-toggle-case-sensitive ()
"Toggle case-sensitive matching occurrences."
(interactive)
+ (setq iedit-case-sensitive (not iedit-case-sensitive))
(if iedit-buffering
(iedit-stop-buffering))
(setq iedit-last-occurrence-in-history (iedit-current-occurrence-string))
- (remove-overlays (point-min) (point-max) iedit-occurrence-overlay-name t)
- (iedit-show-all)
- (setq iedit-occurrences-overlays nil)
- (setq iedit-case-sensitive (not iedit-case-sensitive))
- (if iedit-last-occurrence-in-history
- (iedit-refresh iedit-last-occurrence-in-history)))
+ (when iedit-last-occurrence-in-history
+ (remove-overlays (point-min) (point-max) iedit-occurrence-overlay-name t)
+ (iedit-show-all)
+ (iedit-refresh iedit-last-occurrence-in-history (point-min) (point-max))))
(defun iedit-toggle-buffering ()
"Toggle buffering.
@@ -821,15 +856,31 @@ This function is supposed to be called in overlay
local-map."
(setq overlays (cdr overlays)))))
found))
+;; This function might be called out of any occurrence
(defun iedit-current-occurrence-string ()
- "Return occurrence string."
- (let* ((ov (car iedit-occurrences-overlays))
+ "Return current occurrence string.
+Return nil if occurrence string is empty string."
+ (let* ((ov (or (iedit-find-current-occurrence-overlay)
+ (car iedit-occurrences-overlays)))
(beg (overlay-start ov))
(end (overlay-end ov)))
(if (and ov (/= beg end))
(regexp-quote (buffer-substring-no-properties beg end))
nil)))
+(defun iedit-find-overlay-in-region (beg end property)
+ "Return a overlay with property in region."
+ (let ((overlays (overlays-in beg end))
+ found)
+ (while (and overlays (not found))
+ (let ((overlay (car overlays)))
+ (if (and (overlay-get overlay property)
+ (>= (overlay-start overlay) beg)
+ (<= (overlay-end overlay) end))
+ (setq found overlay)
+ (setq overlays (cdr overlays)))))
+ found))
+
(defun iedit-printable (string)
"Return a omitted substring that is not longer than 50.
STRING is already `regexp-quote'ed"
- [nongnu] elpa/iedit 0edc86ff41 024/301: Fix the last occurrence problem when it is a complete symbol., (continued)
- [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
- [nongnu] elpa/iedit e568677fe4 056/301: Add new functionality: restrict iedit-mode in region,
ELPA Syncer <=
- [nongnu] elpa/iedit a9bda4db66 060/301: Refine hotkeys, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 4fa7342be9 065/301: Copy from iedit.el, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b579dd0739 063/301: Update with new information, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit a13c4d6b56 067/301: Remove README, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 90ef2d5ac9 064/301: Add digit prefix argment 0 to enable restricting match in a function, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 697e24c337 073/301: remove a todo item: add ert test case, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 428be4e13e 078/301: Fix iedit-kill-rectangle problem, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f348f2d8fb 004/301: updates, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit da0a24701b 005/301: Add option to match only complete words, not inside words, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 1b3672d28a 069/301: Init, ELPA Syncer, 2022/01/10