GNU bug report logs -
#80083
Detect OSC-52 support (OS clipboard integration) from Primary Device Attributes
Previous Next
To reply to this bug, email your comments to 80083 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#80083; Package
emacs.
(Sun, 28 Dec 2025 13:14:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Daniel Eklöf <daniel <at> ekloef.se>:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Sun, 28 Dec 2025 13:14:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[0001-Use-Primary-Device-Attributes-to-detect-OSC-52-suppo.patch (text/x-patch, attachment)]
[0002-Automatically-enable-xterm-mouse-mode-in-the-foot-te.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]
When auto-detecting OSC-52 support (xterm-extra-capabilities ==
check), Emacs currently requests the Secondary Device Attributes,
and parses it with the assumption the response is an XTerm version
number (more or less - there are attempts to detect e.g. Gnome
Terminal and map it to a corresponding XTerm version number). For
other terminals, all bets are off.
Almost all modern terminal emulators recently decided to add '52'
to their Primary Device Attributes, to signal support for
OSC-52. The first patch requests the primary DA, and enables
get-selection if '52' is found in the response. We _could_ also
enable set-selection, but the specification does not *guarantee*
the clipboard can be read. But most terminals will allow it. It
also only guarantees that the 'c' parameter (CLIPBOARD) is
supported, but most terminals should also support 'p'
(PRIMARY). Emacs does make use of both 'c' and 'p', but given the
rather random detection currently being done, and given that 'p'
will be ignored by terminals not supporting it, this patch is
still an improvement. See
https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
for details.
The second patch adds 'foot' to the list of terminals for which
xterm-mouse-mode should be automatically enabled. It has always
supported OSC-52, but the first patch is required for Emacs to
enable it automatically.
--
Daniel
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#80083; Package
emacs.
(Sun, 28 Dec 2025 17:48:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 80083 <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 28 Dec 2025 14:12:56 +0100
> From: Daniel Eklöf via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> When auto-detecting OSC-52 support (xterm-extra-capabilities ==
> check), Emacs currently requests the Secondary Device Attributes,
> and parses it with the assumption the response is an XTerm version
> number (more or less - there are attempts to detect e.g. Gnome
> Terminal and map it to a corresponding XTerm version number). For
> other terminals, all bets are off.
>
> Almost all modern terminal emulators recently decided to add '52'
> to their Primary Device Attributes, to signal support for
> OSC-52. The first patch requests the primary DA, and enables
> get-selection if '52' is found in the response. We _could_ also
> enable set-selection, but the specification does not *guarantee*
> the clipboard can be read. But most terminals will allow it. It
> also only guarantees that the 'c' parameter (CLIPBOARD) is
> supported, but most terminals should also support 'p'
> (PRIMARY). Emacs does make use of both 'c' and 'p', but given the
> rather random detection currently being done, and given that 'p'
> will be ignored by terminals not supporting it, this patch is
> still an improvement. See
> https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
> for details.
>
> The second patch adds 'foot' to the list of terminals for which
> xterm-mouse-mode should be automatically enabled. It has always
> supported OSC-52, but the first patch is required for Emacs to
> enable it automatically.
Thanks.
Jared, any comments or suggestions?
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#80083; Package
emacs.
(Mon, 29 Dec 2025 21:57:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 80083 <at> debbugs.gnu.org (full text, mbox):
On 2025-12-28 09:47, Eli Zaretskii wrote:
>> Date: Sun, 28 Dec 2025 14:12:56 +0100
>> From: Daniel Eklöf via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>> When auto-detecting OSC-52 support (xterm-extra-capabilities ==
>> check), Emacs currently requests the Secondary Device Attributes,
>> and parses it with the assumption the response is an XTerm version
>> number (more or less - there are attempts to detect e.g. Gnome
>> Terminal and map it to a corresponding XTerm version number). For
>> other terminals, all bets are off.
>>
>> Almost all modern terminal emulators recently decided to add '52'
>> to their Primary Device Attributes, to signal support for
>> OSC-52. The first patch requests the primary DA, and enables
>> get-selection if '52' is found in the response. We _could_ also
>> enable set-selection, but the specification does not *guarantee*
>> the clipboard can be read. But most terminals will allow it. It
>> also only guarantees that the 'c' parameter (CLIPBOARD) is
>> supported, but most terminals should also support 'p'
>> (PRIMARY). Emacs does make use of both 'c' and 'p', but given the
>> rather random detection currently being done, and given that 'p'
>> will be ignored by terminals not supporting it, this patch is
>> still an improvement. See
>> https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
>> for details.
+ ;; Many modern terminals include 52 in their primary DA
+ ;; response, to indicate support for *writing* to the OS
+ ;; clipboard. *Reading* the clipboard is _usually_ possible,
but
+ ;; not guaranteed. See
+ ;;
https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
+ ;;(xterm--init-activate-get-selection)
In my experience, reading the clipboard is often unsupported. Many
terminals refuse to support reading the clipboard as a matter of policy
for security reasons. I would just leave out the reference to getting
the selection.
Otherwise, this patch is fine.
>> The second patch adds 'foot' to the list of terminals for which
>> xterm-mouse-mode should be automatically enabled. It has always
>> supported OSC-52, but the first patch is required for Emacs to
>> enable it automatically.
I don't have foot terminal available locally to test. Assuming that
bracketed paste mode is supported, this patch is fine.
Thanks!
-- MJF
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#80083; Package
emacs.
(Tue, 30 Dec 2025 06:07:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 80083 <at> debbugs.gnu.org (full text, mbox):
[0001-Use-Primary-Device-Attributes-to-detect-OSC-52-suppo.patch (text/x-patch, attachment)]
[0002-Automatically-enable-xterm-mouse-mode-in-the-foot-te.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]
> + ;; Many modern terminals include 52 in their primary DA
> + ;; response, to indicate support for *writing* to the
> OS
> + ;; clipboard. *Reading* the clipboard is _usually_
> possible,
> but
> + ;; not guaranteed. See
> + ;;
> https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
> + ;;(xterm--init-activate-get-selection)
>
> In my experience, reading the clipboard is often unsupported.
> Many
> terminals refuse to support reading the clipboard as a matter of
> policy for security reasons. I would just leave out the
> reference to
> getting the selection.
>
> Otherwise, this patch is fine.
That makes sense. I've updated the comment, and removed the
commented out reference to xterm--init-activate-get-selection in
the attached patch.
>>> The second patch adds 'foot' to the list of terminals for
>>> which
>>> xterm-mouse-mode should be automatically enabled. It has
>>> always
>>> supported OSC-52, but the first patch is required for Emacs to
>>> enable it automatically.
>
> I don't have foot terminal available locally to test. Assuming
> that
> bracketed paste mode is supported, this patch is fine.
Bracketed paste is supported :)
--
Daniel
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#80083; Package
emacs.
(Tue, 30 Dec 2025 18:13:04 GMT)
Full text and
rfc822 format available.
Message #17 received at 80083 <at> debbugs.gnu.org (full text, mbox):
On 2025-12-29 22:06, Daniel Eklöf wrote:
>> + ;; Many modern terminals include 52 in their primary DA
>> + ;; response, to indicate support for *writing* to the OS
>> + ;; clipboard. *Reading* the clipboard is _usually_ possible,
>> but
>> + ;; not guaranteed. See
>> + ;;
>> https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
>> + ;;(xterm--init-activate-get-selection)
>>
>> In my experience, reading the clipboard is often unsupported. Many
>> terminals refuse to support reading the clipboard as a matter of
>> policy for security reasons. I would just leave out the reference to
>> getting the selection.
>>
>> Otherwise, this patch is fine.
>
> That makes sense. I've updated the comment, and removed the commented
> out reference to xterm--init-activate-get-selection in the attached
> patch.
>
>>>> The second patch adds 'foot' to the list of terminals for which
>>>> xterm-mouse-mode should be automatically enabled. It has always
>>>> supported OSC-52, but the first patch is required for Emacs to
>>>> enable it automatically.
>>
>> I don't have foot terminal available locally to test. Assuming that
>> bracketed paste mode is supported, this patch is fine.
>
> Bracketed paste is supported :)
Thanks for the update. These patches look generally look good to me.
Only one comment:
+(defun xterm--primary-da-handler ()
+ ;; The reply should be: \e [ ? NUMBER1 ; ... ; NUMBER_N c
+ (let ((str (xterm--read-string ?c)))
+ (let ((numbers (mapcar #'string-to-number
+ (split-string str ";" t))))
Can you put a comment how the existing error handling is structured?
Because of the wide variety of terminal implementations Emacs should
tolerate improper responses. This code relies on the function
string-to-number's error handling right now, which is fine, however a
future contributor may not realize that.
-- MJF
This bug report was last modified today.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.