如果您删除foo
中的文件dired-x
,系统会向您询问Kill buffer of foo, too?
。如何跳过此问题并始终使用yes
回答?
答案 0 :(得分:9)
您可以建议dired-delete-entry
函数,以便在删除之前关闭所有文件缓冲区:
(defadvice dired-delete-entry (before force-clean-up-buffers (file) activate)
(kill-buffer (get-file-buffer file)))
Elisp手册描述的建议是“比重新定义整个功能更清洁”,如果将来函数的定义发生变化,它就不太可能破坏。
答案 1 :(得分:5)
只需在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?
))