[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/meow ec94fa609b: Add `meow-replace-pop`. (#509)
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/meow ec94fa609b: Add `meow-replace-pop`. (#509) |
Date: |
Mon, 25 Sep 2023 13:01:06 -0400 (EDT) |
branch: elpa/meow
commit ec94fa609bcbf7a3ad29bb09a9bf39943cc254e9
Author: okamsn <28612288+okamsn@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
Add `meow-replace-pop`. (#509)
This command, when run after a replacement command, such as `meow-replace`
or
itself, replaces the just inserted text with the next item in the kill ring,
without rotating the kill ring.
- Add command `meow-replace`.
- Add variables `meow--replace-pop-index`, `meow--replace-start-marker`,
and `meow-replace-pop-command-start-indexes`.
- Modify commands `meow-replace`, `meow-replace-save`, and
`meow-replace-char`
to set the marker before inserting the replacement text.
Co-authored-by: okamsn <okamsn@users.noreply.github.com>
---
meow-command.el | 35 +++++++++++++++++++++++++++++++++++
meow-var.el | 22 ++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/meow-command.el b/meow-command.el
index 0f3b0b0269..9f59960acb 100644
--- a/meow-command.el
+++ b/meow-command.el
@@ -541,6 +541,7 @@ This command supports `meow-selection-command-fallback'."
(when (meow--allow-modify-p)
(when-let ((s (string-trim-right (current-kill 0 t) "\n")))
(delete-region (region-beginning) (region-end))
+ (set-marker meow--replace-start-marker (point))
(insert s))))))
(defun meow-replace-char ()
@@ -550,6 +551,7 @@ This command supports `meow-selection-command-fallback'."
(when (< (point) (point-max))
(when-let ((s (string-trim-right (current-kill 0 t) "\n")))
(delete-region (point) (1+ (point)))
+ (set-marker meow--replace-start-marker (point))
(insert s)))))
(defun meow-replace-save ()
@@ -565,10 +567,43 @@ This command supports `meow-selection-command-fallback'."
(buffer-substring-no-properties (region-beginning)
(region-end)))))
(progn
(delete-region (region-beginning) (region-end))
+ (set-marker meow--replace-start-marker (point))
(insert s)
(kill-new old)))
+ (set-marker meow--replace-start-marker (point))
(insert s)))))))
+(defun meow-replace-pop ()
+ "Like `yank-pop', but for `meow-replace'.
+
+If this command is called after `meow-replace',
+`meow-replace-char', `meow-replace-save', or itself, replace the
+previous replacement with the next item in the `kill-ring'.
+
+Unlike `yank-pop', this command does not rotate the `kill-ring'.
+For that, see the command `rotate-yank-pointer'.
+
+For custom commands, see also the user option
+`meow-replace-pop-command-start-indexes'."
+ (interactive "*")
+ (unless kill-ring (user-error "Can't replace; kill ring is empty"))
+ (let ((select-enable-clipboard meow-use-clipboard))
+ (when (meow--allow-modify-p)
+ (setq meow--replace-pop-index
+ (cond
+ ((eq last-command 'meow-replace-pop) (1+ meow--replace-pop-index))
+ ((alist-get last-command meow-replace-pop-command-start-indexes))
+ (t (user-error "Can only run `meow-replace-pop' after itself or a
command in `meow-replace-pop-command-start-indexes'"))))
+ (when (>= meow--replace-pop-index (length kill-ring))
+ (setq meow--replace-pop-index 0)
+ (message "`meow-replace-pop': Reached end of kill ring"))
+ (let ((txt (string-trim-right (current-kill meow--replace-pop-index t)
+ "\n")))
+ (delete-region meow--replace-start-marker (point))
+ (set-marker meow--replace-start-marker (point))
+ (insert txt))))
+ (setq this-command 'meow-replace-pop))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; CHAR MOVEMENT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/meow-var.el b/meow-var.el
index f6b364de14..1fc5cfe08b 100644
--- a/meow-var.el
+++ b/meow-var.el
@@ -644,6 +644,28 @@ The value can be nil, quick or record.")
(meow-backspace . "backspace"))
"A list of (command . short-name)")
+(defcustom meow-replace-pop-command-start-indexes
+ '((meow-replace . 1)
+ (meow-replace-char . 1)
+ (meow-replace-save . 2))
+ "Alist of commands and their starting indices for use by `meow-replace-pop'.
+
+If `meow-replace-pop' is run and the previous command is not
+`meow-replace-pop' or a command which is present in this alist,
+`meow-replace-pop' signals an error."
+ :type '(alist :key-type function :value-type natnum))
+
+(defvar meow--replace-pop-index nil
+ "The index of the previous replacement in the `kill-ring'.
+See also the command `meow-replace-pop'.")
+
+(defvar meow--replace-start-marker (make-marker)
+ "The beginning of the replaced text.
+
+This marker stays before any text inserted at the location, to
+account for any automatic formatting that happens after inserting
+the replacement text.")
+
;;; Backup variables
(defvar meow--backup-var-delete-activae-region nil
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/meow ec94fa609b: Add `meow-replace-pop`. (#509),
ELPA Syncer <=