From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephane Chauveau Newsgroups: gmane.emacs.bugs Subject: bug#24652: 25.1.50; gui-backend-get-selection does not work in xterm fra Date: Fri, 9 Dec 2016 10:30:58 +0100 Message-ID: <584A79D2.1060202@nvidia.com> References: <87vax1zdce.fsf@aol.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1481301414 21833 195.159.176.226 (9 Dec 2016 16:36:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Dec 2016 16:36:54 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 To: <24652@debbugs.gnu.org> Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 09 17:36:51 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFOAE-00050T-RX for geb-bug-gnu-emacs@m.gmane.org; Fri, 09 Dec 2016 17:36:51 +0100 Original-Received: from localhost ([::1]:47588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFOAJ-0004o0-0X for geb-bug-gnu-emacs@m.gmane.org; Fri, 09 Dec 2016 11:36:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFO5f-0007uV-Dx for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2016 11:32:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cFO5a-0007yX-Cb for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2016 11:32:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49041) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cFO5a-0007yT-9n for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2016 11:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cFO5a-0006Io-4B for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2016 11:32:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87vax1zdce.fsf@aol.de> Resent-From: Stephane Chauveau Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Dec 2016 16:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24652 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24652-submit@debbugs.gnu.org id=B24652.148130107224155 (code B ref 24652); Fri, 09 Dec 2016 16:32:02 +0000 Original-Received: (at 24652) by debbugs.gnu.org; 9 Dec 2016 16:31:12 +0000 Original-Received: from localhost ([127.0.0.1]:36204 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFO4m-0006HW-5e for submit@debbugs.gnu.org; Fri, 09 Dec 2016 11:31:12 -0500 Original-Received: from hqemgate16.nvidia.com ([216.228.121.65]:11330) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFHWJ-0000oc-UE for 24652@debbugs.gnu.org; Fri, 09 Dec 2016 04:31:12 -0500 Original-Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Fri, 09 Dec 2016 01:31:18 -0800 Original-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 Original-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 Original-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 X-Originating-IP: [10.26.11.240] X-ClientProxiedBy: DRUKMAIL102.nvidia.com (10.25.59.20) To UKMAIL101.nvidia.com (10.26.138.13) X-Mailman-Approved-At: Fri, 09 Dec 2016 11:31:11 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:126775 Archived-At: 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.