all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* multiple kill and paste from X clipboard
@ 2024-01-12 15:35 Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-12 15:49 ` Eli Zaretskii
  2024-01-12 20:12 ` orzodk
  0 siblings, 2 replies; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-12 15:35 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'd like to be able to paste a serie of strings from Emacs to an
external X program (e.g. a form with multiple entry in a web browser).

I could put all the strings in the Emacs' kill-ring but then a paste in
the other program will just retrieve the last killed string.  Or maybe,
Emacs could be informed that the last kill was paste externally and then
proceed to kill the next item?

How could I do that?
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-12 15:35 multiple kill and paste from X clipboard Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-12 15:49 ` Eli Zaretskii
  2024-01-12 16:58   ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-12 20:12 ` orzodk
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2024-01-12 15:49 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 12 Jan 2024 16:35:18 +0100
> From:  Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> 
> I'd like to be able to paste a serie of strings from Emacs to an
> external X program (e.g. a form with multiple entry in a web browser).
> 
> I could put all the strings in the Emacs' kill-ring but then a paste in
> the other program will just retrieve the last killed string.  Or maybe,
> Emacs could be informed that the last kill was paste externally and then
> proceed to kill the next item?
> 
> How could I do that?

Did you try using append-next-kill to make all the strings be a single
large kill?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-12 15:49 ` Eli Zaretskii
@ 2024-01-12 16:58   ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-12 19:49     ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-13  0:42     ` Po Lu
  0 siblings, 2 replies; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-12 16:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Fri, 12 Jan 2024 16:35:18 +0100
>> From:  Manuel Giraud via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
>> 
>> I'd like to be able to paste a serie of strings from Emacs to an
>> external X program (e.g. a form with multiple entry in a web browser).
>> 
>> I could put all the strings in the Emacs' kill-ring but then a paste in
>> the other program will just retrieve the last killed string.  Or maybe,
>> Emacs could be informed that the last kill was paste externally and then
>> proceed to kill the next item?
>> 
>> How could I do that?
>
> Did you try using append-next-kill to make all the strings be a single
> large kill?

I guess that it would work but it is not what I intended to do.  I'd
like to be able to paste each string separately.  For example: paste the
first string in one text form, the second one elsewhere,…
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-12 16:58   ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-12 19:49     ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-13  0:42     ` Po Lu
  1 sibling, 0 replies; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-12 19:49 UTC (permalink / raw)
  To: Manuel Giraud via Users list for the GNU Emacs text editor; +Cc: Eli Zaretskii

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

> Eli Zaretskii <eliz@gnu.org> writes:

[...]

>> Did you try using append-next-kill to make all the strings be a single
>> large kill?
>
> I guess that it would work but it is not what I intended to do.  I'd
> like to be able to paste each string separately.  For example: paste the
> first string in one text form, the second one elsewhere,…

FWIW, I have found that I could do the following:

(gui-set-selection 'CLIPBOARD first-string)
(gui-set-selection 'PRIMARY second-string)

But this has two drawbacks:
    - You cannot store more than two strings
    - The procedure for yanking is different for one string to the other
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-12 15:35 multiple kill and paste from X clipboard Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-12 15:49 ` Eli Zaretskii
@ 2024-01-12 20:12 ` orzodk
  2024-01-12 21:32   ` Manuel Giraud via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 15+ messages in thread
From: orzodk @ 2024-01-12 20:12 UTC (permalink / raw)
  To: Manuel Giraud via Users list for the GNU Emacs text editor; +Cc: Manuel Giraud

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

> Hi,
>
> I'd like to be able to paste a serie of strings from Emacs to an
> external X program (e.g. a form with multiple entry in a web browser).
>
> I could put all the strings in the Emacs' kill-ring but then a paste in
> the other program will just retrieve the last killed string.  Or maybe,
> Emacs could be informed that the last kill was paste externally and then
> proceed to kill the next item?
>
> How could I do that?

This is a limitation of X not Emacs. Each time you kill a value Emacs
will put it into X's clipboard overwriting the previous value. A
clipboard manager will help with this by keeping the history around. I
personally use clipmenu but there are several tools to choose from. I
also bind C-M-v in the window manager to the command to display the
manager's history.

My workflow for what you're asking would be:

- kill-ring-save (M-w) however many times in Emacs to populate the
  clipboard manager's history.
- Switch to the browser
- Pull up the clipboard history (C-M-v) and select the value I want for
  each form entry. 



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-12 20:12 ` orzodk
@ 2024-01-12 21:32   ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-12 21:32 UTC (permalink / raw)
  To: orzodk; +Cc: Manuel Giraud via Users list for the GNU Emacs text editor

orzodk <orzodk@fastmail.com> writes:

> Manuel Giraud via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>> Hi,
>>
>> I'd like to be able to paste a serie of strings from Emacs to an
>> external X program (e.g. a form with multiple entry in a web browser).
>>
>> I could put all the strings in the Emacs' kill-ring but then a paste in
>> the other program will just retrieve the last killed string.  Or maybe,
>> Emacs could be informed that the last kill was paste externally and then
>> proceed to kill the next item?
>>
>> How could I do that?
>
> This is a limitation of X not Emacs. Each time you kill a value Emacs
> will put it into X's clipboard overwriting the previous value. A
> clipboard manager will help with this by keeping the history around. I
> personally use clipmenu but there are several tools to choose from. I
> also bind C-M-v in the window manager to the command to display the
> manager's history.

Thanks.  I've never used a clipboard manager so maybe I should now.  I
wish I could have a simpler Emacs only solution for this.  I thought
that maybe Emacs could be aware when the content is get from the primary
selection or the clipboard.
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-12 16:58   ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-12 19:49     ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-13  0:42     ` Po Lu
  2024-01-13 10:08       ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-14 15:58       ` Manuel Giraud via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 15+ messages in thread
From: Po Lu @ 2024-01-13  0:42 UTC (permalink / raw)
  To: Manuel Giraud via Users list for the GNU Emacs text editor
  Cc: Eli Zaretskii, Manuel Giraud

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

> I guess that it would work but it is not what I intended to do.  I'd
> like to be able to paste each string separately.  For example: paste the
> first string in one text form, the second one elsewhere,…

X doesn't provide any mechanism for programs to exchange the contents of
independent text fields, so this isn't possible, unless you implement
your own protocol on both sides of the selection request.  The most
similar mechanism is the Search Parameter Sharing Protocol, which has
languished over the years, in that its implementations are unreliable if
they exist at all.

Don't let the above deter you from implementing this, as such a protocol
would be a welcome addition if adopted by the popular toolkits.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-13  0:42     ` Po Lu
@ 2024-01-13 10:08       ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-14 15:58       ` Manuel Giraud via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-13 10:08 UTC (permalink / raw)
  To: Po Lu
  Cc: Manuel Giraud via Users list for the GNU Emacs text editor,
	Eli Zaretskii

Po Lu <luangruo@yahoo.com> writes:

> Manuel Giraud via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>> I guess that it would work but it is not what I intended to do.  I'd
>> like to be able to paste each string separately.  For example: paste the
>> first string in one text form, the second one elsewhere,…
>
> X doesn't provide any mechanism for programs to exchange the contents of
> independent text fields, so this isn't possible, unless you implement
> your own protocol on both sides of the selection request.  The most
> similar mechanism is the Search Parameter Sharing Protocol, which has
> languished over the years, in that its implementations are unreliable if
> they exist at all.

Thanks Po.  Too bad there is no such mechanism already.

> Don't let the above deter you from implementing this, as such a protocol
> would be a welcome addition if adopted by the popular toolkits.

I don't think I can/will code this but, just for the record, you're
talking about implementing "Search Parameter Sharing Protocol" here?
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-13  0:42     ` Po Lu
  2024-01-13 10:08       ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-14 15:58       ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-14 22:45         ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-14 15:58 UTC (permalink / raw)
  To: Po Lu
  Cc: Manuel Giraud via Users list for the GNU Emacs text editor,
	Eli Zaretskii

Hi,

FTR, I was able to get the behaviour I wanted with the following code.
So far, it has two drawbacks:
        - it works with the primary selection and is, therefore, X11
          only
        - it does not work on Emacs itself (but we have better
          alternatives here ;-)

--8<---------------cut here---------------start------------->8---
(defvar primary-list nil)
(defvar my-timer nil)

(defun next-primary (name type success)
  (when (and (eq name 'PRIMARY)
	     (not (eq type 'TARGETS))
	     success
	     primary-list)
    (gui-set-selection 'PRIMARY (pop primary-list))))

(defun clean-up-when-empty ()
  (unless primary-list
    (cancel-timer my-timer)
    (setq my-timer nil)
    (remove-hook 'x-sent-selection-functions 'next-primary)))

(defun put-list-into-primary (list)
  (gui-set-selection 'PRIMARY (car list))
  (setq primary-list (cdr list))
  (add-hook 'x-sent-selection-functions 'next-primary)
  (setq my-timer (run-with-timer t 1 'clean-up-when-empty)))

(defun test-me ()
  (interactive)
  (put-list-into-primary (list "hello" "how" "are" "you?")))
--8<---------------cut here---------------end--------------->8---
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-14 15:58       ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-14 22:45         ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-01-15 14:09           ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-01-14 22:45 UTC (permalink / raw)
  To: help-gnu-emacs

>   (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.


        Stefan




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-14 22:45         ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-01-15 14:09           ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-17 14:52             ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-15 14:09 UTC (permalink / raw)
  To: Stefan Monnier via Users list for the GNU Emacs text editor
  Cc: Stefan Monnier

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.
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-15 14:09           ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-17 14:52             ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-01-31 19:27               ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-01-17 14:52 UTC (permalink / raw)
  To: Manuel Giraud via Users list for the GNU Emacs text editor
  Cc: Stefan Monnier, Po Lu

[-- Attachment #1: Type: text/plain, Size: 1922 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: targets.patch --]
[-- Type: text/x-patch, Size: 365 bytes --]

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)

[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-17 14:52             ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-01-31 19:27               ` Stefan Monnier
  2024-02-02 15:58                 ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2024-01-31 19:27 UTC (permalink / raw)
  To: Manuel Giraud
  Cc: Manuel Giraud via Users list for the GNU Emacs text editor, Po Lu

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

I'm definitely not an expert in the way selection works in GUIs, nor how
this works in Emacs.  So I can't judge what your patch does, sorry.
This said, maybe a "safer" change is to propagate the information that
a particular request is a "TARGETS" request to the
`x-sent-selection-functions` so that *your* function can decide whether
that should count as consuming or not.


        Stefan




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-01-31 19:27               ` Stefan Monnier
@ 2024-02-02 15:58                 ` Manuel Giraud via Users list for the GNU Emacs text editor
  2024-02-02 16:54                   ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-02-02 15:58 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: Manuel Giraud via Users list for the GNU Emacs text editor, Po Lu

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> 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).
>
> I'm definitely not an expert in the way selection works in GUIs, nor how
> this works in Emacs.  So I can't judge what your patch does, sorry.
> This said, maybe a "safer" change is to propagate the information that
> a particular request is a "TARGETS" request to the
> `x-sent-selection-functions` so that *your* function can decide whether
> that should count as consuming or not.

Hi Stefan,

This is what is not clear to me because this information is already
propagated (and handled) via 'type' in my function 'next-primary'.
FWIW, it may also be a bug in firefox because this works in chromium for
example.
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: multiple kill and paste from X clipboard
  2024-02-02 15:58                 ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2024-02-02 16:54                   ` Manuel Giraud via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 15+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2024-02-02 16:54 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: Manuel Giraud via Users list for the GNU Emacs text editor, Po Lu

Manuel Giraud <manuel@ledu-giraud.fr> writes:

[...]

>> I'm definitely not an expert in the way selection works in GUIs, nor how
>> this works in Emacs.  So I can't judge what your patch does, sorry.
>> This said, maybe a "safer" change is to propagate the information that
>> a particular request is a "TARGETS" request to the
>> `x-sent-selection-functions` so that *your* function can decide whether
>> that should count as consuming or not.
>
> Hi Stefan,
>
> This is what is not clear to me because this information is already
> propagated (and handled) via 'type' in my function 'next-primary'.
> FWIW, it may also be a bug in firefox because this works in chromium for
> example.

Ok, so just a "heads up" on this.  My test with Firefox was not exactly
useful: I only test it in the address bar.  But this works as expected
with web forms.  So I think there might be some bug in primary selection
handling in the Firefox address bar… but I could live with that.
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-02-02 16:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12 15:35 multiple kill and paste from X clipboard Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-12 15:49 ` Eli Zaretskii
2024-01-12 16:58   ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-12 19:49     ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-13  0:42     ` Po Lu
2024-01-13 10:08       ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-14 15:58       ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-14 22:45         ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-01-15 14:09           ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-17 14:52             ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-31 19:27               ` Stefan Monnier
2024-02-02 15:58                 ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-02-02 16:54                   ` Manuel Giraud via Users list for the GNU Emacs text editor
2024-01-12 20:12 ` orzodk
2024-01-12 21:32   ` Manuel Giraud via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.