From: Tassilo Horn <tsdh@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 54636@debbugs.gnu.org, schwab@linux-m68k.org
Subject: bug#54636: dired fails to update subdirs when files are created/deleted/renamed
Date: Wed, 30 Mar 2022 18:29:29 +0200 [thread overview]
Message-ID: <874k3f1jxb.fsf@gnu.org> (raw)
In-Reply-To: <878rsr1kss.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 415 bytes --]
Tassilo Horn <tsdh@gnu.org> writes:
> I think my patch is valid but now I think I should just create a
> separate function dired-buffers-for-cleanup and use that from
> dired-clean-up-after-deletion (or just collect the buffers in that
> function) and remove the SUBDIRS argument from dired-buffers-for-dir
> as it changes its logic too drastically.
>
> I'll prepare a patch in that direction later.
Here it is:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired2.patch --]
[-- Type: text/x-patch, Size: 3210 bytes --]
diff --git a/lisp/dired.el b/lisp/dired.el
index 75dcd33e67..89b81ca0db 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2870,12 +2870,10 @@ dired-copy-filename-as-kill
\f
;;; Keeping Dired buffers in sync with the filesystem and with each other
-(defun dired-buffers-for-dir (dir &optional file subdirs)
+(defun dired-buffers-for-dir (dir &optional file)
"Return a list of buffers for DIR (top level or in-situ subdir).
If FILE is non-nil, include only those whose wildcard pattern (if any)
matches FILE.
-If SUBDIRS is non-nil, also include the dired buffers of
-directories below DIR.
The list is in reverse order of buffer creation, most recent last.
As a side effect, killed dired buffers for DIR are removed from
`dired-buffers'."
@@ -2889,8 +2887,7 @@ dired-buffers-for-dir
(setq dired-buffers (delq elt dired-buffers)))
((dired-in-this-tree-p dir (car elt))
(with-current-buffer buf
- (when (and (or subdirs
- (assoc dir dired-subdir-alist))
+ (when (and (assoc dir dired-subdir-alist)
(or (null file)
(if (stringp dired-directory)
(let ((wildcards (file-name-nondirectory
@@ -2903,6 +2900,22 @@ dired-buffers-for-dir
(setq result (cons buf result)))))))
result))
+(defun dired-buffers-for-dir-or-subdir (dir)
+ "Return a list of buffers for DIR or a subdirectory thereof.
+As a side effect, killed dired buffers for DIR are removed from
+`dired-buffers'."
+ (setq dir (file-name-as-directory dir))
+ (let (result buf)
+ (dolist (elt dired-buffers)
+ (setq buf (cdr elt))
+ (cond
+ ((null (buffer-name buf))
+ ;; Buffer is killed - clean up:
+ (setq dired-buffers (delq elt dired-buffers)))
+ ((dired-in-this-tree-p (car elt) dir)
+ (setq result (cons buf result)))))
+ result))
+
(defun dired-glob-regexp (pattern)
"Convert glob-pattern PATTERN to a regular expression."
(let ((matched-in-pattern 0) ;; How many chars of PATTERN we've handled.
@@ -3479,15 +3492,16 @@ dired-clean-up-after-deletion
(file-name-nondirectory fn))))
(not dired-clean-confirm-killing-deleted-buffers))
(kill-buffer buf)))
- (let ((buf-list (dired-buffers-for-dir (expand-file-name fn)
- nil 'subdirs)))
+ (let ((buf-list (dired-buffers-for-dir-or-subdir
+ (expand-file-name fn))))
(and buf-list
(or (and dired-clean-confirm-killing-deleted-buffers
(y-or-n-p
(format
- (ngettext "Kill Dired buffer of %s, too? "
- "Kill Dired buffers of %s, too? "
- (length buf-list))
+ (ngettext
+ "Kill Dired buffer of %s, too? "
+ "Kill Dired buffers of %s and its sub-directories, too? "
+ (length buf-list))
(file-name-nondirectory
;; FN may end in a / if `dired-listing-switches'
;; contains -p, so we need to strip that
[-- Attachment #3: Type: text/plain, Size: 132 bytes --]
I think that's a better approach than changing dired-buffers-for-dir
which I shouldn't have done in the first place.
Bye,
Tassilo
next prev parent reply other threads:[~2022-03-30 16:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 11:15 bug#54636: dired fails to update subdirs when files are created/deleted/renamed Andreas Schwab
2022-03-30 12:03 ` Eli Zaretskii
2022-03-30 12:11 ` Andreas Schwab
2022-03-30 12:43 ` Tassilo Horn
2022-03-30 13:22 ` Eli Zaretskii
2022-03-30 13:29 ` Tassilo Horn
2022-03-30 13:56 ` Eli Zaretskii
2022-03-30 14:30 ` Tassilo Horn
2022-03-30 15:51 ` Eli Zaretskii
2022-03-30 16:02 ` Tassilo Horn
2022-03-30 16:29 ` Tassilo Horn [this message]
2022-03-30 16:42 ` Eli Zaretskii
2022-03-30 16:47 ` Tassilo Horn
2022-03-30 16:55 ` Eli Zaretskii
2022-03-30 17:51 ` Tassilo Horn
2022-04-05 11:30 ` Eli Zaretskii
2022-03-30 16:30 ` Eli Zaretskii
2022-03-30 16:32 ` Tassilo Horn
2023-07-08 18:31 ` Jakub Ječmínek
2023-07-09 11:09 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874k3f1jxb.fsf@gnu.org \
--to=tsdh@gnu.org \
--cc=54636@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=schwab@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).