]> git.eshelyaron.com Git - emacs.git/commitdiff
Ask if dir and subdir dired buffers be killed when deleting dir
authorTassilo Horn <tsdh@gnu.org>
Fri, 4 Jun 2021 19:58:11 +0000 (21:58 +0200)
committerTassilo Horn <tsdh@gnu.org>
Fri, 4 Jun 2021 19:58:11 +0000 (21:58 +0200)
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 ../.

lisp/dired.el

index 165484302a355750c82dd50798daf34921bbf421..bb428e21983a18efc29026bbdff9d8beaaab21c0 100644 (file)
@@ -2820,10 +2820,12 @@ You can then feed the file name(s) to other commands with \\[yank]."
 \f
 ;; 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