每当我尝试退出 Emacs 时,它会询问我是否要保存任何修改过的缓冲区。如果我回答“否”,它会问我:
Modified buffers exist; exit anyway? (y or n)
有什么办法可以阻止 Emacs 问我最后一个问题吗?
最佳答案
有多种方法可以做到这一点:
您可以建议 save-buffers-kill-emacs 功能:
(defadvice save-buffers-kill-emacs (around no-y-or-n activate)
(flet ((yes-or-no-p (&rest args) t)
(y-or-n-p (&rest args) t))
ad-do-it))
这样做的缺点是它还会绕过 Emacs 中对事件进程的检查(这是在文件缓冲区检查之后完成的)。因此,编写自己的 save-buffers-kill-emacs 版本可能是最安全的
(defun my-save-buffers-kill-emacs (&optional arg)
"Offer to save each buffer(once only), then kill this Emacs process.
With prefix ARG, silently save all file-visiting buffers, then kill."
(interactive "P")
(save-some-buffers arg t)
(and (or (not (fboundp 'process-list))
;; process-list is not defined on MSDOS.
(let ((processes (process-list))
active)
(while processes
(and (memq (process-status (car processes)) '(run stop open listen))
(process-query-on-exit-flag (car processes))
(setq active t))
(setq processes (cdr processes)))
(or (not active)
(progn (list-processes t)
(yes-or-no-p "Active processes exist; kill them and exit anyway? ")))))
;; Query the user for other things, perhaps.
(run-hook-with-args-until-failure 'kill-emacs-query-functions)
(or (null confirm-kill-emacs)
(funcall confirm-kill-emacs "Really exit Emacs? "))
(kill-emacs)))
并将其绑定(bind)到标准 C-x C-c 键绑定(bind):
(global-set-key (kbd "C-x C-c") 'my-save-buffers-kill-emacs)
或将其设置为“save-buffers-kill-emacs”:
(fset 'save-buffers-kill-emacs 'my-save-buffers-kill-emacs)
关于emacs - 防止 Emacs 询问 "modified buffers exist; exit anyway?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6762686/