From: Juri Linkov Date: Wed, 19 May 2021 16:30:33 +0000 (+0300) Subject: * lisp/simple.el (yank-from-kill-ring-rotate): New defcustom (bug#48478). X-Git-Tag: emacs-28.0.90~2391 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1f0f922ef279e29bc91642f4e8ff2b552064d07f;p=emacs.git * lisp/simple.el (yank-from-kill-ring-rotate): New defcustom (bug#48478). (read-from-kill-ring, yank-from-kill-ring): Use it. --- diff --git a/etc/NEWS b/etc/NEWS index 8bbb972493a..32d7c4fe18b 100644 --- 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'. diff --git a/lisp/simple.el b/lisp/simple.el index 2d9b7dddab6..8697eed9e3b 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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)))))) + ;; Some kill commands.