summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
authorTassilo Horn <tsdh@gnu.org>2022-03-30 19:49:01 +0200
committerTassilo Horn <tsdh@gnu.org>2022-03-30 19:49:01 +0200
commit03e6a295d5c46151361845afbf5c8bcae915c89f (patch)
tree577a955b3cc83f4b9fb5116d7b6d311c77d9e848 /lisp/dired.el
parent7208106e8143ecc22c5313ddd1ea785fc9086d6b (diff)
downloademacs-03e6a295d5c46151361845afbf5c8bcae915c89f.tar.gz
emacs-03e6a295d5c46151361845afbf5c8bcae915c89f.tar.bz2
emacs-03e6a295d5c46151361845afbf5c8bcae915c89f.zip
dired: implement feature from 7b50ed553f differently
* lisp/dired.el (dired-buffers-for-dir): Restore to emacs-27 version. (dired-buffers-for-dir-or-subdir): New function. (dired-clean-up-after-deletion): Use dired-buffers-for-dir-or-subdir instead dired-buffers-for-dir.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el54
1 files changed, 34 insertions, 20 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 75dcd33e67c..a3768d224b4 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2870,12 +2870,10 @@ 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 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,18 +2887,33 @@ As a side effect, killed dired buffers for DIR are removed from
(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))
- (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)))))))
+ (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)))))))
+ 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)
@@ -3479,15 +3492,16 @@ 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)
- 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