;; 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...
(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
(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)))