emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master f09dc0b: Fix XTerm OSC 52 selection retrieval (bug#


From: Mattias Engdegård
Subject: [Emacs-diffs] master f09dc0b: Fix XTerm OSC 52 selection retrieval (bug#36879)
Date: Thu, 8 Aug 2019 05:35:34 -0400 (EDT)

branch: master
commit f09dc0b81c23046c17574c2ef8d614907455f622
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    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.
    
    * lisp/term/xterm.el (gui-backend-get-selection):
    Use ST as string terminator in request and reply.
    Use a time-out when reading the reply.
---
 lisp/term/xterm.el | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index c4b0a8f..4b56b2c 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -946,21 +946,31 @@ The title is constructed from `frame-title-format'."
     (type data-type
      &context (window-system nil)
               ;; Only applies to terminals which have it enabled.
-              ((terminal-parameter nil 'xterm--get-selection) (eql t)))
+              ((terminal-parameter nil 'xterm--get-selection) (eql t))
+              ;; Doesn't work in screen; see bug#36879.
+              ((eq (terminal-parameter nil 'terminal-initted)
+                   'terminal-init-screen)
+               (eql nil)))
   (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) ";")))
+  (let ((query (concat "\e]52;" (xterm--selection-char type) ";")))
     (with-temp-buffer
       (set-buffer-multibyte nil)
       (xterm--query
-       (concat (when screen "\eP") query "?\a" (when screen "\e\\"))
-       (list (cons query (lambda ()
-                           (while (let ((char (read-char)))
-                                    (unless (eq char ?\a)
-                                      (insert char)
-                                      t))))))
+       ;; Use ST as query terminator to get ST as reply terminator (bug#36879).
+       (concat query "?\e\\")
+       (list (cons query
+                   (lambda ()
+                     ;; Read data up to the string terminator, ST.
+                     (let (char last)
+                       (while (and (setq char (read-char
+                                               nil nil
+                                               xterm-query-timeout))
+                                   (not (and (eq char ?\\)
+                                             (eq last ?\e))))
+                         (when last
+                           (insert last))
+                         (setq last char))))))
        'no-async)
       (base64-decode-region (point-min) (point-max))
       (decode-coding-region (point-min) (point-max) 'utf-8-unix t))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]