[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iedit fd801e77df 165/301: Merge pull request #38 from mgal
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iedit fd801e77df 165/301: Merge pull request #38 from mgalgs/narrow-around-current-line |
Date: |
Mon, 10 Jan 2022 22:58:59 -0500 (EST) |
branch: elpa/iedit
commit fd801e77dfdcfa0bdeadc153a9fb637dab2b4bb4
Merge: 1242c675d2 d2f08e8862
Author: victorhge <victorhge@gmail.com>
Commit: victorhge <victorhge@gmail.com>
Merge pull request #38 from mgalgs/narrow-around-current-line
Provide functions to narrow around current-line
A good start point to a more mature functionality
---
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 6c155ceba0..abd3ba624e 100644
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -850,6 +850,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 46d5f65019 154/301: clean up old occurrences when calling from isearch, (continued)
- [nongnu] elpa/iedit 46d5f65019 154/301: clean up old occurrences when calling from isearch, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c55fcd5bac 189/301: avoid error if iedit-toggle-key-default already bound to iedit-mode, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit adb0d2e92d 179/301: Expand to next occurence ("incremental select"), ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d25b655768 207/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d31bafa97c 171/301: Refactored for easier to show different messages, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 2d9017daea 181/301: Merge pull request #51 from jasminpatry/fix/restrict-current-line-resets-expand, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 048d8417cf 202/301: *** empty log message ***, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit a8ab03848d 158/301: complete iedit-toggle-selection, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit c0d108da3b 166/301: make the occurrence the latest kill in the kill ring, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit d89ee51834 148/301: Merge branch 'redo-prs' of github.com:lewang/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit fd801e77df 165/301: Merge pull request #38 from mgalgs/narrow-around-current-line,
ELPA Syncer <=
- [nongnu] elpa/iedit 52c4865e5b 197/301: Add special prefix argument 1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 8d20094a11 182/301: Use the original case in the iedit-replace default value, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 1242c675d2 164/301: Add save-window-excursion, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit b5a3415b00 180/301: Merge pull request #47 from zhenya1007/help-char-can-be-meta, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 6019d3c376 170/301: defvar iedit-current-symbol, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 22f4729ae9 150/301: Add test case for iedit-hide-unmatched-lines, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 4884f61a3b 188/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 607e82c7b0 208/301: rename `iedit-current-symbol` to `iedit-default-occurrence`, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit 1eabaa061a 210/301: Merge branch 'master' of github.com:victorhge/iedit, ELPA Syncer, 2022/01/10
- [nongnu] elpa/iedit a6d8568379 161/301: Merge pull request #35 from lewang/ensure-skip-mofication-once, ELPA Syncer, 2022/01/10