[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit 345431294a 294/301: Unify prefix augument handling
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit 345431294a 294/301: Unify prefix augument handling |
Date: |
Mon, 10 Jan 2022 22:59:11 -0500 (EST) |
branch: elpa/iedit
commit 345431294a9d346e34eec08acff41c8abae369ab
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor Ren <victorhge@gmail.com>
Unify prefix augument handling
`iedit-mode-from-isearch' can be called with the same prefix argument as
`iedit-mode'.
---
iedit-lib.el | 3 +-
iedit-tests.el | 45 +++++++++++++++++------------
iedit.el | 91 ++++++++++++++++++++++++++++++++--------------------------
3 files changed, 79 insertions(+), 60 deletions(-)
diff --git a/iedit-lib.el b/iedit-lib.el
index 0818eab9ed..cca5b952e8 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2010 - 2019, 2020, 2021 Victor Ren
-;; Time-stamp: <2021-08-12 15:17:29 Victor Ren>
+;; Time-stamp: <2021-12-23 18:18:46 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous rectangle refactoring
;; Version: 0.9.9.9
@@ -413,6 +413,7 @@ Return the start position of the new occurrence if
successful."
))
pos))
+;; todo: this function is not used yet.
(defun iedit-add-region-as-occurrence (beg end)
"Add region as an occurrence.
The length of the region must the same as other occurrences if
diff --git a/iedit-tests.el b/iedit-tests.el
index f6888650da..d3fc19834b 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010 - 2019, 2020 Victor Ren
-;; Time-stamp: <2021-08-12 13:50:27 Victor Ren>
+;; Time-stamp: <2021-12-23 18:19:15 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Version: 0.9.9.9
;; X-URL: https://github.com/victorhge/iedit
@@ -213,24 +213,33 @@ fob")))))
(ert-deftest iedit-mode-start-from-isearch-test ()
(with-iedit-test-fixture
-"foo
- foo
- barfoo
- foo"
+"a
+(defun foo (foo bar foo)
+\"foo bar foobar\" nil)
+ (defun bar (bar foo bar)
+ \"bar foo barfoo\" nil)
+foo
+ foo"
(lambda ()
- (should (= 3 (length iedit-occurrences-overlays)))
- (should (string= iedit-initial-string-local "foo"))
- (iedit-mode)
- (forward-line 2)
- (isearch-mode t)
- (isearch-process-search-char ?f)
- (isearch-process-search-char ?o)
- (isearch-process-search-char ?o)
- (call-interactively 'iedit-mode-from-isearch)
- (should (string= iedit-initial-string-local "foo"))
- (should (= 4 (length iedit-occurrences-overlays)))
- (iedit-mode)
- (should (null iedit-occurrences-overlays)))))
+ (iedit-mode)
+ (emacs-lisp-mode)
+ (goto-char 5)
+ (iedit-mode)
+ (isearch-mode t)
+ (isearch-process-search-char ?f)
+ (isearch-process-search-char ?o)
+ (isearch-process-search-char ?o)
+ (iedit-mode-from-isearch 0)
+ (should (string= iedit-initial-string-local "foo"))
+ (should (= 5 (length iedit-occurrences-overlays)))
+ (iedit-mode)
+ (isearch-mode t)
+ (isearch-process-search-char ?f)
+ (isearch-process-search-char ?o)
+ (isearch-process-search-char ?o)
+ (iedit-mode-from-isearch)
+ (should (= 10 (length iedit-occurrences-overlays)))
+ )))
(ert-deftest iedit-mode-start-from-isearch-regexp-test ()
(with-iedit-test-fixture
diff --git a/iedit.el b/iedit.el
index 4d4777a17f..6ac2b3713a 100755
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2010 - 2019, 2020, 2021 Victor Ren
-;; Time-stamp: <2021-08-05 15:18:16 Victor Ren>
+;; Time-stamp: <2021-12-23 18:27:46 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.9.9.9
@@ -118,7 +118,7 @@ isearch-mode-map, esc-map and help-map."
(defvar iedit-mode nil) ;; Name of the minor mode
(defcustom iedit-auto-narrow nil
- "If no-nil, the buffer is narrowed temporairily if iedit-mode
+ "If no-nil, the buffer is narrowed temporarily if iedit-mode
is enabled on current defun."
:type 'boolean
:group 'iedit)
@@ -392,11 +392,7 @@ Keymap used within overlays:
(if iedit-mode
(iedit-mode-on-action arg)
(iedit-barf-if-lib-active)
- (let (occurrence
- (beg (if (eq major-mode 'occur-edit-mode) ; skip the first occurrence
- (next-single-char-property-change 1 'read-only)
- (point-min)))
- (end (point-max)))
+ (let (occurrence beg end)
;; Get the occurrence and iedit-occurrence-type-local
(cond ((and arg
(= 4 (prefix-numeric-value arg))
@@ -415,26 +411,7 @@ Keymap used within overlays:
(unless occurrence
(error "No candidate of the occurrence, cannot enable Iedit
mode"))))
;; Get the scope
- (when arg
- (cond ((= 0 (prefix-numeric-value arg))
- (save-excursion
- ;; Since Emacs 26.1, `mark-defun' marks the next defun if the
- ;; mark is active.
- (deactivate-mark t)
- (mark-defun)
- (setq beg (region-beginning))
- (setq end (region-end)))
- (when (and iedit-auto-narrow (not (buffer-narrowed-p)))
- (narrow-to-region beg end)
- (setq iedit-is-narrowed t)))
- ((and (= 1 (prefix-numeric-value arg))
- (not (iedit-region-active)))
- (let ((region (bounds-of-thing-at-point 'symbol)))
- (setq beg (car region))
- (setq end (cdr region))))
- ((iedit-region-active)
- (setq beg (region-beginning))
- (setq end (region-end)))))
+ (cl-multiple-value-setq (beg end) (iedit--get-scope arg))
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(setq iedit-initial-string-local occurrence)
@@ -445,31 +422,34 @@ Keymap used within overlays:
(unless (boundp 'isearch-regexp-function)
(defvaralias 'isearch-regexp-function 'isearch-word))
-(defun iedit-mode-from-isearch (regexp)
+
+(defun iedit-mode-from-isearch (&optional arg)
"Start Iedit mode using last search string as the regexp."
- (interactive
- (let ((regexp (cond
- ((functionp isearch-regexp-function)
+ (interactive "P")
+ (or isearch-success
+ (error "No match" ))
+ (let ((regexp (cond
+ ((functionp isearch-regexp-function)
(funcall isearch-regexp-function isearch-string))
(isearch-regexp-function (word-search-regexp isearch-string))
(isearch-regexp isearch-string)
- (t (regexp-quote isearch-string)))))
- (list regexp)))
- (or isearch-success
- (error "No match" ))
- (if (or isearch-regexp isearch-regexp-function)
- nil
- (setq iedit-initial-string-local isearch-string))
- (let ((iedit-case-sensitive (not isearch-case-fold-search))
- result)
+ (t (regexp-quote isearch-string))))
+ (iedit-case-sensitive (not isearch-case-fold-search))
+ result
+ beg
+ end)
+ (if (or isearch-regexp isearch-regexp-function)
+ nil
+ (setq iedit-initial-string-local isearch-string))
(isearch-exit)
+ (cl-multiple-value-setq (beg end) (iedit--get-scope arg))
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(when iedit-mode
(iedit-lib-cleanup))
(setq result
(catch 'not-same-length
- (iedit-start regexp (point-min) (point-max))))
+ (iedit-start regexp beg end)))
(cond ((not iedit-occurrences-overlays)
(message "No matches found for %s" regexp)
(iedit-done))
@@ -477,6 +457,35 @@ Keymap used within overlays:
(message "Matches are not the same length.")
(iedit-done)))))
+(defun iedit--get-scope (arg)
+ "Return a region according to the prefix argument."
+ (let ((beg (if (eq major-mode 'occur-edit-mode) ; skip the first occurrence
+ (next-single-char-property-change 1 'read-only)
+ (point-min)))
+ (end (point-max)))
+ (when arg
+ (cond
+ ((= 0 (prefix-numeric-value arg))
+ (save-excursion
+ ;; Since Emacs 26.1, `mark-defun' marks the next defun if the
+ ;; mark is active.
+ (deactivate-mark t)
+ (mark-defun)
+ (setq beg (region-beginning))
+ (setq end (region-end)))
+ (when (and iedit-auto-narrow (not (buffer-narrowed-p)))
+ (narrow-to-region beg end)
+ (setq iedit-is-narrowed t)))
+ ((and (= 1 (prefix-numeric-value arg))
+ (not (iedit-region-active)))
+ (let ((region (bounds-of-thing-at-point 'symbol)))
+ (setq beg (car region))
+ (setq end (cdr region))))
+ ((iedit-region-active)
+ (setq beg (region-beginning))
+ (setq end (region-end)))))
+ (list beg end)))
+
(defun iedit-start (occurrence-regexp beg end)
"Start Iedit mode for the `occurrence-regexp' in the current buffer."
(setq iedit-initial-region (list beg end))
- [nongnu] elpa/iedit 06f1f50939 224/301: Merge pull request #65 from pstray/master, (continued)
- [nongnu] elpa/iedit 06f1f50939 224/301: Merge pull request #65 from pstray/master, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c11ecd9080 273/301: Update copyright notice, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit e5b51ac0af 278/301: Move hooks setup to iedit-lib to reduce code duplication, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c00a8ba805 272/301: Add a new feature - preserve case, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 4ef9bf6323 287/301: prefix-arg for `iedit-next-occurrence` and `iedit-prev-occurrence`, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 3d71392852 276/301: Fix as well issue #118, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit f7184f81d6 284/301: Clean up some lines of unnecessary code, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 2e1fd5b1b2 295/301: fix a byte compile issue, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 012de2e8d8 293/301: A few rephase in doc, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6bb8d63a97 297/301: Fix several typo errors, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 345431294a 294/301: Unify prefix augument handling,
ELPA Syncer <=
- [nongnu] elpa/iedit 61689f6ba4 057/301: Add arg handle for iedit-mode to exclude some occurrences., ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 7479d4c947 079/301: Merge branch 'topic/multi-interface', ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6cc86d58e6 086/301: Merge pull request #6 from gorakhargosh/master, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 4cf803d9cb 092/301: Skip the first occurrence for occur-edit-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c5ab2c593d 094/301: Avoid to restore Iedit mode when restoring desktop, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 95eb44ee30 117/301: Add new function iedit-add-next-occurrence-overlay, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b94c75e8c6 107/301: Move iedit-help-keymap to iedit.el, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 84896f8be0 104/301: *** empty log message ***, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 962fcdb6cd 124/301: Fix failed test cases, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6d16d92a5a 112/301: replace iedit-occurrence-face with real face, ELPA Syncer, 2022/01/10