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.
This commit is contained in:
Lars Ingebrigtsen 2021-07-06 19:25:41 +02:00
parent abe5eb9add
commit 855fd92120
2 changed files with 14 additions and 6 deletions

View file

@ -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)

View file

@ -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)