[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/substitute 178453e3a4 22/39: Rename scope functions; ma
From: |
ELPA Syncer |
Subject: |
[elpa] externals/substitute 178453e3a4 22/39: Rename scope functions; make code cleaner |
Date: |
Mon, 16 Jan 2023 11:58:51 -0500 (EST) |
branch: externals/substitute
commit 178453e3a44016391cf6f41d55753fb24221a69f
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Rename scope functions; make code cleaner
---
substitute.el | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/substitute.el b/substitute.el
index 6105c1c63c..841a3d4b77 100644
--- a/substitute.el
+++ b/substitute.el
@@ -119,7 +119,7 @@ Pass to it the TARGET and SCOPE arguments."
target
scope))
-(defun substitute--current-and-below-motion (target)
+(defun substitute--scope-current-and-below (target)
"Position point to match current TARGET and all below."
(lambda ()
(widen)
@@ -129,7 +129,7 @@ Pass to it the TARGET and SCOPE arguments."
((save-excursion (looking-back target (beginning-of-line)))
(goto-char (match-beginning 0))))))
-(defun substitute--current-and-above-motion (target)
+(defun substitute--scope-current-and-above (target)
"Position point to match current TARGET and all above."
(lambda ()
(widen)
@@ -139,29 +139,41 @@ Pass to it the TARGET and SCOPE arguments."
((save-excursion (looking-back target (beginning-of-line)))
(goto-char (match-end 0))))))
-(defun substitute--current-defun ()
+(defun substitute--scope-current-defun ()
"Position point to the top after `narrow-to-defun'."
(lambda ()
(narrow-to-defun)
(goto-char (point-min))))
+(defun substitute--scope-top-of-buffer ()
+ "Position point to the top of the buffer."
+ (lambda ()
+ (widen)
+ (goto-char (point-min))))
+
+(defun substitute--setup-scope (target scope)
+ "Derive SCOPE for TARGET."
+ (let (scope-fn)
+ (pcase scope
+ ('below (setq scope-fn (substitute--scope-current-and-below target)))
+ ('above (setq scope-fn (substitute--scope-current-and-above target)))
+ ('defun (setq scope-fn (substitute--scope-current-defun)))
+ (_ (setq scope-fn (substitute--scope-top-of-buffer))))
+ (funcall scope-fn)))
+
(defun substitute--operate (target sub &optional scope)
"Substitute TARGET with SUB in SCOPE.
This is the subroutine of `substitute-target' and related."
(let (count)
(save-excursion
(save-restriction
- (let ((search-fn 're-search-forward)
- (scope-fn (lambda () (widen) (goto-char (point-min)))))
- (pcase scope
- ('below (setq scope-fn (substitute--current-and-below-motion
target)))
- ('above (setq search-fn 're-search-backward
- scope-fn (substitute--current-and-above-motion
target)))
- ('defun (setq scope-fn (substitute--current-defun))))
- (funcall scope-fn)
- (while (funcall search-fn target nil t)
- (push (match-string-no-properties 0) count)
- (replace-match sub nil t)))))
+ (substitute--setup-scope target scope)
+ (while (funcall (if (eq scope 'above)
+ 're-search-backward
+ 're-search-forward)
+ target nil t)
+ (push (match-string-no-properties 0) count)
+ (replace-match sub nil t))))
(run-hook-with-args 'substitute-post-replace-hook
target sub (length count)
(substitute--scope scope))))
- [elpa] externals/substitute ff63ce986f 06/39: Use more descriptive name for local variable, (continued)
- [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
- [elpa] externals/substitute be5b7f3e71 11/39: Streamline all commands with a macro, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute a1382f1860 19/39: Tweak substitute backronym, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 8431c6b54d 20/39: Make local variables less verbose, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 178453e3a4 22/39: Rename scope functions; make code cleaner,
ELPA Syncer <=
- [elpa] externals/substitute 0c3e1c79ca 26/39: Add indentation in one place, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute b8cd86b7b8 28/39: Add FIXME, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute f5b7b373b1 30/39: Make link to blog easier to find, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 591d6df15b 38/39: Expand README; add video demo, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute af56e87099 31/39: Refine how description of scope is made, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 86423acf44 37/39: Use correct word in a couple of places, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 731cb688e2 39/39: Bump version to trigger GNU ELPA build, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 3f2e429e2d 32/39: Refine substitute-command macro, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute b665f84d4b 14/39: Reuse code in substitute--prompt-with-highlight, ELPA Syncer, 2023/01/16
- [elpa] externals/substitute 89c3389e1c 15/39: Rename local variable for clarity, ELPA Syncer, 2023/01/16