Commit 5d9432e6 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

xterm and OSC 52: Add NEWS entry, and tweak the code

* lisp/term/xterm.el (gui-set-selection) <nil>: Move method definition to
top-level.
(terminal-init-xterm-activate-set-selection): Set a terminal property.
(xterm--set-selection): Use it instead of checking the value of
`terminal-initted'.  Don't use string-bytes.
parent 2b2fd396
...@@ -227,6 +227,9 @@ Unicode standards. ...@@ -227,6 +227,9 @@ Unicode standards.
* Changes in Specialized Modes and Packages in Emacs 25.1 * Changes in Specialized Modes and Packages in Emacs 25.1
** In xterms, killing text now also sets the CLIPBOARD/PRIMARY selection
in the surrounding GUI (using the OSC-52 escape sequence).
** xterm-mouse-mode now supports mouse-tracking (if your xterm supports it). ** xterm-mouse-mode now supports mouse-tracking (if your xterm supports it).
** package.el ** package.el
......
...@@ -40,7 +40,6 @@ The relevant features are: ...@@ -40,7 +40,6 @@ The relevant features are:
reportBackground -- if supported, Xterm reports its background color reportBackground -- if supported, Xterm reports its background color
setSelection -- if supported, Xterm saves yanked text to the X selection" setSelection -- if supported, Xterm saves yanked text to the X selection"
:version "24.1" :version "24.1"
:group 'xterm
:type '(choice (const :tag "No" nil) :type '(choice (const :tag "No" nil)
(const :tag "Check" check) (const :tag "Check" check)
;; NOTE: If you add entries here, make sure to update ;; NOTE: If you add entries here, make sure to update
...@@ -62,7 +61,6 @@ using the OSC 52 sequence. ...@@ -62,7 +61,6 @@ using the OSC 52 sequence.
If you select a region larger than this size, it won't be copied to your system If you select a region larger than this size, it won't be copied to your system
clipboard. Since clipboard data is base 64 encoded, the actual number of clipboard. Since clipboard data is base 64 encoded, the actual number of
string bytes that can be copied is 3/4 of this value." string bytes that can be copied is 3/4 of this value."
:group 'xterm
:type 'integer) :type 'integer)
(defconst xterm-paste-ending-sequence "\e[201~" (defconst xterm-paste-ending-sequence "\e[201~"
...@@ -748,10 +746,11 @@ We run the first FUNCTION whose STRING matches the input events." ...@@ -748,10 +746,11 @@ We run the first FUNCTION whose STRING matches the input events."
(defun terminal-init-xterm-activate-set-selection () (defun terminal-init-xterm-activate-set-selection ()
"Terminal initialization for `gui-set-selection'." "Terminal initialization for `gui-set-selection'."
;; All text terminals are represented by the nil GUI type. We need (set-terminal-parameter nil 'xterm--set-selection t))
;; to detect XTerm again in `xterm--set-selection' using the
;; terminal parameters. ;; FIXME: This defines the gui method for all terminals, even tho it only
(gui-method-define gui-set-selection nil #'xterm--set-selection)) ;; supports a subset of them.
(gui-method-define gui-set-selection nil #'xterm--set-selection)
(defun xterm--set-selection (type data) (defun xterm--set-selection (type data)
"Copy DATA to the X selection using the OSC 52 escape sequence. "Copy DATA to the X selection using the OSC 52 escape sequence.
...@@ -773,12 +772,11 @@ on a bare terminal emulators as well as inside the screen ...@@ -773,12 +772,11 @@ on a bare terminal emulators as well as inside the screen
program. When inside the screen program, this function also program. When inside the screen program, this function also
chops long DCS sequences into multiple smaller ones to avoid chops long DCS sequences into multiple smaller ones to avoid
hitting screen's max DCS length." hitting screen's max DCS length."
(let* ((init-function (terminal-parameter nil 'terminal-initted)) (let* ((screen (eq (terminal-parameter nil 'terminal-initted)
(xterm (eq init-function 'terminal-init-xterm)) 'terminal-init-screen)))
(screen (eq init-function 'terminal-init-screen)))
;; Only do something if the current terminal is actually an XTerm ;; Only do something if the current terminal is actually an XTerm
;; or screen. ;; or screen.
(when (or xterm screen) (when (terminal-parameter nil 'xterm--set-selection)
(let* ((bytes (encode-coding-string data 'utf-8-unix)) (let* ((bytes (encode-coding-string data 'utf-8-unix))
(base-64 (if screen (base-64 (if screen
(replace-regexp-in-string (replace-regexp-in-string
...@@ -786,7 +784,7 @@ hitting screen's max DCS length." ...@@ -786,7 +784,7 @@ hitting screen's max DCS length."
(base64-encode-string bytes) (base64-encode-string bytes)
:fixedcase :literal) :fixedcase :literal)
(base64-encode-string bytes :no-line-break))) (base64-encode-string bytes :no-line-break)))
(length (string-bytes base-64))) (length (length base-64)))
(if (> length xterm-max-cut-length) (if (> length xterm-max-cut-length)
(progn (progn
(warn "Selection too long to send to terminal: %d bytes" length) (warn "Selection too long to send to terminal: %d bytes" length)
...@@ -795,10 +793,10 @@ hitting screen's max DCS length." ...@@ -795,10 +793,10 @@ hitting screen's max DCS length."
(concat (concat
(when screen "\eP") (when screen "\eP")
"\e]52;" "\e]52;"
(cond (pcase type
((eq type 'PRIMARY) "p") ('PRIMARY "p")
((eq type 'CLIPBOARD) "c") ('CLIPBOARD "c")
(t (error "Invalid type %S" type))) (_ (error "Invalid selection type: %S" type)))
";" ";"
base-64 base-64
"\a" "\a"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment