每当我尝试退出Emacs时,它会询问我是否要保存任何修改过的缓冲区。在我回答“否”的情况下,它会问我:
存在修改的缓冲区;无论如何退出? (是或否)
有没有办法阻止Emacs问我最后一个问题?
答案 0 :(得分:16)
有很多方法可以做到这一点:
您可以建议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)))
并将其绑定到标准 C-x C-c 键绑定:
(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)
答案 1 :(得分:7)
如果您查看source for save-buffers-kill-emacs
,您会看到没有用户选项可以关闭此问题。
所以我担心获得你想要的最简单的方法就是编写你自己的save-buffers-kill-emacs
版本来跳过确认(请参阅Trey Jackson的answer了解这看起来如何)。 / p>
但是,我认为更好的方法是改变您的工作习惯,这样您就不必经常退出Emacs。如果您经常退出Emacs,则表明您没有充分利用Emacs的客户端/服务器功能,或者能够运行交互式shell,在远程计算机上编辑文件,连接到多个终端等等。 / p>
答案 2 :(得分:6)
您可以将此添加到.emacs,这会提示您保存未保存的文件更改,然后退出w / out进一步确认:
(defun my-kill-emacs ()
"save some buffers, then exit unconditionally"
(interactive)
(save-some-buffers nil t)
(kill-emacs))
(global-set-key (kbd "C-x C-c") 'my-kill-emacs)