GNU bug report logs -
#79592
[PATCH] mouse.el: Make mouse-yank-primary work in xterm-mouse-mode
Previous Next
To reply to this bug, email your comments to 79592 AT debbugs.gnu.org.
There is no need to reopen the bug first.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Tue, 07 Oct 2025 06:17:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Lin Sun <sunlin7 <at> hotmail.com>:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Tue, 07 Oct 2025 06:17:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi, There is a bug that mouse-2 pasting feature does not work on a xterm-256color with xterm-mouse-mode on. To reproduce the issue, setting the xterm-extra-capabilities with "getSelection" in the early-init.el, and turn on the "xterm-mouse-mode" in the .emacs. Here are the configuration lines: (setq xterm-extra-capabilities '(getSelection modifyOtherKeys reportBackground setSelection)) ; in early-init.el (xterm-mouse-mode) ; in .emacs file Then use a mintty (on windows) ssh to remote Ubuntu 22.04, and start emacs: $ export TERM=xterm-256color $ emacs -nw -q Switch to "*scratch*" buffer and press middle button on mouse, then emacs will give an user error message "No selection is available". Copy a word like "hello" into system clipboard, and switch to the mintty, try press "mouse-2" button, the "*scratch*" buffer will got "52;c;aGVsbG8="; as comparison, Ctrl+y yank feature works for the scenario. The issue is caused by the mouse-paste-primary function works towarding a GUI frame, but does not consider a xterm with OSC 52 enabled. Here are another quick way to reproduce the issue: 1. start a xterm on ubuntu 22, 2. run "emacs -nw -q" in the xterm 3. eval "(xterm-mouse-mode)" and "(xterm--init-activate-get-selection)" 4. press middle button on mouse to paste text; (press Ctrl+y for comparison) The patch file will fix the issue to make the mouse paste feature works on the scenario. Please help review it. Thanks
[Message part 2 (text/html, inline)]
[0001-lisp-mouse.el-mouse-yank-primary-Compatible-with-xte.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Tue, 07 Oct 2025 06:54:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 79592 <at> debbugs.gnu.org (full text, mbox):
> From: Lin Sun <sunlin7 <at> hotmail.com>
> Date: Tue, 7 Oct 2025 06:11:35 +0000
>
> Hi, There is a bug that mouse-2 pasting feature does not work on a xterm-256color with xterm-mouse-mode
> on. To reproduce the issue, setting the xterm-extra-capabilities with "getSelection" in the early-init.el, and
> turn on the "xterm-mouse-mode" in the .emacs. Here are the configuration lines:
> (setq xterm-extra-capabilities '(getSelection modifyOtherKeys reportBackground setSelection)) ; in early-init.el
> (xterm-mouse-mode) ; in .emacs file
> Then use a mintty (on windows) ssh to remote Ubuntu 22.04, and start
> emacs: $ export TERM=xterm-256color $ emacs -nw -q
> Switch to "*scratch*" buffer and press middle button
> on mouse, then emacs will give an user error message "No selection is available".
> Copy a word like "hello"
> into system clipboard, and switch to the mintty, try press "mouse-2" button, the "*scratch*" buffer will got
> "52;c;aGVsbG8="; as comparison, Ctrl+y yank feature works for the scenario.
> The issue is caused by the
> mouse-paste-primary function works towarding a GUI frame, but does not consider a xterm with OSC 52
> enabled. Here are another quick way to reproduce the issue:
> 1. start a xterm on ubuntu 22,
> 2. run "emacs -nw -q" in the xterm
> 3. eval "(xterm-mouse-mode)" and "(xterm--init-activate-get-selection)"
> 4. press middle button on mouse to paste text; (press Ctrl+y for comparison)
> The patch file will fix the issue to make the
> mouse paste feature works on the scenario. Please help review it. Thanks
Thanks. Jared, could you please look into this and provide comments
or suggestions?
> From becf74da64f96c3dcd11683b8faeb570ee55d11a Mon Sep 17 00:00:00 2001
> From: Lin Sun <sunlin7 <at> hotmail.com>
> Date: Mon, 6 Oct 2025 06:30:03 +0000
>
> * lisp/mouse.el (mouse-yank-primary): In a terminal frame with
> 'xterm-mouse-mode' on, use 'current-kill' instead of
> 'gui-get-primary-selection' to support yanking, where the PRIMARY
> selection is unavailable.
>
> ---
> lisp/mouse.el | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lisp/mouse.el b/lisp/mouse.el
> index 907a4883230..6ba0dbe7e85 100644
> --- a/lisp/mouse.el
> +++ b/lisp/mouse.el
> @@ -2148,7 +2148,9 @@ mouse-yank-primary
> (let (select-active-regions)
> (deactivate-mark)))
> (or mouse-yank-at-point (mouse-set-point event))
> - (let ((primary (gui-get-primary-selection)))
> + (let ((primary (if (display-graphic-p)
> + (gui-get-primary-selection)
> + (current-kill 0))))
> (push-mark)
> (insert-for-yank primary)))
>
> --
> 2.34.1
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Tue, 14 Oct 2025 23:32:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 79592 <at> debbugs.gnu.org (full text, mbox):
On 2025-10-06 23:53, Eli Zaretskii wrote:
>> From: Lin Sun <sunlin7 <at> hotmail.com>
>> Date: Tue, 7 Oct 2025 06:11:35 +0000
>>
>> Hi, There is a bug that mouse-2 pasting feature does not work on a
>> xterm-256color with xterm-mouse-mode
>> on. To reproduce the issue, setting the xterm-extra-capabilities with
>> "getSelection" in the early-init.el, and
>> turn on the "xterm-mouse-mode" in the .emacs. Here are the
>> configuration lines:
>> (setq xterm-extra-capabilities '(getSelection modifyOtherKeys
>> reportBackground setSelection)) ; in early-init.el
>> (xterm-mouse-mode) ; in .emacs file
>> Then use a mintty (on windows) ssh to remote Ubuntu 22.04, and start
>> emacs: $ export TERM=xterm-256color $ emacs -nw -q
>> Switch to "*scratch*" buffer and press middle button
>> on mouse, then emacs will give an user error message "No selection is
>> available".
>> Copy a word like "hello"
>> into system clipboard, and switch to the mintty, try press "mouse-2"
>> button, the "*scratch*" buffer will got
>> "52;c;aGVsbG8="; as comparison, Ctrl+y yank feature works for the
>> scenario.
>> The issue is caused by the
>> mouse-paste-primary function works towarding a GUI frame, but does not
>> consider a xterm with OSC 52
>> enabled. Here are another quick way to reproduce the issue:
>> 1. start a xterm on ubuntu 22,
>> 2. run "emacs -nw -q" in the xterm
>> 3. eval "(xterm-mouse-mode)" and
>> "(xterm--init-activate-get-selection)"
>> 4. press middle button on mouse to paste text; (press Ctrl+y for
>> comparison)
>> The patch file will fix the issue to make the
>> mouse paste feature works on the scenario. Please help review it.
>> Thanks
>
> Thanks. Jared, could you please look into this and provide comments
> or suggestions?
>
>> - (let ((primary (gui-get-primary-selection)))
>> + (let ((primary (if (display-graphic-p)
>> + (gui-get-primary-selection)
>> + (current-kill 0))))
Can you please confirm that this is changing because you are getting
different strings from the system clipboard? This could also be causing
a change because current-kill also looks at the Emacs kill ring. I
think gui-get-primary-selection and current-kill both end up talking to
the system clipboard through gui-backend-get-selection in term/xterm.el,
so that would be the only difference.
Please try the following to confirm. Check if you are seeing different
results from gui-backend-get-selection after this patch. You can use
M-x trace-function RET gui-backend-get-selection RET to see when these
are called and what the different results are.
My understanding is that gui-get-primary-selection calls through this
code path:
gui-get-primary-selection
gui--selection-value-internal
gui-get-selection
gui-backend-get-selection
And current-kill calls through this code path:
current-kill
gui-selection-value (through interprogram-paste-function)
gui--selection-value-internal
(and then the same flow as above)
-- MJF
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Wed, 15 Oct 2025 03:22:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 79592 <at> debbugs.gnu.org (full text, mbox):
> From: Jared Finder <jared <at> finder.org>
> Sent: Tuesday, October 14, 2025 04:31 PM
> Can you please confirm that this is changing because you are getting
> different strings from the system clipboard? This could also be causing
> a change because current-kill also looks at the Emacs kill ring. I
> think gui-get-primary-selection and current-kill both end up talking to
> the system clipboard through gui-backend-get-selection in term/xterm.el,
> so that would be the only difference.
I tried as the steps I pasted on first message, it's not caused by the kill ring.
> Please try the following to confirm. Check if you are seeing different
> results from gui-backend-get-selection after this patch. You can use
> M-x trace-function RET gui-backend-get-selection RET to see when these
> are called and what the different results are.
The trace results for two functions:
======================================================================
1 -> (gui-get-primary-selection)
1 <- gui-get-primary-selection: ""
======================================================================
1 -> (current-kill 0)
1 <- current-kill: "hello"
> My understanding is that gui-get-primary-selection calls through this
> code path:
>
> gui-get-primary-selection
> gui--selection-value-internal
> gui-get-selection
> gui-backend-get-selection
>
> And current-kill calls through this code path:
>
> current-kill
> gui-selection-value (through interprogram-paste-function)
> gui--selection-value-internal
> (and then the same flow as above)
The current-kill call stack:
* gui-backend-get-selection(CLIPBOARD STRING)
gui-get-selection(CLIPBOARD STRING)
gui--selection-value-internal(CLIPBOARD)
gui-selection-value()
current-kill(0)
The major function is the gui-backend-get-selection() in xterm.el, which supports the OCS 52 then get expected string from terminal. Then the mouse-2 paste feature works as good as C-y.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Wed, 15 Oct 2025 03:52:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 79592 <at> debbugs.gnu.org (full text, mbox):
Attache the call stacks for two functions:
* gui-backend-get-selection(PRIMARY STRING)
gui-get-selection(PRIMARY STRING)
gui--selection-value-internal(PRIMARY)
gui-get-primary-selection()
mouse-yank-primary((mouse-2...))
===============================
* gui-backend-get-selection(CLIPBOARD STRING)
gui-get-selection(CLIPBOARD STRING)
gui--selection-value-internal(CLIPBOARD)
gui-selection-value()
current-kill(0)
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Wed, 15 Oct 2025 03:54:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 79592 <at> debbugs.gnu.org (full text, mbox):
On 2025-10-14 20:21, Lin Sun wrote:
>> From: Jared Finder <jared <at> finder.org>
>> Sent: Tuesday, October 14, 2025 04:31 PM
>> Can you please confirm that this is changing because you are getting
>> different strings from the system clipboard? This could also be
>> causing
>> a change because current-kill also looks at the Emacs kill ring. I
>> think gui-get-primary-selection and current-kill both end up talking
>> to
>> the system clipboard through gui-backend-get-selection in
>> term/xterm.el,
>> so that would be the only difference.
>
> I tried as the steps I pasted on first message, it's not caused by the
> kill ring.
>
>> Please try the following to confirm. Check if you are seeing
>> different
>> results from gui-backend-get-selection after this patch. You can use
>> M-x trace-function RET gui-backend-get-selection RET to see when these
>> are called and what the different results are.
>
> The trace results for two functions:
> ======================================================================
> 1 -> (gui-get-primary-selection)
> 1 <- gui-get-primary-selection: ""
> ======================================================================
> 1 -> (current-kill 0)
> 1 <- current-kill: "hello"
Thanks, can you please run this as well with gui-backend-get-selection
also traced? I'm expecting to see a trace like the following. My
machine locally shows the following:
1 -> (gui-get-primary-selection)
| 2 -> (gui-backend-get-selection PRIMARY STRING)
| 2 <- gui-backend-get-selection: "hello"
1 <- gui-get-primary-selection: "hello"
======================================================================
1 -> (current-kill 0)
| 2 -> (gui-backend-get-selection CLIPBOARD STRING)
| 2 <- gui-backend-get-selection: "hello"
1 <- current-kill: "hello"
> The major function is the gui-backend-get-selection() in xterm.el,
> which supports the OCS 52 then get expected string from terminal. Then
> the mouse-2 paste feature works as good as C-y.
And I believe that gui-get-primary-selection already calls this. The
gui-backend-get-selection and gui-backend-set-selection generic
functions are the primary workhorses of system clipboard implementation.
-- MJF
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Wed, 15 Oct 2025 04:34:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 79592 <at> debbugs.gnu.org (full text, mbox):
On 2025-10-14 20:51, Lin Sun wrote:
> Attache the call stacks for two functions:
>
> * gui-backend-get-selection(PRIMARY STRING)
> gui-get-selection(PRIMARY STRING)
> gui--selection-value-internal(PRIMARY)
> gui-get-primary-selection()
> mouse-yank-primary((mouse-2...))
>
> ===============================
>
> * gui-backend-get-selection(CLIPBOARD STRING)
> gui-get-selection(CLIPBOARD STRING)
> gui--selection-value-internal(CLIPBOARD)
> gui-selection-value()
> current-kill(0)
Thanks.
This implies that on this terminal (mintty on Windows, right?), the
primary selection and the clipboard selection are not both set. Only the
clipboard is set. Mintty is the Cygwin terminal emulator and I believe
Cygwin optionally supports an X server.
Can you confirm my understanding here? No need for Emacs at this point,
just have a bash terminal open in mintty and run the following two
commands:
echo -e '\e]52;p;?\e\\'
echo -e '\e]52;c;?\e\\'
-- MJF
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Wed, 15 Oct 2025 07:04:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 79592 <at> debbugs.gnu.org (full text, mbox):
From: Jared Finder <jared <at> finder.org>
Sent: Tuesday, October 14, 2025 09:33 PM
> This implies that on this terminal (mintty on Windows, right?), the
> primary selection and the clipboard selection are not both set. Only the
> clipboard is set. Mintty is the Cygwin terminal emulator and I believe
> Cygwin optionally supports an X server.
>
> Can you confirm my understanding here? No need for Emacs at this point,
> just have a bash terminal open in mintty and run the following two
> commands:
>
> echo -e '\e]52;p;?\e\\'
> echo -e '\e]52;c;?\e\\'
The output from mintty as follow, seems it's a mintty issue that responsed the "..;p;.." with "..;c;..".
$ echo -e '\e]52;c;?\e\\'
$ 52;c;aGVsbG8=
$ echo -e '\e]52;p;?\e\\'
$ 52;c;aGVsbG8=
So it's a mitty issue which give wrong response for the primary clipboard querying.
I find the line in mintty source code which caused the issue:
https://github.com/mintty/mintty/blob/f942dfb303bf4c0e7e137d43eeb409bead57510c/src/termout.c#L4525
I had report the issue to mintty:
https://github.com/mintty/mintty/issues/1337
Please feel free to close this ticket. Thank you so much!
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Fri, 17 Oct 2025 14:42:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 79592 <at> debbugs.gnu.org (full text, mbox):
Hi Jared,
According to the https://github.com/mintty/mintty/issues/1337, the "primary-clipboard" is not available for mintty on Windows.
And the document https://invisible-island.net/xterm/ctlseqs/ctlseqs.html had mentioned an OSC 52 query can be in variant formats, like
a) an empty type "\e]52;;?\e\\" for default
b) multiple type "\e]52;cp0;?\e\\" for clipboard/primary/0 indexed clipboard
c) "\e]52;?;?\e\\" to query first available
Can Emacs use one of them for better compatibility for term on windows? Thanks
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Sat, 01 Nov 2025 09:07:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 79592 <at> debbugs.gnu.org (full text, mbox):
Ping! Jared, any further comments? Or should I close this bug?
> From: Lin Sun <sunlin7 <at> hotmail.com>
> CC: Eli Zaretskii <eliz <at> gnu.org>, "79592 <at> debbugs.gnu.org"
> <79592 <at> debbugs.gnu.org>
> Date: Fri, 17 Oct 2025 14:41:34 +0000
> msip_labels:
>
> Hi Jared,
>
> According to the https://github.com/mintty/mintty/issues/1337, the "primary-clipboard" is not available for mintty on Windows.
>
> And the document https://invisible-island.net/xterm/ctlseqs/ctlseqs.html had mentioned an OSC 52 query can be in variant formats, like
>
> a) an empty type "\e]52;;?\e\\" for default
>
> b) multiple type "\e]52;cp0;?\e\\" for clipboard/primary/0 indexed clipboard
>
> c) "\e]52;?;?\e\\" to query first available
>
> Can Emacs use one of them for better compatibility for term on windows? Thanks
>
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79592; Package
emacs.
(Sat, 01 Nov 2025 15:55:01 GMT)
Full text and
rfc822 format available.
Message #35 received at 79592 <at> debbugs.gnu.org (full text, mbox):
On 2025-11-01 02:06, Eli Zaretskii wrote:
> Ping! Jared, any further comments? Or should I close this bug?
I think you can close this bug. Mintty has addressed the issue on their
side in
https://github.com/mintty/mintty/commit/070229da33ddd77119fc92cf5db0be5dfd79a861.
-- MJF
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility.
(Sat, 01 Nov 2025 16:48:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Lin Sun <sunlin7 <at> hotmail.com>:
bug acknowledged by developer.
(Sat, 01 Nov 2025 16:48:02 GMT)
Full text and
rfc822 format available.
Message #40 received at 79592-done <at> debbugs.gnu.org (full text, mbox):
> Date: Sat, 01 Nov 2025 08:54:06 -0700
> From: Jared Finder <jared <at> finder.org>
> Cc: Lin Sun <sunlin7 <at> hotmail.com>, 79592 <at> debbugs.gnu.org
>
> On 2025-11-01 02:06, Eli Zaretskii wrote:
> > Ping! Jared, any further comments? Or should I close this bug?
>
> I think you can close this bug. Mintty has addressed the issue on their
> side in
> https://github.com/mintty/mintty/commit/070229da33ddd77119fc92cf5db0be5dfd79a861.
Thanks, closing.
This bug report was last modified 4 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.