]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/simple.el (yank-from-kill-ring-rotate): New defcustom (bug#48478).
authorJuri Linkov <juri@linkov.net>
Wed, 19 May 2021 16:30:33 +0000 (19:30 +0300)
committerJuri Linkov <juri@linkov.net>
Wed, 19 May 2021 16:30:33 +0000 (19:30 +0300)
(read-from-kill-ring, yank-from-kill-ring): Use it.

etc/NEWS
lisp/simple.el

index 8bbb972493aa851bb8da2e5826601e9f6f07cbfd..32d7c4fe18b35efd743eb251ad08522574627a68 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -340,7 +340,8 @@ When invoked like that, it prompts in the minibuffer for one of the
 previous kills, offering completion and minibuffer-history navigation
 through previous kills recorded in the kill ring.  A similar feature
 in Isearch can be invoked if you bind 'C-s M-y' to the command
-'isearch-yank-pop'.
+'isearch-yank-pop'.  When the user option 'yank-from-kill-ring-rotate'
+is nil the kill ring is not rotated after 'yank-from-kill-ring'.
 
 ---
 ** New user options 'copy-region-blink-delay' and 'delete-pair-blink-delay'.
index 2d9b7dddab666de345921a1d8dac6cdd35512cb9..8697eed9e3b99324dd15b05ad8b035ca8952fb5b 100644 (file)
@@ -5683,6 +5683,9 @@ PROMPT is a string to prompt with."
   ;; `current-kill' updates `kill-ring' with a possible interprogram-paste
   (current-kill 0)
   (let* ((history-add-new-input nil)
+         (history-pos (when yank-from-kill-ring-rotate
+                        (- (length kill-ring)
+                           (length kill-ring-yank-pointer))))
          (ellipsis (if (char-displayable-p ?…) "…" "..."))
          ;; Remove keymaps from text properties of copied string,
          ;; because typing RET in the minibuffer might call
@@ -5730,7 +5733,16 @@ PROMPT is a string to prompt with."
              '(metadata (display-sort-function . identity))
            (complete-with-action action completions string pred)))
        nil nil nil
-       'read-from-kill-ring-history))))
+       (if history-pos
+           (cons 'read-from-kill-ring-history history-pos)
+         'read-from-kill-ring-history)))))
+
+(defcustom yank-from-kill-ring-rotate t
+  "Whether using `yank-from-kill-ring' should rotate `kill-ring-yank-pointer'.
+If non-nil, the kill ring is rotated after selecting previously killed text."
+  :type 'boolean
+  :group 'killing
+  :version "28.1")
 
 (defun yank-from-kill-ring (string &optional arg)
   "Select a stretch of previously killed text and insert (\"paste\") it.
@@ -5755,12 +5767,19 @@ beginning of the inserted text and mark at the end, like `yank' does.
 When called from Lisp, insert STRING like `insert-for-yank' does."
   (interactive (list (read-from-kill-ring "Yank from kill-ring: ")
                      current-prefix-arg))
+  (setq yank-window-start (window-start))
   (push-mark)
   (insert-for-yank string)
+  (when yank-from-kill-ring-rotate
+    (let ((pos (seq-position kill-ring string)))
+      (setq kill-ring-yank-pointer
+            (or (and pos (nthcdr (1+ pos) kill-ring))
+                kill-ring))))
   (if (consp arg)
-      ;; Swap point and mark like in `yank'.
+      ;; Swap point and mark like in `yank' and `yank-pop'.
       (goto-char (prog1 (mark t)
                    (set-marker (mark-marker) (point) (current-buffer))))))
+
 \f
 ;; Some kill commands.