GNU bug report logs -
#54636
dired fails to update subdirs when files are created/deleted/renamed
Previous Next
Reported by: Andreas Schwab <schwab <at> linux-m68k.org>
Date: Wed, 30 Mar 2022 11:16:02 UTC
Severity: normal
Merged with 51486
Found in version 28.0.60
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #44 received at 54636 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Tassilo Horn <tsdh <at> 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:
[dired2.patch (text/x-patch, inline)]
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
;;; 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
[Message part 3 (text/plain, inline)]
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
This bug report was last modified 1 year and 319 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.