GNU bug report logs - #24652
25.1.50; gui-backend-get-selection does not work in xterm frame

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Olaf Rogalsky <olaf.rogalsky@HIDDEN>; dated Sun, 9 Oct 2016 18:09:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 24652 <at> debbugs.gnu.org:


Received: (at 24652) by debbugs.gnu.org; 9 Dec 2016 16:31:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Dec 09 11:31:12 2016
Received: from localhost ([127.0.0.1]:36204 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cFO4m-0006HW-5e
	for submit <at> debbugs.gnu.org; Fri, 09 Dec 2016 11:31:12 -0500
Received: from hqemgate16.nvidia.com ([216.228.121.65]:11330)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <schauveau@HIDDEN>) id 1cFHWJ-0000oc-UE
 for 24652 <at> debbugs.gnu.org; Fri, 09 Dec 2016 04:31:12 -0500
Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by
 hqemgate16.nvidia.com
 id <B584a79e60000>; Fri, 09 Dec 2016 01:31:18 -0800
Received: from HQMAIL108.nvidia.com ([172.20.13.39])
 by hqnvupgp07.nvidia.com (PGP Universal service);
 Thu, 08 Dec 2016 13:28:49 -0800
X-PGP-Universal: processed;
 by hqnvupgp07.nvidia.com on Thu, 08 Dec 2016 13:28:49 -0800
Received: from UKMAIL101.nvidia.com (10.26.138.13) by HQMAIL108.nvidia.com
 (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 9 Dec
 2016 09:31:04 +0000
Received: from [10.26.11.240] (10.26.11.240) by UKMAIL101.nvidia.com
 (10.26.138.13) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 9 Dec
 2016 09:31:01 +0000
To: <24652 <at> debbugs.gnu.org>
From: Stephane Chauveau <schauveau@HIDDEN>
Subject: Re: 25.1.50; gui-backend-get-selection does not work in xterm fra
Message-ID: <584A79D2.1060202@HIDDEN>
Date: Fri, 9 Dec 2016 10:30:58 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.2.0
MIME-Version: 1.0
X-Originating-IP: [10.26.11.240]
X-ClientProxiedBy: DRUKMAIL102.nvidia.com (10.25.59.20) To
 UKMAIL101.nvidia.com (10.26.138.13)
Content-Type: text/plain; charset="utf-8"; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -8.0 (--------)
X-Debbugs-Envelope-To: 24652
X-Mailman-Approved-At: Fri, 09 Dec 2016 11:31:11 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -8.0 (--------)

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.








Information forwarded to bug-gnu-emacs@HIDDEN:
bug#24652; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 9 Oct 2016 18:08:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 09 14:08:27 2016
Received: from localhost ([127.0.0.1]:50214 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1btIWR-0000TB-0M
	for submit <at> debbugs.gnu.org; Sun, 09 Oct 2016 14:08:27 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54046)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <olaf.rogalsky@HIDDEN>) id 1btHWk-0007Jv-6u
 for submit <at> debbugs.gnu.org; Sun, 09 Oct 2016 13:04:42 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <olaf.rogalsky@HIDDEN>) id 1btHWd-0000pu-HU
 for submit <at> debbugs.gnu.org; Sun, 09 Oct 2016 13:04:37 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM,
 T_DKIM_INVALID autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:33730)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <olaf.rogalsky@HIDDEN>) id 1btHWd-0000pe-EN
 for submit <at> debbugs.gnu.org; Sun, 09 Oct 2016 13:04:35 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45010)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <olaf.rogalsky@HIDDEN>) id 1btHWa-0007Ja-Hz
 for bug-gnu-emacs@HIDDEN; Sun, 09 Oct 2016 13:04:34 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <olaf.rogalsky@HIDDEN>) id 1btHWW-0000nb-6B
 for bug-gnu-emacs@HIDDEN; Sun, 09 Oct 2016 13:04:31 -0400
Received: from omr-m013e.mx.aol.com ([204.29.186.14]:56252)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <olaf.rogalsky@HIDDEN>) id 1btHWV-0000nB-V0
 for bug-gnu-emacs@HIDDEN; Sun, 09 Oct 2016 13:04:28 -0400
Received: from mtaout-aan01.mx.aol.com (mtaout-aan01.mx.aol.com [172.27.19.77])
 by omr-m013e.mx.aol.com (Outbound Mail Relay) with ESMTP id F21DC3800081
 for <bug-gnu-emacs@HIDDEN>; Sun,  9 Oct 2016 12:42:14 -0400 (EDT)
Received: from blaubaer (dslb-084-063-095-023.084.063.pools.vodafone-ip.de
 [84.63.95.23])
 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
 (No client certificate requested)
 by mtaout-aan01.mx.aol.com (MUA/Third Party Client Interface) with ESMTPSA id
 4CA663800008D
 for <bug-gnu-emacs@HIDDEN>; Sun,  9 Oct 2016 12:42:13 -0400 (EDT)
From: Olaf Rogalsky <olaf.rogalsky@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 25.1.50; gui-backend-get-selection does not work in xterm frame
Date: Sun, 09 Oct 2016 18:39:13 +0200
Message-ID: <87vax1zdce.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
x-aol-global-disposition: G
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mx.aol.de;
 s=20150623; t=1476031334;
 bh=5+cld8c5FQP1nWd+9qdlGkF3CIQhC/VDG5UPGGz8+Z0=;
 h=From:To:Subject:Message-ID:Date:MIME-Version:Content-Type;
 b=ddQb/2WsHshVeoX+AWWxiP9ZXfmDckma4aossen3YPVMZShWARPWTocpRa9s2Mei9
 zybfuaHGiOINiT8zexhSthArPhhLOlQwGjsg0/hEFw/tY4uBjcOWfs8r3UyYgiGEqA
 T2T/dyjce1C6nCyEZgILV6qxDzo/Naw6+dsXQazM=
x-aol-sid: 3039ac1b134d57fa736551c5
X-AOL-IP: 84.63.95.23
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.4 (----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sun, 09 Oct 2016 14:08:25 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.4 (----)

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




Acknowledgement sent to Olaf Rogalsky <olaf.rogalsky@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#24652; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.