From c5ebd3ee6c2c14727d926aef5d8e36682a00bb59 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sat, 29 Aug 2020 18:33:05 +0200 Subject: [PATCH] Fix isearch yank on last occurrence of search string * lisp/isearch.el (isearch-yank-internal): (isearch-yank-prev-point): Fix yanking when we are at the last occurrence of a search string. (Bug#22118) --- lisp/isearch.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/isearch.el b/lisp/isearch.el index 81e83d7950..ac8b48e43a 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -2518,6 +2518,8 @@ isearch-xterm-paste (let ((pasted-text (nth 1 event))) (isearch-yank-string pasted-text)))) +(defvar isearch-yank-prev-point nil) + (defun isearch-yank-internal (jumpform) "Pull the text from point to the point reached by JUMPFORM. JUMPFORM is a lambda expression that takes no arguments and returns @@ -2528,7 +2530,14 @@ isearch-yank-internal (save-excursion (and (not isearch-forward) isearch-other-end (goto-char isearch-other-end)) - (buffer-substring-no-properties (point) (funcall jumpform))))) + (and (not isearch-success) isearch-yank-prev-point + (goto-char isearch-yank-prev-point)) + (buffer-substring-no-properties + (point) + (prog1 + (setq isearch-yank-prev-point (funcall jumpform)) + (when isearch-success + (setq isearch-yank-prev-point nil))))))) (defun isearch-yank-char-in-minibuffer (&optional arg) "Pull next character from buffer into end of search string in minibuffer." -- 2.28.0