Subject: bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name

From: Visuwesh <[email-masked]>
Date: Thu, 26 Dec 2024 17:21:15 +0530

[வியாழன் டிசம்பர் 26, 2024] Eli Zaretskii wrote:

>> [...]
>> >> +++ #<buffer dired.el>
>> >> @@ -2089,8 +2089,10 @@
>> >>             `( mouse-face highlight
>> >>                help-echo "mouse-1: revert this buffer"
>> >>                keymap ,(define-keymap
>> >> -                        "<mouse-2>" #'revert-buffer
>> >> -                        "<follow-link>" 'follow-link
>> >> +                        "<mouse-2>" (lambda (_)
>> >> +                                      (interactive "@e")
>> >> +                                      (revert-buffer))
>> >> +                        "<follow-link>" 'mouse-face
>> >
>> > I don't know how to fix the mouse-1 problem in a sensible way either.
>> > Does anyone?
>> >
>> > (And I think in this version the "e" code in `interactive' isn't
>> > significant - but let's first see if we can improve the behavior even
>> > more.)
>> 
>> Indeed, I thought @ had to go with e _always_.
>
> Thanks, so please post a proper patch with a commit log message, so I
> could install it.

Thanks, patch attached.

>From 53cf31f879811389b030d5af7a90aa823ce35bde Mon Sep 17 00:00:00 2001
From: Visuwesh <[email-masked]>
Date: Thu, 26 Dec 2024 17:19:41 +0530
Subject: [PATCH] Ensure Dired window is selected when reverting buffer

* lisp/dired.el (dired--make-directory-clickable): Ensure the
Dired window is selected.  This prevents erroneously reverting a
non-Dired buffer.  (Bug#74700)
---
 lisp/dired.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 9895229694a..9632858703c 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2089,8 +2089,10 @@ dired--make-directory-clickable
            `(mouse-face highlight
              help-echo "mouse-1: re-read this buffer's directory"
              keymap ,(define-keymap
-                       "<mouse-2>" #'revert-buffer
-                       "<follow-link>" 'follow-link
+                       "<mouse-2>" (lambda ()
+                                     (interactive "@")
+                                     (revert-buffer))
+                       "<follow-link>" 'mouse-face
                        "RET" #'revert-buffer))))))))

 (defun dired--get-ellipsis-length ()
--
2.45.2