Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dired-x: How to set "Kill buffer of ..., too?" to yes without confirmation?

Tags:

emacs

dired

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?

like image 420
Marius Hofert Avatar asked Jul 18 '12 17:07

Marius Hofert


2 Answers

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.

like image 172
Michael Hoffman Avatar answered Sep 22 '22 11:09

Michael Hoffman


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?
  ))
like image 28
pmielke Avatar answered Sep 20 '22 11:09

pmielke