fix(dired): prevent dired from prompting about removing dired buffers

When deleting a file in Dired, it has recently started prompting about
removing the dired buffer along with file buffer. This is rather
annoying, as I almost never want to close the dired instance I have open
when simply deleting a file from a folder.

So I've overridden the relevant function, and added an option
specifically to enable/disable the prompt about removing the dired
buffer.
This commit is contained in:
2021-11-26 21:28:25 +00:00
parent 0ac1c86102
commit 819f068879

View File

@@ -17,6 +17,9 @@
("c" . dired-create-directory)
("M-?" . siren-dired-display-size))
:custom
(siren-dired-clean-up-dired-buffers-after-deletion nil)
:init
(defun siren-dired-mode-setup ()
(hl-line-mode +1))
@@ -70,7 +73,61 @@
(file-attribute-size ; might be int or float
(file-attributes filename)))))
(defgroup siren-dired nil
"Siren specific options for dired."
:group 'dired)
(defcustom siren-dired-clean-up-dired-buffers-after-deletion t
"Offer to remove dired buffers of the directory files were deleted from."
:type 'boolean
:group 'siren-dired)
:config
;; Replace built-in dired buffer cleanup function with a custom patched
;; version that allows separately configuring if dired buffers are cleaned up
;; along with file buffers. Without this, whenever you delete a file in dired,
;; you get prompted if I want to kill the dired buffer you're in in, and most
;; of the time you probably want to continue using dired.
(defun dired-clean-up-after-deletion (fn)
"Clean up after a deleted file or directory FN.
Removes any expanded subdirectory of deleted directory. If
`dired-x' is loaded and `dired-clean-up-buffers-too' is non-nil,
kill any buffers visiting those files, prompting for
confirmation. To disable the confirmation, see
`dired-clean-confirm-killing-deleted-buffers'."
(save-excursion (and (cdr dired-subdir-alist)
(dired-goto-subdir fn)
(dired-kill-subdir)))
;; Offer to kill buffer of deleted file FN.
(when (and (featurep 'dired-x) dired-clean-up-buffers-too)
(let ((buf (get-file-buffer fn)))
(and buf
(or (and dired-clean-confirm-killing-deleted-buffers
(funcall #'y-or-n-p
(format "Kill buffer of %s, too? "
(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)))
(and buf-list
siren-dired-clean-up-dired-buffers-after-deletion
(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))
(file-name-nondirectory
;; FN may end in a / if `dired-listing-switches'
;; contains -p, so we need to strip that
;; (bug#48301).
(directory-file-name fn)))))
(not dired-clean-confirm-killing-deleted-buffers))
(dolist (buf buf-list)
(kill-buffer buf))))))
;; dired+ needs to explicitly loaded as it advices lots of dired functions to
;; work. Without this, the first opened dired window will not have dired+
;; active, but all further dired instances will.