mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-27 07:37:33 +00:00
Bring back xterm pasting with middle mouse
Problem reported by Jan Synáček. Solution suggested by Stefan Monnier (Bug#23519). * lisp/isearch.el (isearch-mode-map): Add a binding for xterm-paste. (xterm--pasted-text): New decl. (isearch-xterm-paste): New function. * lisp/term/xterm.el (xterm--pasted-text): New function, taken from xterm-paste internals. (xterm-paste): Use it.
This commit is contained in:
parent
5ab083034c
commit
869092c9ed
@ -510,6 +510,7 @@ This is like `describe-bindings', but displays only Isearch keys."
|
||||
;; People expect to be able to paste with the mouse.
|
||||
(define-key map [mouse-2] #'isearch-mouse-2)
|
||||
(define-key map [down-mouse-2] nil)
|
||||
(define-key map [xterm-paste] #'isearch-xterm-paste)
|
||||
|
||||
;; Some bindings you may want to put in your isearch-mode-hook.
|
||||
;; Suggest some alternates...
|
||||
@ -2001,6 +2002,13 @@ is bound to outside of Isearch."
|
||||
(when (functionp binding)
|
||||
(call-interactively binding)))))
|
||||
|
||||
(declare-function xterm--pasted-text "term/xterm" ())
|
||||
|
||||
(defun isearch-xterm-paste ()
|
||||
"Pull terminal paste into search string."
|
||||
(interactive)
|
||||
(isearch-yank-string (xterm--pasted-text)))
|
||||
|
||||
(defun isearch-yank-internal (jumpform)
|
||||
"Pull the text from point to the point reached by JUMPFORM.
|
||||
JUMPFORM is a lambda expression that takes no arguments and returns
|
||||
|
@ -71,28 +71,29 @@ string bytes that can be copied is 3/4 of this value."
|
||||
(defconst xterm-paste-ending-sequence "\e[201~"
|
||||
"Characters send by the terminal to end a bracketed paste.")
|
||||
|
||||
(defun xterm--pasted-text ()
|
||||
"Handle the rest of a terminal paste operation.
|
||||
Return the pasted text as a string."
|
||||
(let ((end-marker-length (length xterm-paste-ending-sequence)))
|
||||
(with-temp-buffer
|
||||
(set-buffer-multibyte nil)
|
||||
(while (not (search-backward xterm-paste-ending-sequence
|
||||
(- (point) end-marker-length) t))
|
||||
(let ((event (read-event nil nil
|
||||
;; Use finite timeout to avoid glomming the
|
||||
;; event onto this-command-keys.
|
||||
most-positive-fixnum)))
|
||||
(when (eql event ?\r)
|
||||
(setf event ?\n))
|
||||
(insert event)))
|
||||
(let ((last-coding-system-used))
|
||||
(decode-coding-region (point-min) (point) (keyboard-coding-system)
|
||||
t)))))
|
||||
|
||||
(defun xterm-paste ()
|
||||
"Handle the start of a terminal paste operation."
|
||||
(interactive)
|
||||
(let* ((end-marker-length (length xterm-paste-ending-sequence))
|
||||
(pasted-text (with-temp-buffer
|
||||
(set-buffer-multibyte nil)
|
||||
(while (not (search-backward
|
||||
xterm-paste-ending-sequence
|
||||
(- (point) end-marker-length) t))
|
||||
(let ((event (read-event
|
||||
nil nil
|
||||
;; Use finite timeout to avoid
|
||||
;; glomming the event onto
|
||||
;; this-command-keys.
|
||||
most-positive-fixnum)))
|
||||
(when (eql event ?\r)
|
||||
(setf event ?\n))
|
||||
(insert event)))
|
||||
(let ((last-coding-system-used))
|
||||
(decode-coding-region
|
||||
(point-min) (point)
|
||||
(keyboard-coding-system) t))))
|
||||
(let* ((pasted-text (xterm--pasted-text))
|
||||
(interprogram-paste-function (lambda () pasted-text)))
|
||||
(yank)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user