[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/substitute be5b7f3e71 11/39: Streamline all commands wi
From: |
ELPA Syncer |
Subject: |
[elpa] externals/substitute be5b7f3e71 11/39: Streamline all commands with a macro |
Date: |
Mon, 16 Jan 2023 11:58:48 -0500 (EST) |
branch: externals/substitute
commit be5b7f3e7193206e080b860d1a25cb72af04d9e8
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Streamline all commands with a macro
---
README.md | 2 +-
substitute.el | 63 ++++++++++++++++++++++++++++-------------------------------
2 files changed, 31 insertions(+), 34 deletions(-)
diff --git a/README.md b/README.md
index 0af9cfae6a..f3e0b08c64 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ Sample configuration:
(define-key map (kbd "M-# s") #'substitute-target-below-point)
(define-key map (kbd "M-# r") #'substitute-target-above-point)
(define-key map (kbd "M-# d") #'substitute-target-in-function)
- (define-key map (kbd "M-# M-#") #'substitute-target))
+ (define-key map (kbd "M-# b") #'substitute-target-in-buffer))
```
+ Package name (GNU ELPA): `substitute` (not available yet)
diff --git a/substitute.el b/substitute.el
index 8fecdafc35..93c2df63f0 100644
--- a/substitute.el
+++ b/substitute.el
@@ -185,49 +185,46 @@ Report a `user-error' if no target is found."
(t (or (format "\\_<%s\\_>" (thing-at-point 'symbol t))
(user-error "No substitution target at point")))))
-;;;###autoload
-(defun substitute-target (target sub &optional narrow)
- "Replace TARGET with SUB throughout the buffer.
+(defmacro substitute-command (fn doc scope)
+ "Produce substitute command using FN, DOC, and SCOPE."
+ `(defun ,fn (target sub)
+ ,(format
+ "Replace TARGET with SUB %s.
-When called interactively, TARGET is the target at point and
-SUB is a string that is provided at the minibuffer
-prompt.
+When called interactively, TARGET is the symbol at point and SUB
+is a string that is provided at the minibuffer prompt.
If the region is active, TARGET is the text within the region's
-boundaries.
+boundaries." doc)
+ (interactive
+ (let ((target (substitute--target)))
+ (list target
+ (substitute--prompt target current-prefix-arg))))
+ (substitute--operate target sub ,scope)))
-With optional NARROW as a prefix argument, limit the substitution
-to the current function by using `narrow-to-defun'."
- (interactive
- (let ((target (substitute--target)))
- (list target
- (substitute--prompt target current-prefix-arg)
- current-prefix-arg)))
- (substitute--operate target sub (when narrow 'defun)))
+;;;###autoload
+(substitute-command
+ substitute-target-in-buffer
+ "throughout the buffer"
+ nil)
;;;###autoload
-(defun substitute-target-in-function ()
- "Replace target at point in the scope of the currenct function.
-This is the same as calling `narrow-to-defun' before
-`substitute-target' OR invoking the latter command with its
-NARROW prefix argument."
- (interactive)
- (let ((target (substitute--target)))
- (substitute--operate target (substitute--prompt target 'defun) 'defun)))
+(substitute-command
+ substitute-target-in-function
+ "in the defun (per `narrow-to-defun')"
+ 'defun)
;;;###autoload
-(defun substitute-target-below-point ()
- "Replace target from point to the end of the buffer."
- (interactive)
- (let ((target (substitute--target)))
- (substitute--operate target (substitute--prompt target 'below) 'below)))
+(substitute-command
+ substitute-target-below-point
+ "to the end of the buffer"
+ 'below)
;;;###autoload
-(defun substitute-target-above-point ()
- "Replace target from point to the end of the buffer."
- (interactive)
- (let ((target (substitute--target)))
- (substitute--operate target (substitute--prompt target 'above) 'above)))
+(substitute-command
+ substitute-target-above-point
+ "to the beginning of the buffer"
+ 'above)
(defun substitute-report-operation (target sub count scope)
"Print message of substitution.
- [elpa] externals/substitute fd60c0da63 08/39: Mention substitute-report-operation in hook doc string, (continued)
- [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
- [elpa] externals/substitute be5b7f3e71 11/39: Streamline all commands with a macro,
ELPA Syncer <=
- [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, 2023/01/16
- [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