Subject: bug#23519: closed (Re: 25.0.93; pasting with the middle mouse button while searching doesn't work)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 22 May 2016 20:50:02 +0000

Your bug report

#23519: 25.0.93; pasting with the middle mouse button while searching doesn't work

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
23519: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23519
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: 25.0.93; pasting with the middle mouse button while searching doesn't work
From: Paul Eggert <[email-masked]>
To: Stefan Monnier <[email-masked]>
Cc: Eli Zaretskii <[email-masked]>, Jan Synacek <[email-masked]>, [email-masked], Kaushal Modi <[email-masked]>
Date: Sun, 22 May 2016 13:49:40 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

> isearch currently doesn't have a binding for
> xterm-paste.  We should add one, just like we added one to global-map.

Thanks, I did that by installing the attached patch into the emacs-25 branch.
From 3ca5d39a25a6f56b5946c85fa9bdc722ee0c9546 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sun, 22 May 2016 13:38:53 -0700
Subject: [PATCH] Bring back xterm pasting with middle mouse
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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.
---
 lisp/isearch.el    |  8 ++++++++
 lisp/term/xterm.el | 39 ++++++++++++++++++++-------------------
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index e4de0b6..7360a0b 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -510,6 +510,7 @@ isearch-mode-map
     ;; 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 @@ isearch-mouse-2
       (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
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index e06423c..19eb37a 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -71,28 +71,29 @@ xterm-max-cut-length
 (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)))
 
-- 
2.5.5

Subject: 25.0.93; pasting with the middle mouse button while searching doesn't work
From: [email-masked] (Jan Synáček)
To: [email-masked]
Date: Thu, 12 May 2016 09:28:03 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

1) emacs -Q -nw <file> (reproduces even without -nw)
2) C-s
3) Have some text selected and click the middle mouse button.

The selected text is pasted into the buffer, not the minibuffer. Here is
what I see in lossage:

C-s [isearch-forward]
ESC [ 2 0 0 ~ [xterm-paste]
r s y n c ESC [ 2 0 1 ~ C-h l [view-lossage]

This is a regression from Emacs 24.5.

In GNU Emacs 25.0.93.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.20.3)
 of 2016-05-03 built on jsynacek-ntb
Windowing system distributor 'Fedora Project', version 11.0.11803000
System Description:	Fedora release 24 (Twenty Four)

Configured using:
 'configure --build=x86_64-redhat-linux-gnu
 --host=x86_64-redhat-linux-gnu --program-prefix=
 --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
 --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
 --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
 --libexecdir=/usr/libexec --localstatedir=/var
 --sharedstatedir=/var/lib --mandir=/usr/share/man
 --infodir=/usr/share/info --with-dbus --with-gif --with-jpeg --with-png
 --with-rsvg --with-tiff --with-xft --with-xpm --with-x-toolkit=gtk3
 --with-gpm=no --with-xwidgets build_alias=x86_64-redhat-linux-gnu
 host_alias=x86_64-redhat-linux-gnu 'CFLAGS=-DMAIL_USE_LOCKF -O2 -g
 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
 -m64 -mtune=generic' LDFLAGS=-Wl,-z,relro
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GCONF GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XWIDGETS

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Haskell

Minor modes in effect:
  global-auto-revert-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  diff-auto-refine-mode: t
  haskell-indentation-mode: t
  erc-notifications-mode: t
  shell-dirtrack-mode: t
  erc-list-mode: t
  erc-menu-mode: t
  erc-autojoin-mode: t
  erc-ring-mode: t
  erc-networks-mode: t
  erc-pcomplete-mode: t
  erc-track-mode: t
  erc-track-minor-mode: t
  erc-match-mode: t
  erc-button-mode: t
  erc-fill-mode: t
  erc-stamp-mode: t
  erc-netsplit-mode: t
  erc-irccontrols-mode: t
  erc-noncommands-mode: t
  erc-move-to-prompt-mode: t
  erc-readonly-mode: t
  recentf-mode: t
  override-global-mode: t
  show-paren-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
<redacted>

Load-path shadows:
/home/jsynacek/.emacs.d/elpa/helm-20160202.843/helm-multi-match hides /home/jsynacek/.emacs.d/elpa/helm-core-20160201.100/helm-multi-match

Features:
(shadow sort mail-extr emacsbug sendmail align linum magit-blame
magit-stash magit-bisect magit-remote magit-commit magit-sequence magit
magit-apply magit-wip magit-log magit-diff smerge-mode magit-core
magit-autorevert autorevert filenotify magit-process magit-popup
magit-mode magit-git crm magit-section magit-utils git-commit log-edit
message idna rfc822 mml mml-sec epg mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev mail-utils
gmm-utils mailheader pcvs-util add-log with-editor async-bytecomp async
tramp-sh server dash hippie-exp vc-git diff-mode sh-script smie
executable derived rpm-spec-mode undo-tree diff misearch multi-isearch
haskell-doc inf-haskell haskell-decl-scan imenu haskell
haskell-completions haskell-load haskell-commands highlight-uses-mode
haskell-modules haskell-sandbox haskell-repl haskell-debug
haskell-interactive-mode haskell-presentation-mode haskell-collapse
haskell-navigate-imports haskell-compile haskell-hoogle haskell-process
haskell-session json map haskell-mode haskell-font-lock
haskell-indentation haskell-string haskell-sort-imports haskell-lexeme
haskell-align-imports haskell-compat haskell-complete-module noutline
outline flymake etags xref project dabbrev haskell-cabal haskell-utils
haskell-customize ido tramp-cache erc-desktop-notifications
notifications dbus winner helm-command helm-elisp helm-eval edebug
helm-mode helm-files rx image-dired tramp tramp-compat tramp-loaddefs
trampver ucs-normalize shell dired-aux ffap helm-buffers helm-elscreen
helm-tags helm-bookmark helm-adaptive helm-info bookmark helm-locate
helm-external helm-net browse-url xml url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
url-parse url-vars mailcap helm-types private erc-list erc-menu erc-join
erc-ring erc-networks erc-pcomplete pcomplete erc-track erc-match
erc-button erc-fill erc-stamp erc-netsplit erc-goodies erc erc-backend
erc-compat format-spec auth-source gnus-util mm-util help-fns mail-prsvr
password-cache thingatpt pp helm-swoop helm-grep helm-regexp helm-plugin
helm-utils compile comint ansi-color ring helm-help helm helm-source
cl-seq eieio-compat eieio eieio-core cl-macs helm-multi-match helm-lib
geiser recentf tree-widget wid-edit edmacro kmacro dired-x dired cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs use-package diminish bind-key easy-mmode advice finder-inf
goto-chg-autoloads undo-tree-autoloads info package epg-config seq
byte-opt gv bytecomp byte-compile cl-extra help-mode easymenu cconv
cl-loaddefs pcase cl-lib paren time-date mule-util tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
dbusbind inotify dynamic-setting system-font-setting font-render-setting
xwidget-internal move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 755528 110849)
 (symbols 48 44955 0)
 (miscs 40 304 1993)
 (strings 32 108614 21710)
 (string-bytes 1 3127236)
 (vectors 16 77284)
 (vector-slots 8 2054196 158754)
 (floats 8 521 702)
 (intervals 56 26890 825)
 (buffers 976 36)
 (heap 1024 67884 3877))

-- 
Jan Synacek
Software Engineer, Red Hat