Skip to content

Commit 7b50ed5

Browse files
committed
Ask if dir and subdir dired buffers be killed when deleting dir
Previously, when you've had dired buffers ~/foo/ ~/foo/bar/ ~/foo/bar/baz/ and then deleted ~/foo/, dired (with dired-clean-up-buffers-too set to non-nil) would only ask to delete the dired buffer of ~/foo/. Now it will offer to delete all three buffers. * lisp/dired.el (dired-buffers-for-dir): Add optional argument SUBDIRS which makes the function return also dired buffers showing a subdir of DIR. (dired-in-this-tree-p): Make obsolete in favor of file-in-directory-p which actually does what the name suggest whereas dired-in-this-tree-p is just string-matching on filenames which will fail with symlinks filenames including ./ or ../.
1 parent 4c362b4 commit 7b50ed5

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lisp/dired.el

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,10 +2820,12 @@ You can then feed the file name(s) to other commands with \\[yank]."
28202820

28212821
;; Keeping Dired buffers in sync with the filesystem and with each other
28222822

2823-
(defun dired-buffers-for-dir (dir &optional file)
2823+
(defun dired-buffers-for-dir (dir &optional file subdirs)
28242824
"Return a list of buffers for DIR (top level or in-situ subdir).
28252825
If FILE is non-nil, include only those whose wildcard pattern (if any)
28262826
matches FILE.
2827+
If SUBDIRS is non-nil, also include the dired buffers of
2828+
directories below DIR.
28272829
The list is in reverse order of buffer creation, most recent last.
28282830
As a side effect, killed dired buffers for DIR are removed from
28292831
dired-buffers."
@@ -2835,19 +2837,20 @@ dired-buffers."
28352837
((null (buffer-name buf))
28362838
;; Buffer is killed - clean up:
28372839
(setq dired-buffers (delq elt dired-buffers)))
2838-
((dired-in-this-tree-p dir (car elt))
2840+
((file-in-directory-p (car elt) dir)
28392841
(with-current-buffer buf
2840-
(and (assoc dir dired-subdir-alist)
2841-
(or (null file)
2842-
(if (stringp dired-directory)
2843-
(let ((wildcards (file-name-nondirectory
2844-
dired-directory)))
2845-
(or (zerop (length wildcards))
2846-
(string-match-p (dired-glob-regexp wildcards)
2847-
file)))
2848-
(member (expand-file-name file dir)
2849-
(cdr dired-directory))))
2850-
(setq result (cons buf result)))))))
2842+
(when (and (or subdirs
2843+
(assoc dir dired-subdir-alist))
2844+
(or (null file)
2845+
(if (stringp dired-directory)
2846+
(let ((wildcards (file-name-nondirectory
2847+
dired-directory)))
2848+
(or (zerop (length wildcards))
2849+
(string-match-p (dired-glob-regexp wildcards)
2850+
file)))
2851+
(member (expand-file-name file dir)
2852+
(cdr dired-directory)))))
2853+
(setq result (cons buf result)))))))
28512854
result))
28522855

28532856
(defun dired-glob-regexp (pattern)
@@ -2912,6 +2915,7 @@ dired-buffers."
29122915
;;"Is FILE part of the directory tree starting at DIR?"
29132916
(let (case-fold-search)
29142917
(string-match-p (concat "^" (regexp-quote dir)) file)))
2918+
(make-obsolete 'dired-in-this-tree-p 'file-in-directory-p "28.1")
29152919
(define-obsolete-function-alias 'dired-in-this-tree
29162920
'dired-in-this-tree-p "27.1")
29172921

@@ -3427,7 +3431,8 @@ confirmation. To disable the confirmation, see
34273431
(file-name-nondirectory fn))))
34283432
(not dired-clean-confirm-killing-deleted-buffers))
34293433
(kill-buffer buf)))
3430-
(let ((buf-list (dired-buffers-for-dir (expand-file-name fn))))
3434+
(let ((buf-list (dired-buffers-for-dir (expand-file-name fn)
3435+
nil 'subdirs)))
34313436
(and buf-list
34323437
(or (and dired-clean-confirm-killing-deleted-buffers
34333438
(y-or-n-p

0 commit comments

Comments
 (0)