[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/substitute 87fc9cb145 05/39: Abstract positioning and f
From: |
ELPA Syncer |
Subject: |
[elpa] externals/substitute 87fc9cb145 05/39: Abstract positioning and fix issues with targeting |
Date: |
Mon, 16 Jan 2023 11:58:45 -0500 (EST) |
branch: externals/substitute
commit 87fc9cb145ba2a6a1bd08942d5df0fef3a7a4bc8
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Abstract positioning and fix issues with targeting
The previous positioning was problematic as it would miss the current
target depending on where the point was.
---
substitute.el | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/substitute.el b/substitute.el
index ae64f26b86..ae93ff12ec 100644
--- a/substitute.el
+++ b/substitute.el
@@ -123,6 +123,32 @@ Pass to it the TARGET and SCOPE arguments."
target
scope))
+(defun substitute--current-and-below-motion (target)
+ "Position point to match current TARGET and all below."
+ (lambda ()
+ (widen)
+ (cond
+ ((looking-at target)
+ (goto-char (match-beginning 0)))
+ ((save-excursion (looking-back target (beginning-of-line)))
+ (goto-char (match-beginning 0))))))
+
+(defun substitute--current-and-above-motion (target)
+ "Position point to match current TARGET and all above."
+ (lambda ()
+ (widen)
+ (cond
+ ((looking-at target)
+ (goto-char (match-end 0)))
+ ((save-excursion (looking-back target (beginning-of-line)))
+ (goto-char (match-end 0))))))
+
+(defun substitute--current-defun ()
+ "Position point to the after after `narrow-to-defun'."
+ (lambda ()
+ (narrow-to-defun)
+ (goto-char (point-min))))
+
(defun substitute--operate (target sub &optional scope)
"Substitute TARGET with SUB in SCOPE.
This is the subroutine of `substitute-target' and related."
@@ -132,10 +158,10 @@ This is the subroutine of `substitute-target' and
related."
(let ((search 're-search-forward)
(narrow (lambda () (widen) (goto-char (point-min)))))
(pcase scope
- ('below (setq narrow (lambda () (forward-sexp -1) (widen))))
+ ('below (setq narrow (substitute--current-and-below-motion
target)))
('above (setq search 're-search-backward
- narrow (lambda () (forward-sexp 1) (widen))))
- ('defun (setq narrow (lambda () (narrow-to-defun) (goto-char
(point-min))))))
+ narrow (substitute--current-and-above-motion
target)))
+ ('defun (setq narrow (substitute--current-defun))))
(funcall narrow)
(while (funcall search target nil t)
(push (match-string-no-properties 0) count)
- [elpa] branch externals/substitute created (now 731cb688e2), ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 2eedda90bf 02/39: Add COPYING and gitignore, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 511a45bbbc 01/39: Add initial version of substitute.el (WORK-IN-PROGRESS), ELPA Syncer, 2023/01/16
- [elpa] externals/substitute e5a012fd15 03/39: Reference correct symbol in doc string, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 8b1d32af46 04/39: Use pretty target in substitute-report-operation, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 87fc9cb145 05/39: Abstract positioning and fix issues with targeting,
ELPA Syncer <=
- [elpa] externals/substitute fd60c0da63 08/39: Mention substitute-report-operation in hook doc string, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute b73b62df77 10/39: Add initial version of the README, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute fd991c2e8c 07/39: Tweak one doc string format, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute ff63ce986f 06/39: Use more descriptive name for local variable, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute deb7d28b9e 09/39: Change substitute-highlight default value and fix typo, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 3c91a4a100 12/39: Define aliases for two commands, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 11b4277bfe 13/39: Remove obsolete symbol from doc strings, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute cdb23ab35c 17/39: Reference blog post in the README, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute e90152fc90 18/39: Bump version for package-vc-rebuild to do its job, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute e55a121666 25/39: Make minor formatting change, ELPA Syncer, 2023/01/16