From: Lars Ingebrigtsen Date: Tue, 6 Jul 2021 17:25:41 +0000 (+0200) Subject: Make `M-x clipboard-yank' work reliably X-Git-Tag: emacs-28.0.90~1940 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=855fd921201a75a21ff225128a8dced16cd95b52;p=emacs.git Make `M-x clipboard-yank' work reliably * lisp/menu-bar.el (clipboard-yank): Make the command work consistently (bug#27442). * lisp/select.el (gui-selection-value): Try to explain why the logic is the way it is. --- diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 739e751d8a4..8def1575b24 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -570,7 +570,9 @@ (defun clipboard-yank () "Insert the clipboard contents, or the last stretch of killed text." (interactive "*") - (let ((select-enable-clipboard t)) + (let ((select-enable-clipboard t) + ;; Ensure that we defeat the DWIM login in `gui-selection-value'. + (gui--last-selected-text-clipboard nil)) (yank))) (defun clipboard-kill-ring-save (beg end &optional region) diff --git a/lisp/select.el b/lisp/select.el index c39bc93deab..eaa74cebd80 100644 --- a/lisp/select.el +++ b/lisp/select.el @@ -184,11 +184,17 @@ decoded. If `gui-get-selection' signals an error, return nil." (let ((clip-text (when select-enable-clipboard (let ((text (gui--selection-value-internal 'CLIPBOARD))) - (if (string= text "") (setq text nil)) - - ;; Check the CLIPBOARD selection for 'newness', is it different - ;; from what we remembered them to be last time we did a - ;; cut/paste operation. + (when (string= text "") + (setq text nil)) + ;; When `select-enable-clipboard' is non-nil, + ;; killing/copying text (with, say, `C-w') will push the + ;; text to the clipboard (and store it in + ;; `gui--last-selected-text-clipboard'). We check + ;; whether the text on the clipboard is identical to this + ;; text, and if so, we report that the clipboard is + ;; empty. See (bug#27442) for further discussion about + ;; this DWIM action, and possible ways to make this check + ;; less fragile, if so desired. (prog1 (unless (equal text gui--last-selected-text-clipboard) text)