Subject: Re: bug#56198: Request to delete window with mouse event

From: Visuwesh <[email-masked]>
Date: Sun, 26 Jun 2022 21:10:35 +0530

[ஞாயிறு ஜூன் 26, 2022] Lars Ingebrigtsen wrote:

> Visuwesh <[email-masked]> writes:
>
>> I was kind of sloppy with that.  If you move the mouse to another
>> window, then it won't delete it.  But you're right, it should also bail
>> out if the end position wasn't the modeline so something like this
>> maybe?
>
> Thanks; that works well for me, too, so I've now pushed your patch to
> Emacs 29.

How about doing this as well?  (On hindsight, I should have included
this in the other mail as well but oh well)

>From 6dc4f29dbfcf6c40ef0808bf04987d918df98972 Mon Sep 17 00:00:00 2001
From: Visuwesh <[email-masked]>
Date: Sun, 26 Jun 2022 21:10:09 +0530
Subject: [PATCH] Make <mouse-2> in mode line more careful as well

* lisp/mouse.el (mouse-delete-other-windows): Only delete other
windows if the user didn't move the cursor off the mode-line. (bug#56198)
---
 lisp/mouse.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 82c8a14693..f7ada4f1ec 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -681,10 +681,13 @@ tear-off-window
     (switch-to-buffer buf)
     (delete-window window)))
 
-(defun mouse-delete-other-windows ()
+(defun mouse-delete-other-windows (click)
   "Delete all windows except the one you click on."
-  (interactive "@")
-  (delete-other-windows))
+  (interactive "e")
+  (when (and (eq (posn-area (event-end click)) 'mode-line)
+             (eq (posn-window (event-start click))
+                 (posn-window (event-end click))))
+    (delete-other-windows (posn-window (event-start click)))))
 
 (defun mouse-split-window-vertically (click)
   "Select Emacs window mouse is on, then split it vertically in half.
-- 
2.35.1