* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
@ 2024-12-05 6:12 Visuwesh
2024-12-05 7:02 ` Eli Zaretskii
0 siblings, 1 reply; 9+ messages in thread
From: Visuwesh @ 2024-12-05 6:12 UTC (permalink / raw)
To: 74700
[-- Attachment #1: Type: text/plain, Size: 882 bytes --]
Tags: patch
Attached patch makes it possible to revert the current Dired buffer by
clicking on the last segment of the directory line. With the patch
applied,
/home/viz/lib/ports/emacs:
clicking on 'emacs' now reverts the buffer that shows ~/lib/ports/emacs.
Previously, it did nothing. This makes it possible to update the Dired
listing without needing to use the keyboard.
In GNU Emacs 31.0.50 (build 25, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.18.2, Xaw scroll bars) of 2024-11-10 built on astatine
Repository revision: 1704fa4fb4164a15c7e258b922dbba190811d92d
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101014
System Description: Debian GNU/Linux trixie/sid
Configured using:
'configure --with-sound=alsa --with-x-toolkit=lucid --without-xaw3d
--without-gconf --without-libsystemd --with-cairo CFLAGS=-g3'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Revert-Dired-buffer-when-clicking-on-last-segment-of.patch --]
[-- Type: text/patch, Size: 1863 bytes --]
From 83da5ad8ef930ed6d093b6b5dec2322599fac763 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Thu, 5 Dec 2024 11:40:02 +0530
Subject: [PATCH] Revert Dired buffer when clicking on last segment of
directory name
* lisp/dired.el (dired--make-directory-clickable): Make clicking
on the last segment of the directory line revert the Dired
buffer.
* etc/NEWS: Announce the change.
---
etc/NEWS | 5 +++++
lisp/dired.el | 11 ++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index e63132efeda..e35f007dbe1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -587,6 +587,11 @@ Without 'dired-hide-details-hide-absolute-location':
/absolute/path/to/my/important/project: (100 GiB available)
+---
+*** Clicking on last segment of directory reverts buffer
+When 'dired-make-directory-clickable' is non-nil, clicking on the last
+segment of the directory name now reverts the Dired buffer.
+
** Grep
+++
diff --git a/lisp/dired.el b/lisp/dired.el
index f79a2220bea..4e300879f88 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2082,7 +2082,16 @@ dired--make-directory-clickable
"<mouse-2>" click
"<follow-link>" 'mouse-face
"RET" click))))
- (setq segment-start (point)))))))
+ (setq segment-start (point)))
+ (when (search-forward ":" bound t)
+ (add-text-properties
+ segment-start (1- (point))
+ `( mouse-face highlight
+ help-echo "mouse-1: revert this buffer"
+ keymap ,(define-keymap
+ "<mouse-2>" #'revert-buffer
+ "<follow-link>" 'follow-link
+ "RET" #'revert-buffer))))))))
(defun dired--get-ellipsis-length ()
"Return length of ellipsis."
--
2.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 6:12 bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name Visuwesh
@ 2024-12-05 7:02 ` Eli Zaretskii
2024-12-05 8:26 ` Visuwesh
0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2024-12-05 7:02 UTC (permalink / raw)
To: Visuwesh; +Cc: 74700
> From: Visuwesh <visuweshm@gmail.com>
> Date: Thu, 05 Dec 2024 11:42:08 +0530
>
> Attached patch makes it possible to revert the current Dired buffer by
> clicking on the last segment of the directory line. With the patch
> applied,
>
> /home/viz/lib/ports/emacs:
>
> clicking on 'emacs' now reverts the buffer that shows ~/lib/ports/emacs.
> Previously, it did nothing. This makes it possible to update the Dired
> listing without needing to use the keyboard.
Thanks, a few comments below.
> +---
> +*** Clicking on last segment of directory reverts buffer
> +When 'dired-make-directory-clickable' is non-nil, clicking on the last
> +segment of the directory name now reverts the Dired buffer.
We don't call these "segments", we call them "components". And since
you are talking about the last one, you could also say "base name of
the directory".
> + (when (search-forward ":" bound t)
> + (add-text-properties
> + segment-start (1- (point))
> + `( mouse-face highlight
^^
We don't leave whitespace after the opening parenthesis.
> + help-echo "mouse-1: revert this buffer"
I think the help-echo should say something more similar to what we say
for the other components of the directory shown in the header line.
Something like "re-read this buffer's directory".
> + keymap ,(define-keymap
> + "<mouse-2>" #'revert-buffer
> + "<follow-link>" 'follow-link
> + "RET" #'revert-buffer))))))))
Should we perhaps call dired-revert directly?
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 7:02 ` Eli Zaretskii
@ 2024-12-05 8:26 ` Visuwesh
2024-12-05 8:41 ` Eli Zaretskii
2024-12-12 10:31 ` Eli Zaretskii
0 siblings, 2 replies; 9+ messages in thread
From: Visuwesh @ 2024-12-05 8:26 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 74700
[-- Attachment #1: Type: text/plain, Size: 2192 bytes --]
[வியாழன் டிசம்பர் 05, 2024] Eli Zaretskii wrote:
>> From: Visuwesh <visuweshm@gmail.com>
>> Date: Thu, 05 Dec 2024 11:42:08 +0530
>>
>> Attached patch makes it possible to revert the current Dired buffer by
>> clicking on the last segment of the directory line. With the patch
>> applied,
>>
>> /home/viz/lib/ports/emacs:
>>
>> clicking on 'emacs' now reverts the buffer that shows ~/lib/ports/emacs.
>> Previously, it did nothing. This makes it possible to update the Dired
>> listing without needing to use the keyboard.
>
> Thanks, a few comments below.
>
>> +---
>> +*** Clicking on last segment of directory reverts buffer
>> +When 'dired-make-directory-clickable' is non-nil, clicking on the last
>> +segment of the directory name now reverts the Dired buffer.
>
> We don't call these "segments", we call them "components". And since
> you are talking about the last one, you could also say "base name of
> the directory".
I've changed it to base name.
>> + (when (search-forward ":" bound t)
>> + (add-text-properties
>> + segment-start (1- (point))
>> + `( mouse-face highlight
> ^^
> We don't leave whitespace after the opening parenthesis.
I removed the whitespace. But isn't that way to make lists such as
( 1
2
3)
aligned without manual intervention? It is used in the list above too.
>> + help-echo "mouse-1: revert this buffer"
>
> I think the help-echo should say something more similar to what we say
> for the other components of the directory shown in the header line.
> Something like "re-read this buffer's directory".
Now done.
>> + keymap ,(define-keymap
>> + "<mouse-2>" #'revert-buffer
>> + "<follow-link>" 'follow-link
>> + "RET" #'revert-buffer))))))))
>
> Should we perhaps call dired-revert directly?
revert-buffer-function is set to dired-revert by dired. If someone has
changed it, for some reason, using revert-buffer would heed their
customisation. So I've left it as revert-buffer.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Revert-Dired-buffer-when-clicking-on-basename-of-dir.patch --]
[-- Type: text/x-diff, Size: 1850 bytes --]
From 642338b96d5f39f3b11285fff319f744c1a07164 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Thu, 5 Dec 2024 11:40:02 +0530
Subject: [PATCH] Revert Dired buffer when clicking on basename of directory
* lisp/dired.el (dired--make-directory-clickable): Make clicking
on basename of the directory revert the Dired buffer.
* etc/NEWS: Announce the change. (Bug#74700)
---
etc/NEWS | 5 +++++
lisp/dired.el | 11 ++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index e63132efeda..1ed529b0792 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -587,6 +587,11 @@ Without 'dired-hide-details-hide-absolute-location':
/absolute/path/to/my/important/project: (100 GiB available)
+---
+*** Clicking on base name of directory reverts buffer.
+When 'dired-make-directory-clickable' is non-nil, clicking on the base
+name of the directory now reverts the Dired buffer.
+
** Grep
+++
diff --git a/lisp/dired.el b/lisp/dired.el
index f79a2220bea..9895229694a 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2082,7 +2082,16 @@ dired--make-directory-clickable
"<mouse-2>" click
"<follow-link>" 'mouse-face
"RET" click))))
- (setq segment-start (point)))))))
+ (setq segment-start (point)))
+ (when (search-forward ":" bound t)
+ (add-text-properties
+ segment-start (1- (point))
+ `(mouse-face highlight
+ help-echo "mouse-1: re-read this buffer's directory"
+ keymap ,(define-keymap
+ "<mouse-2>" #'revert-buffer
+ "<follow-link>" 'follow-link
+ "RET" #'revert-buffer))))))))
(defun dired--get-ellipsis-length ()
"Return length of ellipsis."
--
2.45.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 8:26 ` Visuwesh
@ 2024-12-05 8:41 ` Eli Zaretskii
2024-12-05 9:02 ` Visuwesh
2024-12-12 10:31 ` Eli Zaretskii
1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2024-12-05 8:41 UTC (permalink / raw)
To: Visuwesh; +Cc: 74700
> From: Visuwesh <visuweshm@gmail.com>
> Cc: 74700@debbugs.gnu.org
> Date: Thu, 05 Dec 2024 13:56:44 +0530
>
> >> + (when (search-forward ":" bound t)
> >> + (add-text-properties
> >> + segment-start (1- (point))
> >> + `( mouse-face highlight
> > ^^
> > We don't leave whitespace after the opening parenthesis.
>
> I removed the whitespace. But isn't that way to make lists such as
>
> ( 1
> 2
> 3)
>
> aligned without manual intervention?
Typing something like
(setq foo (1
2
3)
aligns the members for me. So I don't think I understand what you are
saying here.
> >> + keymap ,(define-keymap
> >> + "<mouse-2>" #'revert-buffer
> >> + "<follow-link>" 'follow-link
> >> + "RET" #'revert-buffer))))))))
> >
> > Should we perhaps call dired-revert directly?
>
> revert-buffer-function is set to dired-revert by dired. If someone has
> changed it, for some reason, using revert-buffer would heed their
> customisation. So I've left it as revert-buffer.
That's exactly what I wonder: should we call whatever customized value
of revert-buffer-function? It could be something completely
different, not a function that refreshes the directory listing.
What do people think about this?
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 8:41 ` Eli Zaretskii
@ 2024-12-05 9:02 ` Visuwesh
2024-12-05 9:24 ` Eli Zaretskii
2024-12-05 17:56 ` Juri Linkov
0 siblings, 2 replies; 9+ messages in thread
From: Visuwesh @ 2024-12-05 9:02 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 74700
[வியாழன் டிசம்பர் 05, 2024] Eli Zaretskii wrote:
>> I removed the whitespace. But isn't that way to make lists such as
>>
>> ( 1
>> 2
>> 3)
>>
>> aligned without manual intervention?
>
> Typing something like
>
> (setq foo (1
> 2
> 3)
>
> aligns the members for me. So I don't think I understand what you are
> saying here.
Try to align
(setq foo '(1 2
3))
instead. 3 would end up aligning at 2 instead of 1. Adding a space
after ( prevents this.
>> >> + keymap ,(define-keymap
>> >> + "<mouse-2>" #'revert-buffer
>> >> + "<follow-link>" 'follow-link
>> >> + "RET" #'revert-buffer))))))))
>> >
>> > Should we perhaps call dired-revert directly?
>>
>> revert-buffer-function is set to dired-revert by dired. If someone has
>> changed it, for some reason, using revert-buffer would heed their
>> customisation. So I've left it as revert-buffer.
>
> That's exactly what I wonder: should we call whatever customized value
> of revert-buffer-function? It could be something completely
> different, not a function that refreshes the directory listing.
I was about to point out find-dired's value of revert-buffer-function
which is different than dired-revert but as the directory is inserted as
/home/user/lib/ports/emacs/
always, the change wouldn't affect the 'emacs' part. We could "fix"
this as
diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index 13c8bf722c3..12fc64c2151 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -281,7 +281,7 @@ find-dired-with-command
(setq buffer-read-only nil)
;; Subdir headlerline must come first because the first marker in
;; subdir-alist points there.
- (insert " " dir ":\n")
+ (insert " " (directory-file-name dir) ":\n")
(when dired-make-directory-clickable
(dired--make-directory-clickable))
;; Make second line a ``find'' line in analogy to the ``total'' or
to make it insert
/home/user/lib/ports/emacs
but I think clicking on 'emacs' to open the Dired buffer for
~/lib/ports/emacs is also a good option.
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 9:02 ` Visuwesh
@ 2024-12-05 9:24 ` Eli Zaretskii
2024-12-05 10:42 ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-05 17:56 ` Juri Linkov
1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2024-12-05 9:24 UTC (permalink / raw)
To: Visuwesh; +Cc: 74700
> From: Visuwesh <visuweshm@gmail.com>
> Cc: 74700@debbugs.gnu.org
> Date: Thu, 05 Dec 2024 14:32:18 +0530
>
> [வியாழன் டிசம்பர் 05, 2024] Eli Zaretskii wrote:
>
> >> I removed the whitespace. But isn't that way to make lists such as
> >>
> >> ( 1
> >> 2
> >> 3)
> >>
> >> aligned without manual intervention?
> >
> > Typing something like
> >
> > (setq foo (1
> > 2
> > 3)
> >
> > aligns the members for me. So I don't think I understand what you are
> > saying here.
>
> Try to align
>
> (setq foo '(1 2
> 3))
>
> instead. 3 would end up aligning at 2 instead of 1.
Yes, and why is that a problem? This is the standard Lisp indentation
in Emacs. It makes it easy to find the end of the sexps.
> Adding a space after ( prevents this.
I'm not sure I understand why overriding the standard indentation
would be a good idea.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 9:24 ` Eli Zaretskii
@ 2024-12-05 10:42 ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 9+ messages in thread
From: Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-05 10:42 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 74700, Visuwesh
On Thu, 05 Dec 2024 11:24:23 +0200 Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Visuwesh <visuweshm@gmail.com>
>> Cc: 74700@debbugs.gnu.org
>> Date: Thu, 05 Dec 2024 14:32:18 +0530
>>
>> [வியாழன் டிசம்பர் 05, 2024] Eli Zaretskii wrote:
>>
>> >> I removed the whitespace. But isn't that way to make lists such as
>> >>
>> >> ( 1
>> >> 2
>> >> 3)
>> >>
>> >> aligned without manual intervention?
>> >
>> > Typing something like
>> >
>> > (setq foo (1
>> > 2
>> > 3)
>> >
>> > aligns the members for me. So I don't think I understand what you are
>> > saying here.
>>
>> Try to align
>>
>> (setq foo '(1 2
>> 3))
>>
>> instead. 3 would end up aligning at 2 instead of 1.
>
> Yes, and why is that a problem? This is the standard Lisp indentation
> in Emacs. It makes it easy to find the end of the sexps.
>
>> Adding a space after ( prevents this.
>
> I'm not sure I understand why overriding the standard indentation
> would be a good idea.
Sometimes the standard indentation makes the code harder to read, e.g.,
the sexp that the indentation in Visuwesh's patch took as an example is
this (starting at column 10):
(add-text-properties
segment-start (1- (point))
`( mouse-face highlight
help-echo "mouse-1: goto this directory"
keymap ,(let* ((current-dir dir)
(click (lambda ()
(interactive)
(cond
((assoc current-dir dired-subdir-alist)
(dired-goto-subdir current-dir))
;; If there is a wildcard chars
;; in the directory name, don't
;; use the alternate file machinery
;; which tries to keep only one
;; dired buffer open at once.
;;
;; FIXME: Is this code path reachable?
((insert-directory-wildcard-in-dir-p
current-dir)
(dired current-dir))
(t
(dired--find-possibly-alternative-file
current-dir))))))
(define-keymap
"<mouse-2>" click
"<follow-link>" 'mouse-face
"RET" click))))
Here is the indentation without the space (in dired.el several lines of
this code extend well beyond column 80):
(add-text-properties
segment-start (1- (point))
`(mouse-face highlight
help-echo "mouse-1: goto this directory"
keymap ,(let* ((current-dir dir)
(click (lambda ()
(interactive)
(cond
((assoc current-dir dired-subdir-alist)
(dired-goto-subdir current-dir))
;; If there is a wildcard chars
;; in the directory name, don't
;; use the alternate file machinery
;; which tries to keep only one
;; dired buffer open at once.
;;
;; FIXME: Is this code path reachable?
((insert-directory-wildcard-in-dir-p
current-dir)
(dired current-dir))
(t
(dired--find-possibly-alternative-file
current-dir))))))
(define-keymap
"<mouse-2>" click
"<follow-link>" 'mouse-face
"RET" click))))
Steve Berman
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 9:02 ` Visuwesh
2024-12-05 9:24 ` Eli Zaretskii
@ 2024-12-05 17:56 ` Juri Linkov
1 sibling, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2024-12-05 17:56 UTC (permalink / raw)
To: Visuwesh; +Cc: Eli Zaretskii, 74700
> but I think clicking on 'emacs' to open the Dired buffer for
> ~/lib/ports/emacs is also a good option.
Indeed, opening the Dired buffer would be better
instead of directly refreshing the buffer.
To force the directory to refresh, you can call dired with:
(let ((dired-auto-revert-buffer t)) (dired "/..."))
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name
2024-12-05 8:26 ` Visuwesh
2024-12-05 8:41 ` Eli Zaretskii
@ 2024-12-12 10:31 ` Eli Zaretskii
1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2024-12-12 10:31 UTC (permalink / raw)
To: Visuwesh; +Cc: 74700-done
> From: Visuwesh <visuweshm@gmail.com>
> Cc: 74700@debbugs.gnu.org
> Date: Thu, 05 Dec 2024 13:56:44 +0530
>
> > Thanks, a few comments below.
> >
> >> +---
> >> +*** Clicking on last segment of directory reverts buffer
> >> +When 'dired-make-directory-clickable' is non-nil, clicking on the last
> >> +segment of the directory name now reverts the Dired buffer.
> >
> > We don't call these "segments", we call them "components". And since
> > you are talking about the last one, you could also say "base name of
> > the directory".
>
> I've changed it to base name.
>
> >> + (when (search-forward ":" bound t)
> >> + (add-text-properties
> >> + segment-start (1- (point))
> >> + `( mouse-face highlight
> > ^^
> > We don't leave whitespace after the opening parenthesis.
>
> I removed the whitespace. But isn't that way to make lists such as
>
> ( 1
> 2
> 3)
>
> aligned without manual intervention? It is used in the list above too.
>
> >> + help-echo "mouse-1: revert this buffer"
> >
> > I think the help-echo should say something more similar to what we say
> > for the other components of the directory shown in the header line.
> > Something like "re-read this buffer's directory".
>
> Now done.
>
> >> + keymap ,(define-keymap
> >> + "<mouse-2>" #'revert-buffer
> >> + "<follow-link>" 'follow-link
> >> + "RET" #'revert-buffer))))))))
> >
> > Should we perhaps call dired-revert directly?
>
> revert-buffer-function is set to dired-revert by dired. If someone has
> changed it, for some reason, using revert-buffer would heed their
> customisation. So I've left it as revert-buffer.
Thanks, installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-12-12 10:31 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-05 6:12 bug#74700: [PATCH] Revert Dired buffer when clicking on last segment of directory name Visuwesh
2024-12-05 7:02 ` Eli Zaretskii
2024-12-05 8:26 ` Visuwesh
2024-12-05 8:41 ` Eli Zaretskii
2024-12-05 9:02 ` Visuwesh
2024-12-05 9:24 ` Eli Zaretskii
2024-12-05 10:42 ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-05 17:56 ` Juri Linkov
2024-12-12 10:31 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.