If you delete a file foo
in dired-x
, you get asked Kill buffer of foo, too?
. How can I skip this question and always answer it with yes
?
dired-x: How to set "Kill buffer of ..., too?" to yes without confirmation?
Other answers are stale, Since 26.1 Emacs provide a option to skip confirmation
(setq dired-clean-confirm-killing-deleted-buffers nil)
You can advise the dired-delete-entry
function so that any file buffers are closed before the deletion:
(defadvice dired-delete-entry (before force-clean-up-buffers (file) activate)
(kill-buffer (get-file-buffer file)))
The Elisp manual describes advising as "cleaner than redefining the whole function" and it is less likely to break if the definition of the function changes in the future.
I just realized that, unfortunately, this is not behaving as expected . When I'm asked to kill the buffer, too, and I choose yes, I am still in the dired(-x) buffer showing me the remaining files. However, with your code, the following happens: When I delete a file (without being asked), it throws me in a different buffer instead of just deleting the file without changing the buffer. –
Tessin
Simply redefine dired-clean-up-after-deletion in dired-x.el.
;; redefine the definition in dired-x.el, so that we are not prompted
;; to remove buffers that were associated with deleted
;; files/directories
(eval-after-load "dired-x" '(defun dired-clean-up-after-deletion (fn)
"My. Clean up after a deleted file or directory FN.
Remove expanded subdir of deleted dir, if any."
(save-excursion (and (cdr dired-subdir-alist)
(dired-goto-subdir fn)
(dired-kill-subdir)))
;; Offer to kill buffer of deleted file FN.
(if dired-clean-up-buffers-too
(progn
(let ((buf (get-file-buffer fn)))
(and buf
(save-excursion ; you never know where kill-buffer leaves you
(kill-buffer buf))))
(let ((buf-list (dired-buffers-for-dir (expand-file-name fn)))
(buf nil))
(and buf-list
(while buf-list
(save-excursion (kill-buffer (car buf-list)))
(setq buf-list (cdr buf-list)))))))
;; Anything else?
))
Other answers are stale, Since 26.1 Emacs provide a option to skip confirmation
(setq dired-clean-confirm-killing-deleted-buffers nil)
© 2022 - 2024 — McMap. All rights reserved.