[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit d2f08e8862 163/301: Provide functions to narrow arou
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit d2f08e8862 163/301: Provide functions to narrow around current-line |
Date: |
Mon, 10 Jan 2022 22:58:59 -0500 (EST) |
branch: elpa/iedit
commit d2f08e88629ac4618a7acf068272ce9cf5e4bb38
Author: Mitchel Humpherys <mitch.special@gmail.com>
Commit: Mitchel Humpherys <mitch.special@gmail.com>
Provide functions to narrow around current-line
It's nice to be able to run Iedit on only the current line or lines
near the current line. Provide functions to narrow the Iedit search
region to the current line and to expand the search region near the
current line ad-hoc.
---
README.org | 8 +++++++
iedit-lib.el | 19 +++++++++++++++++
iedit.el | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+)
diff --git a/README.org b/README.org
index 47349a4013..eec2121bc1 100644
--- a/README.org
+++ b/README.org
@@ -35,6 +35,14 @@ Renaming refactoring is convinient in Iedit mode
- Last renaming refactoring is remembered and can be applied to other buffers
later
+ - Restricting the search area to just the current line can be done by
+ pressing M-I.
+
+ - Restricting the search area to the lines near the current line can
+ be done by pressing M-{ and M-}. These will expand the search
+ region one line at a time from the top and bottom. Add a prefix
+ argument to go the opposite direction.
+
Iedit-rectangle-mode provides rectangle support with *visible rectangle*
highlighting, which is similar with cua mode rectangle support. But it's
lighter weight and uses iedit mechanisms.
diff --git a/iedit-lib.el b/iedit-lib.el
index 0b3d5e5de5..9e6ef11289 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -848,6 +848,25 @@ STRING is already `regexp-quote'ed"
(concat (substring string 0 50) "...")
string))))
+(defun iedit-char-at-bol (&optional N)
+ "Get char position of the beginning of the current line. If `N'
+is given, move forward (or backward) that many lines (using
+`forward-line') and get the char position at the beginning of
+that line."
+ (save-excursion
+ (forward-line (if N N 0))
+ (point)))
+
+(defun iedit-char-at-eol (&optional N)
+ "Get char position of the end of the current line. If `N' is
+given, move forward (or backward) that many lines (using
+`forward-line') and get the char position at the end of that
+line."
+ (save-excursion
+ (forward-line (if N N 0))
+ (end-of-line)
+ (point)))
+
(defun iedit-region-active ()
"Return t if region is active and not empty.
If variable `iedit-transient-mark-sensitive' is t, active region
diff --git a/iedit.el b/iedit.el
index dc4acf50fc..81bdd63f1b 100644
--- a/iedit.el
+++ b/iedit.el
@@ -132,6 +132,13 @@ Iedit mode is turned off last time.")
"This is buffer local variable which is the initial region
where Iedit mode is started from.")
+(defvar iedit-num-lines-to-expand-up 0
+ "This is a global variable indicating how many lines up from
+point should be included in the replacement region.")
+
+(defvar iedit-num-lines-to-expand-down 0
+ "This is a global variable indicating how many lines down from
+point should be included in the replacement region.")
(make-variable-buffer-local 'iedit-mode)
(make-variable-buffer-local 'iedit-only-complete-symbol-local)
@@ -223,6 +230,9 @@ This is like `describe-bindings', but displays only Iedit
keys."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map iedit-occurrence-keymap-default)
(define-key map (kbd "M-H") 'iedit-restrict-function)
+ (define-key map (kbd "M-I") 'iedit-restrict-current-line)
+ (define-key map (kbd "M-{") 'iedit-expand-up-a-line)
+ (define-key map (kbd "M-}") 'iedit-expand-down-a-line)
(define-key map (kbd "M-G") 'iedit-apply-global-modification)
(define-key map (kbd "M-C") 'iedit-toggle-case-sensitive)
map)
@@ -414,6 +424,8 @@ the initial string globally."
(setq iedit-last-occurrence-local (iedit-current-occurrence-string))
(setq iedit-last-occurrence-global iedit-last-occurrence-local)
(setq iedit-last-initial-string-global iedit-initial-string-local)
+ (setq iedit-num-lines-to-expand-up 0)
+ (setq iedit-num-lines-to-expand-down 0)
(iedit-cleanup)
@@ -502,6 +514,64 @@ the initial string globally."
(message "Restricted in current function, %d matches."
(length iedit-occurrences-overlays)))
+(defun iedit-restrict-current-line ()
+ "Restrict Iedit mode to current line."
+ (interactive)
+ (iedit-restrict-region (iedit-char-at-bol) (iedit-char-at-eol))
+ (message "Restricted to current line, %d match%s."
+ (length iedit-occurrences-overlays)
+ (if (= 1 (length iedit-occurrences-overlays)) "" "es")))
+
+(defun iedit-expand-by-a-line (where amount)
+ "After restricting iedit to the current line with
+`iedit-restrict-current-line', this function expands the top or
+bottom of the search region upwards or downwards by `amount'
+lines. The region being acted upon is controlled with
+`where' ('top to act on the top, anything else for the
+bottom). With a prefix, collapses the top or bottom of the search
+region by `amount' lines."
+ (interactive "P")
+ ;; Since iedit-done resets iedit-num-lines-to-expand-{down,up}, we
+ ;; have to hang on to them in tmp variables
+ (let ((tmp-up iedit-num-lines-to-expand-up)
+ (tmp-down iedit-num-lines-to-expand-down)
+ ;; we want to call iedit-mode with a universal prefix arg
+ (current-prefix-arg '(4)))
+ (iedit-done)
+ (call-interactively 'iedit-mode)
+ (setq iedit-num-lines-to-expand-up tmp-up)
+ (setq iedit-num-lines-to-expand-down tmp-down)
+ (if (eq where 'top)
+ (setq iedit-num-lines-to-expand-up (max 0
+ (+ amount
iedit-num-lines-to-expand-up)))
+ (setq iedit-num-lines-to-expand-down (max 0
+ (+ amount
iedit-num-lines-to-expand-down))))
+ (iedit-restrict-region (iedit-char-at-bol (- iedit-num-lines-to-expand-up))
+ (iedit-char-at-eol iedit-num-lines-to-expand-down))
+ (message "Now looking -%d/+%d lines around current line, %d match%s."
+ iedit-num-lines-to-expand-up
+ iedit-num-lines-to-expand-down
+ (length iedit-occurrences-overlays)
+ (if (= 1 (length iedit-occurrences-overlays)) "" "es"))))
+
+(defun iedit-expand-up-a-line (&optional arg)
+ "After restricting iedit to the current line with
+`iedit-restrict-current-line', this function expands the search
+region upwards by one line. With a prefix, bring the top of the
+region back down one line."
+ (interactive "P")
+ (iedit-expand-by-a-line 'top
+ (if arg -1 1)))
+
+(defun iedit-expand-down-a-line (&optional arg)
+ "After restricting iedit to the current line with
+`iedit-restrict-current-line', this function expands the search
+region downwards by one line. With a prefix, bring the bottom of
+the region back up one line."
+ (interactive "P")
+ (iedit-expand-by-a-line 'bottom
+ (if arg -1 1)))
+
(defun iedit-restrict-region (beg end &optional inclusive)
"Restricting Iedit mode in a region."
(when iedit-buffering
- [nongnu] elpa/iedit 2fe78a5ec9 201/301: Remove two confusing options, (continued)
- [nongnu] elpa/iedit 2fe78a5ec9 201/301: Remove two confusing options, ELPA Syncer, 2022/01/10
- [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 <=
- [nongnu] elpa/iedit 27dbbdda0b 162/301: Split iedit-occurrence-update into two functions, ELPA Syncer, 2022/01/10
- [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