Subject: bug#23007: 24.5; buggy interactive search with middle click

From: Alex <[email-masked]>
Date: Mon, 29 May 2017 13:56:25 -0600

tags 23007 patch
quit

Vincent Lefevre <[email-masked]> writes:

> 1. Start Emacs with its own UI under X Window.
>
> 2. Type: M-<
>    Here the cursor is at the beginning of the buffer, which contains
>    some text.
>
> 3. In some other window, select some text (e.g. the letter "n").
>
> 4. Type: C-s
>    This starts the interactive search. It says:
>    I-search:
>
> 5. Click with the middle button near the bottom of the window.
>    This pastes the text at the end of the buffer.
>
> 6. Type: C-_
>    This removes the pasted text and moves the cursor back at the
>    beginning of the buffer.
>
> 7. Type: C-s
>    This starts the interactive search again. But this time, it says:
>    I-search:  [No previous search string]
>
> 8. Type: e
>    This searches for "e". All the occurrences of "e" are highlighted.
>
> 9. Type: <down>
>    This is no longer the interactive search, but the occurrences of "e"
>    are still highlighted.
>
> Typing other letters brings back to the interactive search.

This is because clicking the middle button during isearch calls
isearch-mouse-2, which calls the usual mouse-yank-primary, which calls
isearch-done to finish isearch. Problem is, it let-binds
overriding-terminal-local-map around this call, which counteracts
isearch-done setting this variable to nil. The end result is having quit
isearch, but with the overriding map still in place.

I have attached a simple patch below. Eli, if it's satisfactory, would
you commit it for me?

TIA

>From 33251d03d1d2298b29ae2a35ecccb8ae41e8bdd4 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <[email-masked]>
Date: Mon, 29 May 2017 13:43:23 -0600
Subject: [PATCH] Limit scope of local overriding-terminal-local-map

The function `binding' may call isearch-done, which globally sets
overriding-terminal-local-map to nil (Bug #23007).
* lisp/isearch.el (isearch-mouse-2): Don't bind
overriding-terminal-local-map around the call to `binding'.
---
 lisp/isearch.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index c34739d638..992794e43a 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -2036,14 +2036,15 @@ isearch-mouse-2
 Otherwise invoke whatever the calling mouse-2 command sequence
 is bound to outside of Isearch."
   (interactive "e")
-  (let* ((w (posn-window (event-start click)))
-	 (overriding-terminal-local-map nil)
-	 (binding (key-binding (this-command-keys-vector) t)))
+  (let ((w (posn-window (event-start click)))
+        binding)
     (if (and (window-minibuffer-p w)
-	     (not (minibuffer-window-active-p w))) ; in echo area
-	(isearch-yank-x-selection)
+             (not (minibuffer-window-active-p w))) ; in echo area
+        (isearch-yank-x-selection)
+      (let ((overriding-terminal-local-map nil))
+        (setq binding (key-binding (this-command-keys-vector) t)))
       (when (functionp binding)
-	(call-interactively binding)))))
+        (call-interactively binding)))))
 
 (declare-function xterm--pasted-text "term/xterm" ())
 
-- 
2.11.0