Fix bugs in selection data manipulation code
* eat.el (eat--t-term): Put a vector of length 8 (instead of 10) in 'cut-buffers' slot. * eat.el (eat--t-manipulate-selection): Don't process the targets '8' and '9', since they are not in the protocol. Return correct list of queried targets to the client. Make sure base64 encoded data doesn't contain line breaks. * eat.el (eat--t-handle-output): Tolerate invalid targets in OSC 52 (manipulate selection data). * eat.el (eat--manipulate-kill-ring): Handle 'nil' correctly.
This commit is contained in:
parent
0586a84e52
commit
6cf6db86c9
2 changed files with 27 additions and 22 deletions
|
@ -13,7 +13,7 @@ It has many features that other Emacs terminal emulator still don't
|
||||||
have, for example complete mouse support, shell integration, etc.
|
have, for example complete mouse support, shell integration, etc.
|
||||||
|
|
||||||
It flickers less than other Emacs terminal emulator, so you get more
|
It flickers less than other Emacs terminal emulator, so you get more
|
||||||
performance and a smooth experience.
|
performance and a smoother experience.
|
||||||
|
|
||||||
To get the most out of Eat, you should also setup shell integration.
|
To get the most out of Eat, you should also setup shell integration.
|
||||||
|
|
||||||
|
|
47
eat.el
47
eat.el
|
@ -976,7 +976,7 @@ Nil when not in alternative display mode.")
|
||||||
(mouse-encoding nil :documentation "Current mouse event encoding.")
|
(mouse-encoding nil :documentation "Current mouse event encoding.")
|
||||||
(focus-event-mode nil :documentation "Whether to send focus event.")
|
(focus-event-mode nil :documentation "Whether to send focus event.")
|
||||||
(cut-buffers
|
(cut-buffers
|
||||||
(1value (make-vector 10 nil))
|
(1value (make-vector 8 nil))
|
||||||
:documentation "Cut buffers.")
|
:documentation "Cut buffers.")
|
||||||
;; NOTE: Change the default value of parameters when changing this.
|
;; NOTE: Change the default value of parameters when changing this.
|
||||||
(bold-face 'eat-term-bold :documentation "Face for bold text.")
|
(bold-face 'eat-term-bold :documentation "Face for bold text.")
|
||||||
|
@ -2604,8 +2604,8 @@ output."
|
||||||
"Set and send current selection.
|
"Set and send current selection.
|
||||||
|
|
||||||
TARGETS is a string containing zero or more characters from the set
|
TARGETS is a string containing zero or more characters from the set
|
||||||
`c', `p', `q', `s', `0', `1', `2', `3', `4', `5', `6', `7', `8', `9'.
|
`c', `p', `q', `s', `0', `1', `2', `3', `4', `5', `6', and `7'. DATA
|
||||||
DATA is the selection data encoded in base64."
|
is the selection data encoded in base64."
|
||||||
(when (string-empty-p targets)
|
(when (string-empty-p targets)
|
||||||
(setq targets "s0"))
|
(setq targets "s0"))
|
||||||
(if (string= data "?")
|
(if (string= data "?")
|
||||||
|
@ -2614,8 +2614,16 @@ DATA is the selection data encoded in base64."
|
||||||
(funcall
|
(funcall
|
||||||
(eat--t-term-input-fn eat--t-term) eat--t-term
|
(eat--t-term-input-fn eat--t-term) eat--t-term
|
||||||
(let ((str nil)
|
(let ((str nil)
|
||||||
(source nil)
|
|
||||||
(n 0))
|
(n 0))
|
||||||
|
;; Remove invalid and duplicate targets from TARGETS before
|
||||||
|
;; processing it and sending it back.
|
||||||
|
(setq targets
|
||||||
|
(apply #'string
|
||||||
|
(cl-delete-duplicates
|
||||||
|
(cl-delete-if-not
|
||||||
|
(lambda (c) (or (<= ?0 c ?7)
|
||||||
|
(memq c '(?c ?p ?q ?s))))
|
||||||
|
(string-to-list targets)))))
|
||||||
(while (and (not str) (< n (length targets)))
|
(while (and (not str) (< n (length targets)))
|
||||||
(setq
|
(setq
|
||||||
str
|
str
|
||||||
|
@ -2640,22 +2648,17 @@ DATA is the selection data encoded in base64."
|
||||||
eat--t-term :select t))
|
eat--t-term :select t))
|
||||||
;; 0 to 9 targets are handled by us, and always work.
|
;; 0 to 9 targets are handled by us, and always work.
|
||||||
((and (pred (<= ?0))
|
((and (pred (<= ?0))
|
||||||
(pred (>= ?9))
|
(pred (>= ?7))
|
||||||
i)
|
i)
|
||||||
(aref (eat--t-term-cut-buffers eat--t-term)
|
(aref (eat--t-term-cut-buffers eat--t-term)
|
||||||
(- i ?0)))))
|
(- i ?0)))))
|
||||||
;; If we got a string to send, record the source to inform
|
|
||||||
;; the client.
|
|
||||||
(when str
|
|
||||||
(setq source (string (aref targets n))))
|
|
||||||
(cl-incf n))
|
(cl-incf n))
|
||||||
;; No string to send, so send an empty string and an empty
|
;; No string to send, so send an empty string.
|
||||||
;; target string meaning that we don't have any answer.
|
(unless str (setq str ""))
|
||||||
(unless str
|
(format "\e]52;%s;%s\e\\" targets
|
||||||
(setq str "")
|
(base64-encode-string (encode-coding-string
|
||||||
(setq source ""))
|
str locale-coding-system)
|
||||||
(format "\e]52;%s;%s\e\\" source
|
'no-line-break))))
|
||||||
(base64-encode-string str))))
|
|
||||||
;; The client is requesting to set clipboard content, let's try to
|
;; The client is requesting to set clipboard content, let's try to
|
||||||
;; fulfill the request.
|
;; fulfill the request.
|
||||||
(let ((str (ignore-errors
|
(let ((str (ignore-errors
|
||||||
|
@ -2677,9 +2680,9 @@ DATA is the selection data encoded in base64."
|
||||||
(?s
|
(?s
|
||||||
(funcall (eat--t-term-manipulate-selection-fn eat--t-term)
|
(funcall (eat--t-term-manipulate-selection-fn eat--t-term)
|
||||||
eat--t-term :select str))
|
eat--t-term :select str))
|
||||||
;; 0 to 9 targets are handled by us, and always work.
|
;; 0 to 7 targets are handled by us, and always work.
|
||||||
((and (pred (<= ?0))
|
((and (pred (<= ?0))
|
||||||
(pred (>= ?9))
|
(pred (>= ?7))
|
||||||
i)
|
i)
|
||||||
(aset (eat--t-term-cut-buffers eat--t-term) (- i ?0)
|
(aset (eat--t-term-cut-buffers eat--t-term) (- i ?0)
|
||||||
str)))))))
|
str)))))))
|
||||||
|
@ -3206,8 +3209,7 @@ DATA is the selection data encoded in base64."
|
||||||
;; OSC 5 2 ; <t> ; <s> ST.
|
;; OSC 5 2 ; <t> ; <s> ST.
|
||||||
((rx string-start "52;"
|
((rx string-start "52;"
|
||||||
(let targets
|
(let targets
|
||||||
(zero-or-more (any ?c ?p ?q ?s
|
(zero-or-more (not ?\;)))
|
||||||
(?0 . ?9))))
|
|
||||||
?\; (let data (zero-or-more anything))
|
?\; (let data (zero-or-more anything))
|
||||||
string-end)
|
string-end)
|
||||||
(eat--t-manipulate-selection
|
(eat--t-manipulate-selection
|
||||||
|
@ -3578,7 +3580,7 @@ should not change point and buffer restriction.
|
||||||
|
|
||||||
To set it, use (`setf' (`eat-term-ring-bell-function' TERMINAL)
|
To set it, use (`setf' (`eat-term-ring-bell-function' TERMINAL)
|
||||||
FUNCTION), where FUNCTION is the function to ring the bell."
|
FUNCTION), where FUNCTION is the function to ring the bell."
|
||||||
(eat--t-term-manipulate-selection-fn terminal))
|
(eat--t-term-bell-fn terminal))
|
||||||
|
|
||||||
(gv-define-setter eat-term-ring-bell-function (function terminal)
|
(gv-define-setter eat-term-ring-bell-function (function terminal)
|
||||||
`(setf (eat--t-term-bell-fn ,terminal) ,function))
|
`(setf (eat--t-term-bell-fn ,terminal) ,function))
|
||||||
|
@ -4560,6 +4562,9 @@ selection, or nil if none."
|
||||||
(when eat-enable-yank-to-terminal
|
(when eat-enable-yank-to-terminal
|
||||||
(ignore-error error
|
(ignore-error error
|
||||||
(current-kill 0 'do-not-move))))
|
(current-kill 0 'do-not-move))))
|
||||||
|
('nil
|
||||||
|
(when eat-enable-kill-from-terminal
|
||||||
|
(kill-new "")))
|
||||||
((and (pred stringp) str)
|
((and (pred stringp) str)
|
||||||
(when eat-enable-kill-from-terminal
|
(when eat-enable-kill-from-terminal
|
||||||
(kill-new str))))))
|
(kill-new str))))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue