* bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame
@ 2016-10-09 16:39 Olaf Rogalsky
2016-12-09 9:30 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra Stephane Chauveau
2021-02-06 12:08 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Lars Ingebrigtsen
0 siblings, 2 replies; 4+ messages in thread
From: Olaf Rogalsky @ 2016-10-09 16:39 UTC (permalink / raw)
To: 24652
Hi emacs,
I try to get `gui-backend-get-selection' to work with xterm:
# In a xterm (version 324):
# 1.) put some text into the clipboard:
echo foobar | xsel -i -b
# 2.) try to insert the clipboard into a fresh *scratch* buffer:
emacs -nw -Q --eval "(progn (xterm--init-activate-get-selection) (insert (gui-backend-get-selection 'CLIPBOARD 'STRING)))"
No text from the clipboard is inserted, instead "Quit" is displayed in
the echo area.
# 3.) for further insight, lets do the same with (setq inhibit-quit t):
emacs -nw -Q --eval "(progn (setq inhibit-quit t) (xterm--init-activate-get-selection) (insert (gui-backend-get-selection 'CLIPBOARD 'STRING)))"
Now the clipboard content is inserted!
My undestanding of the problem is: The xterm escape sequence to query the clipboard content is:
"\e]52;p;?\a"
and xterm responds to this with
"\e]52;p;<base64-encoded-clipboard-content>\a"
Note, that the last character of the response is an "\a", which is the
same as the keyboard quit key "\C-g" and hence, the
gui-backend-get-selection command is aborted before finsishing its work.
Possible solution: There is an alternative escape sequence for querying
the clipoard content:
"\e]52;p;?\e\\"
and the response to this is
"\e]52;p;<base64-encoded-clipboard-content>\e\\"
which does not suffer from the "\C-g" abortion.
Thanks, Olaf
In GNU Emacs 25.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.8, cairo version 1.13.1)
of 2016-09-21 built on blaubaer
Repository revision: d9741b61c8e446de084cc4dc609aaa8e5702118d
System Description: Ubuntu 14.04.4 LTS
Recent messages:
Mark saved where search started
Making completion list...
Quit
Composing main Info directory...done
Making completion list...
C-x n C-g is undefined
Updating buffer list...done
Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help
Entering debugger...
Quit [2 times]
Configured using:
'configure --prefix /home/olaf/local --with-x-toolkit=gtk3 --with-cairo
--with-modules --with-file-notification --without-gconf
--without-gsettings PKG_CONFIG_PATH=/home/olaf/local/lib/pkgconfig
--infodir /home/olaf/local/share/info
--infodir=/home/olaf/local/share/info'
Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO IMAGEMAGICK SOUND GPM DBUS NOTIFY ACL
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 MODULES
Important settings:
value of $LANG: de_DE.UTF-8
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix
Major mode: Emacs-Lisp
Minor modes in effect:
diff-auto-refine-mode: t
savehist-mode: t
save-place-mode: t
global-page-break-lines-mode: t
page-break-lines-mode: t
rainbow-delimiters-mode: t
indent-guide-global-mode: t
indent-guide-mode: t
global-company-mode: t
company-mode: t
recentf-mode: t
xterm-mouse-mode: t
override-global-mode: t
auto-compile-on-load-mode: t
auto-compile-on-save-mode: t
auto-compile-mode: t
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
size-indication-mode: t
column-number-mode: t
line-number-mode: t
transient-mark-mode: t
Load-path shadows:
/home/olaf/local/share/emacs/site-lisp/emms/tq hides /home/olaf/local/share/emacs/25.1.50/lisp/emacs-lisp/tq
Features:
(shadow mail-extr filecache emacsbug message subr-x puny rfc822 mml
mml-sec epa derived epg gnus-util rmail rmail-loaddefs mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils info
misearch multi-isearch pulse find-func thingatpt ibuf-ext ibuffer
ibuffer-loaddefs help-fns radix-tree debug warnings compile comint
vc-git diff-mode map term/xterm xterm disp-table company-oddmuse
company-keywords company-etags etags xref project ring company-gtags
company-dabbrev-code company-dabbrev company-files company-capf
company-cmake company-xcode company-clang company-semantic company-eclim
company-template company-css company-nxml company-bbdb my-tests
my-key-bindings my-audio eap-autoloads eap-dired-keybindings my-packages
emms-librefm-stream xml emms-librefm-scrobbler emms-playlist-limit
emms-volume emms-volume-amixer emms-i18n emms-history emms-score
emms-stream-info emms-metaplaylist-mode emms-bookmarks emms-cue
emms-mode-line-icon emms-browser sort emms-playlist-sort
emms-last-played emms-player-xine emms-player-mpd tq emms-playing-time
emms-lyrics emms-url url url-proxy url-privacy url-expand url-methods
url-history url-cookie url-domsuf url-util mailcap emms-streams
emms-tag-editor format-spec emms-mark emms-mode-line emms-cache
emms-info-ogginfo emms-info-mp3info emms-info later-do
emms-playlist-mode emms-player-vlc emms-player-mplayer
emms-player-simple emms-source-playlist emms-source-file locate dired
dired-loaddefs emms-setup emms emms-compat savehist saveplace
page-break-lines paren mic-paren rainbow-delimiters rainbow-mode
ansi-color color indent-guide windmove browse-kill-ring loccur
yank-pop-improved company edmacro kmacro recentf tree-widget wid-edit
linum xt-mouse use-package diminish bind-key easy-mmode my-tex
my-defaults my-functions my-xterm time-date delsel cus-start jka-compr
cus-load sanityinc-tomorrow-eighties-theme
color-theme-sanityinc-tomorrow auto-compile advice packed dash
finder-inf package epg-config url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs eieio-loaddefs password-cache url-vars seq
byte-opt gv bytecomp byte-compile cl-extra help-mode easymenu cconv
cl-loaddefs pcase cl-lib mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote dbusbind inotify dynamic-setting
font-render-setting cairo move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)
Memory information:
((conses 16 243748 15982)
(symbols 48 30612 0)
(miscs 40 120 557)
(strings 32 56664 5894)
(string-bytes 1 1720863)
(vectors 16 25121)
(vector-slots 8 545849 2832)
(floats 8 496 1920)
(intervals 56 4573 90)
(buffers 976 21)
(heap 1024 48333 3644))
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra
2016-10-09 16:39 bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Olaf Rogalsky
@ 2016-12-09 9:30 ` Stephane Chauveau
2021-02-06 12:08 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Lars Ingebrigtsen
1 sibling, 0 replies; 4+ messages in thread
From: Stephane Chauveau @ 2016-12-09 9:30 UTC (permalink / raw)
To: 24652
Hi,
I have the same problem and I was indeed able to fix it by replacing the
\a by \e\\
Below is my patched gui-backend-get-selection (for 25.5.1) and how I
enable
it in my .emacs.
(unless window-system
(when (string= emacs-version "25.1.1" )
;;
;; The \a used to terminate the OSC52 get-selection reply is causing
;; some issues in the current term/xterm.el implementation (emacs 25.1).
;; so avoid calling (xterm--init-activate-get-selection)
;;
;; Below is patched version of the faulty method
;;
(cl-defmethod gui-backend-get-selection
(type data-type
&context (window-system nil)
;; Only applies to terminals which have it enabled.
((terminal-parameter nil 'xterm--get-selection-PATCHED) (eql t)))
(unless (eq data-type 'STRING)
(error "Unsupported data type %S" data-type))
(let* ((screen (eq (terminal-parameter nil 'terminal-initted)
'terminal-init-screen))
(query (concat "\e]52;" (xterm--selection-char type) ";")))
(with-temp-buffer
(set-buffer-multibyte nil)
(xterm--query
(concat (when screen "\eP") query "?\e\\" (when screen "\e\\"))
(list (cons query (lambda ()
(while (let ((char (read-char)))
(unless (eq char ?\\)
(unless (eq char ?\e)
(insert char))
t))))))
'no-async)
(base64-decode-region (point-min) (point-max))
(decode-coding-region (point-min) (point-max) 'utf-8-unix t))))
;; Call this instead of xterm--init-activate-get-selection
;; to enable our patched implementation of gui-backend-get-selection
(defun xterm--init-activate-get-selection-PATCHED ()
(set-terminal-parameter nil 'xterm--get-selection-PATCHED t)
)
;; a hook that will be called at the end of the xterm initialization
(defun xterm-osc52-hook ()
"Specific configuration when running in xterm"
(message "in xterm-osc52-hook")
(xterm--init-activate-set-selection)
(xterm--init-activate-get-selection-PATCHED)
)
(add-hook 'terminal-init-xterm-hook 'xterm-osc52-hook)
) ;; end of check of emacs version
) ;; end of unless window-system
==============
It probably does not work well with Screen because \e\\ is also the DCS
terminator.
I do not use Screen but looking at the implementation of
gui-backend-set-selection, I suppose that a solution could be to split
the DSC request in two between the \e and the \\.
For instance, the line
(concat (when screen "\eP") query "?\e\\" (when screen "\e\\"))
could become
(concat (when screen "\eP") query "?\e" (when screen "\e\\\eP")
"\\" (when screen "\e\\"))
Remark: Tmux requires a different DCS format and so will not work
properly even though it is identified as Screen.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame
2016-10-09 16:39 bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Olaf Rogalsky
2016-12-09 9:30 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra Stephane Chauveau
@ 2021-02-06 12:08 ` Lars Ingebrigtsen
2021-03-12 1:51 ` Lars Ingebrigtsen
1 sibling, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-06 12:08 UTC (permalink / raw)
To: Olaf Rogalsky; +Cc: 24652
Olaf Rogalsky <olaf.rogalsky@aol.de> writes:
> Possible solution: There is an alternative escape sequence for querying
> the clipoard content:
>
> "\e]52;p;?\e\\"
>
> and the response to this is
>
> "\e]52;p;<base64-encoded-clipboard-content>\e\\"
(I'm going through old bug reports that unfortunately got little response at
the time.)
It looks like this was fixed by this change:
commit f09dc0b81c23046c17574c2ef8d614907455f622
Author: Mattias Engdegård <mattiase@acm.org>
AuthorDate: Sat Aug 3 12:08:27 2019 +0200
Fix XTerm OSC 52 selection retrieval (bug#36879)
When asking XTerm for the selection via OSC 52, use ST as string
terminator in the request to get ST as terminator in the reply,
because BEL is messy to receive in many ways.
Does this work for you in Emacs 28?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame
2021-02-06 12:08 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Lars Ingebrigtsen
@ 2021-03-12 1:51 ` Lars Ingebrigtsen
0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-03-12 1:51 UTC (permalink / raw)
To: Olaf Rogalsky; +Cc: 24652
Lars Ingebrigtsen <larsi@gnus.org> writes:
> It looks like this was fixed by this change:
>
> commit f09dc0b81c23046c17574c2ef8d614907455f622
> Author: Mattias Engdegård <mattiase@acm.org>
> AuthorDate: Sat Aug 3 12:08:27 2019 +0200
>
> Fix XTerm OSC 52 selection retrieval (bug#36879)
>
> When asking XTerm for the selection via OSC 52, use ST as string
> terminator in the request to get ST as terminator in the reply,
> because BEL is messy to receive in many ways.
>
> Does this work for you in Emacs 28?
More information was requested, but no response was given within a
month, so I'm closing this bug report. If the problem still exists,
please respond to this email and we'll reopen the bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-12 1:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-09 16:39 bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Olaf Rogalsky
2016-12-09 9:30 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra Stephane Chauveau
2021-02-06 12:08 ` bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm frame Lars Ingebrigtsen
2021-03-12 1:51 ` Lars Ingebrigtsen
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).