summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
authorTassilo Horn <tsdh@gnu.org>2021-06-04 21:58:11 +0200
committerTassilo Horn <tsdh@gnu.org>2021-06-04 21:58:11 +0200
commit7b50ed553faa6de6d51bf07d12d106ca61ab3ac4 (patch)
treeba6c9f52f8ccc8f9db8bedacde5e00858b4a73b7 /lisp/dired.el
parent4c362b4ef7db64e896b8a9fa5f2b93ff793dee17 (diff)
downloademacs-7b50ed553faa6de6d51bf07d12d106ca61ab3ac4.tar.gz
emacs-7b50ed553faa6de6d51bf07d12d106ca61ab3ac4.tar.bz2
emacs-7b50ed553faa6de6d51bf07d12d106ca61ab3ac4.zip
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 ../.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el33
1 files changed, 19 insertions, 14 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 165484302a3..bb428e21983 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2820,10 +2820,12 @@ You can then feed the file name(s) to other commands with \\[yank]."
;; Keeping Dired buffers in sync with the filesystem and with each other
-(defun dired-buffers-for-dir (dir &optional file)
+(defun dired-buffers-for-dir (dir &optional file subdirs)
"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."
@@ -2835,19 +2837,20 @@ dired-buffers."
((null (buffer-name buf))
;; Buffer is killed - clean up:
(setq dired-buffers (delq elt dired-buffers)))
- ((dired-in-this-tree-p dir (car elt))
+ ((file-in-directory-p (car elt) dir)
(with-current-buffer buf
- (and (assoc dir dired-subdir-alist)
- (or (null file)
- (if (stringp dired-directory)
- (let ((wildcards (file-name-nondirectory
- dired-directory)))
- (or (zerop (length wildcards))
- (string-match-p (dired-glob-regexp wildcards)
- file)))
- (member (expand-file-name file dir)
- (cdr dired-directory))))
- (setq result (cons buf result)))))))
+ (when (and (or subdirs
+ (assoc dir dired-subdir-alist))
+ (or (null file)
+ (if (stringp dired-directory)
+ (let ((wildcards (file-name-nondirectory
+ dired-directory)))
+ (or (zerop (length wildcards))
+ (string-match-p (dired-glob-regexp wildcards)
+ file)))
+ (member (expand-file-name file dir)
+ (cdr dired-directory)))))
+ (setq result (cons buf result)))))))
result))
(defun dired-glob-regexp (pattern)
@@ -2912,6 +2915,7 @@ dired-buffers."
;;"Is FILE part of the directory tree starting at DIR?"
(let (case-fold-search)
(string-match-p (concat "^" (regexp-quote dir)) file)))
+(make-obsolete 'dired-in-this-tree-p 'file-in-directory-p "28.1")
(define-obsolete-function-alias 'dired-in-this-tree
'dired-in-this-tree-p "27.1")
@@ -3427,7 +3431,8 @@ confirmation. To disable the confirmation, see
(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))))
+ (let ((buf-list (dired-buffers-for-dir (expand-file-name fn)
+ nil 'subdirs)))
(and buf-list
(or (and dired-clean-confirm-killing-deleted-buffers
(y-or-n-p