[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult d6cac13fd0 1/3: consult-yank-(pop/replace) foll
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult d6cac13fd0 1/3: consult-yank-(pop/replace) follows yank-kill-from-rotate (#682) |
Date: |
Wed, 23 Nov 2022 13:57:25 -0500 (EST) |
branch: externals/consult
commit d6cac13fd0616ee0e39bd086de89aa5519a232de
Author: Mattias <5543639+mattiasdrp@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
consult-yank-(pop/replace) follows yank-kill-from-rotate (#682)
* consult-yank-(pop/replace) follows yank-kill-from-rotate
If `yank-from-kill-ring-rotate` is set to t, `consult-yank-(pop/replace)`
will put
the last yanked value at the top of the candidates by rotating the kill-ring
If the kill-ring is `'(1 2 3 4)` and 3 was the last yanked value,
kill-ring-yank-pointer is `'(3 4)`, by appending `(butlast '(1 2 3 4)
(length
'(3 4)))` to `'(3 4)` we have a new kill-ring that is `'(3 4 1 2)`
* Added consult-yank-from-kill-ring-rotate variable
`yank-from-kill-ring-rotate` was introduced in Emacs 28.1
* Guard the modification of kill-ring
behind consult-yank-from-kill-ring-rotate
* Minor cleanup
Co-authored-by: Daniel Mendler <mail@daniel-mendler.de>
---
consult.el | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/consult.el b/consult.el
index edb620c94a..8b037a2790 100644
--- a/consult.el
+++ b/consult.el
@@ -67,6 +67,10 @@
;;;; Customization
+(defcustom consult-yank-rotate (bound-and-true-p yank-from-kill-ring-rotate)
+ "Rotate the kill ring."
+ :type 'boolean)
+
(defcustom consult-narrow-key nil
"Prefix key for narrowing during completion.
@@ -3541,7 +3545,11 @@ If no MODES are specified, use currently active major
and minor modes."
(consult--lookup-member
(consult--read
(consult--remove-dups
- (or kill-ring (user-error "Kill ring is empty")))
+ (or (if consult-yank-rotate
+ (append kill-ring-yank-pointer
+ (butlast kill-ring (length kill-ring-yank-pointer)))
+ kill-ring)
+ (user-error "Kill ring is empty")))
:prompt "Yank from kill-ring: "
:history t ;; disable history
:sort nil
@@ -3569,6 +3577,10 @@ version supports preview of the selected string."
(push-mark)
(insert-for-yank string)
(setq this-command 'yank)
+ (when consult-yank-rotate
+ (if-let (pos (seq-position kill-ring string))
+ (setq kill-ring-yank-pointer (nthcdr pos kill-ring))
+ (kill-new string)))
(when (consp arg)
;; Swap point and mark like in `yank'.
(goto-char (prog1 (mark t)