diff options
| author | Mattias EngdegÄrd | 2019-08-03 12:08:27 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-08-08 10:30:09 +0200 |
| commit | f09dc0b81c23046c17574c2ef8d614907455f622 (patch) | |
| tree | 9031523c4b0a280e9eedb5e4518ad71dbd5f3066 | |
| parent | d5622eb6fff94714c5d5a64c98c5e02bc1be478c (diff) | |
| download | emacs-f09dc0b81c23046c17574c2ef8d614907455f622.tar.gz emacs-f09dc0b81c23046c17574c2ef8d614907455f622.zip | |
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.
| -rw-r--r-- | lisp/term/xterm.el | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index c4b0a8fb6e6..4b56b2ce4a1 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el | |||
| @@ -946,21 +946,31 @@ The title is constructed from `frame-title-format'." | |||
| 946 | (type data-type | 946 | (type data-type |
| 947 | &context (window-system nil) | 947 | &context (window-system nil) |
| 948 | ;; Only applies to terminals which have it enabled. | 948 | ;; Only applies to terminals which have it enabled. |
| 949 | ((terminal-parameter nil 'xterm--get-selection) (eql t))) | 949 | ((terminal-parameter nil 'xterm--get-selection) (eql t)) |
| 950 | ;; Doesn't work in screen; see bug#36879. | ||
| 951 | ((eq (terminal-parameter nil 'terminal-initted) | ||
| 952 | 'terminal-init-screen) | ||
| 953 | (eql nil))) | ||
| 950 | (unless (eq data-type 'STRING) | 954 | (unless (eq data-type 'STRING) |
| 951 | (error "Unsupported data type %S" data-type)) | 955 | (error "Unsupported data type %S" data-type)) |
| 952 | (let* ((screen (eq (terminal-parameter nil 'terminal-initted) | 956 | (let ((query (concat "\e]52;" (xterm--selection-char type) ";"))) |
| 953 | 'terminal-init-screen)) | ||
| 954 | (query (concat "\e]52;" (xterm--selection-char type) ";"))) | ||
| 955 | (with-temp-buffer | 957 | (with-temp-buffer |
| 956 | (set-buffer-multibyte nil) | 958 | (set-buffer-multibyte nil) |
| 957 | (xterm--query | 959 | (xterm--query |
| 958 | (concat (when screen "\eP") query "?\a" (when screen "\e\\")) | 960 | ;; Use ST as query terminator to get ST as reply terminator (bug#36879). |
| 959 | (list (cons query (lambda () | 961 | (concat query "?\e\\") |
| 960 | (while (let ((char (read-char))) | 962 | (list (cons query |
| 961 | (unless (eq char ?\a) | 963 | (lambda () |
| 962 | (insert char) | 964 | ;; Read data up to the string terminator, ST. |
| 963 | t)))))) | 965 | (let (char last) |
| 966 | (while (and (setq char (read-char | ||
| 967 | nil nil | ||
| 968 | xterm-query-timeout)) | ||
| 969 | (not (and (eq char ?\\) | ||
| 970 | (eq last ?\e)))) | ||
| 971 | (when last | ||
| 972 | (insert last)) | ||
| 973 | (setq last char)))))) | ||
| 964 | 'no-async) | 974 | 'no-async) |
| 965 | (base64-decode-region (point-min) (point-max)) | 975 | (base64-decode-region (point-min) (point-max)) |
| 966 | (decode-coding-region (point-min) (point-max) 'utf-8-unix t)))) | 976 | (decode-coding-region (point-min) (point-max) 'utf-8-unix t)))) |