help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple kill and paste from X clipboard


From: Manuel Giraud
Subject: Re: multiple kill and paste from X clipboard
Date: Wed, 17 Jan 2024 15:52:15 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Manuel Giraud via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> Stefan Monnier via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>>>   (add-hook 'x-sent-selection-functions 'next-primary)
>>
>> That's what I was about to suggest.  I've never seen it used until now,
>> so I wouldn't be surprised if it's quirky, tho.
>
> Yes, I've tested it lightly and it is not 100% reliable: sometimes it
> works and sometimes I just get one in two selections.

Hi,

I'm still toying with this idea with the following Lisp code (no more
timer involved):
--8<---------------cut here---------------start------------->8---
(defvar primary-list nil)

(defun next-primary (name type success)
  (when (and (eq name 'PRIMARY)
             (not (eq type 'TARGETS))
             success)
    (if primary-list
        (gui-set-selection 'PRIMARY (pop primary-list))
      ;; Remove me and clear PRIMARY
      (remove-hook 'x-sent-selection-functions 'next-primary)
      (gui-set-selection 'PRIMARY ""))))

(defun successively-in-primary (list)
  (add-hook 'x-sent-selection-functions 'next-primary)
  (gui-set-selection 'PRIMARY (car list))
  (setq primary-list (cdr list)))

(defun test-me ()
  (interactive)
  (successively-in-primary (list "hello" "how" "are" "you?")))
--8<---------------cut here---------------end--------------->8---

As I said previously, it works with some X client (like xterm) but with
a more useful one (Firefox) I just get half of the selections.

I tried to debug this and it seems to me that it is because Firefox
issues some "PRIMARY TARGETS" requests that ends up « consuming » the
user data (I'm not sure this is what happen but this is my
interpretation of it).

Anyway, I have put the following patch in place and it solves this issue
with Firefox.  Maybe Po you have an idea of what is going on here?
Thanks.

diff --git a/src/xselect.c b/src/xselect.c
index fd0f06eeed9..27c86cf86ed 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -1231,6 +1231,10 @@ x_handle_selection_request (struct selection_input_event 
*event)
 
       xfree (cs.data);
     }
+  else if (EQ (target_symbol, QTARGETS))
+    {
+      success = true;
+    }
   else
     {
       if (property == None)
-- 
Manuel Giraud

reply via email to

[Prev in Thread] Current Thread [Next in Thread]