unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Constantine Kharlamov <Hi-Angel@yandex.ru>
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>, 27442@debbugs.gnu.org
Subject: bug#27442: Un-obsolete x-clipboard-yank, or provide analogous functional
Date: Mon, 05 Jul 2021 16:13:43 +0200	[thread overview]
Message-ID: <877di4yhk8.fsf@gnus.org> (raw)
In-Reply-To: <9b98217a-be79-56ed-16a9-0c15622111c5@yandex.ru> (Constantine Kharlamov's message of "Wed, 21 Jun 2017 22:55:58 +0300")

Constantine Kharlamov <Hi-Angel@yandex.ru> writes:

> 1. start `emacs -Q`
> 2. Press M-: to execute `(setq select-enable-clipboard nil)`
> 3. Copy a text in the system, i.e. outside of Emacs.
> 4. Press M-: to execute `(clipboard-yank)` (you'll get at the point a
> content from system clipboard)
> 5. Press M-< M-d (so now you have the word ";; This" in kill-ring)
> 6. Press M-: to execute `(clipboard-yank)`
>
> 	You will see ";; This" got pasted at point, not the value in
> the system clipboard.
>
> 7. Press M-: to execute `(x-clipboard-yank)`
>
> 	You will see content from the system clipboard got pasted at point.

Aaah!  This explains the weird behaviour I've been seeing when I'm
trying to paste stuff from the clipboard -- as you say,
`M-x clipboard-yank' doesn't work reliably if you've yanked the
clipboard contents once.

And that's because of this:

(defun gui-selection-value ()
  (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.
             (prog1
                 (unless (equal text gui--last-selected-text-clipboard)
                   text)
               (setq gui--last-selected-text-clipboard text)))))

So, indeed, if you `M-x clipboard-yank', then kill some text in Emacs,
you can't `M-x clipboard-yank' until you've clipboarded some other text,
yanked it, and then clipboarded the original text again.

Fixing this should be pretty trivial -- the following patch should do
the trick, I think (although I haven't tested it).  But I'm not quite
sure about the intended logic here, so I've added Stefan M to the CCs --
perhaps he has some comments.

diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 739e751d8a..dac04e113e 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -570,7 +570,8 @@ menu-bar-edit-menu
 (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)
+        (gui--last-selected-text-clipboard nil))
     (yank)))
 
 (defun clipboard-kill-ring-save (beg end &optional region)


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  reply	other threads:[~2021-07-05 14:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 14:29 bug#27442: Un-obsolete x-clipboard-yank, or provide analogous functional Constantine Kharlamov
2017-06-21 19:10 ` Eli Zaretskii
2017-06-21 19:55   ` Constantine Kharlamov
2021-07-05 14:13     ` Lars Ingebrigtsen [this message]
2021-07-05 14:46       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-05 15:28         ` Lars Ingebrigtsen
2021-07-05 15:59           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-07-05 16:55           ` Eli Zaretskii
2021-07-05 20:11             ` Lars Ingebrigtsen
2021-07-05 20:24               ` Lars Ingebrigtsen
2021-07-06 11:21               ` Eli Zaretskii
2021-07-06 14:18                 ` Lars Ingebrigtsen
2021-07-06 15:45                   ` Eli Zaretskii
2021-07-06 16:20                     ` Lars Ingebrigtsen
2021-07-06 17:15                       ` Eli Zaretskii
2021-07-06 17:26                         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877di4yhk8.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=27442@debbugs.gnu.org \
    --cc=Hi-Angel@yandex.ru \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).