每当我尝试退出Emacs时,它会询问我是否要保存任何修改过的缓冲区.在我回答"否"的情况下,它会问我:
存在修改缓冲区; 无论如何退出?(是或否)
有没有办法阻止Emacs问我最后一个问题?
zev*_*zev 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))
Run Code Online (Sandbox Code Playgroud)
这样做的缺点是它还将绕过对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)))
Run Code Online (Sandbox Code Playgroud)
并将其绑定到标准C-x C-c键绑定:
(global-set-key (kbd "C-x C-c") 'my-save-buffers-kill-emacs)
Run Code Online (Sandbox Code Playgroud)
或者将其设置为"save-buffers-kill-emacs":
(fset 'save-buffers-kill-emacs 'my-save-buffers-kill-emacs)
Run Code Online (Sandbox Code Playgroud)
如果您查看源代码,save-buffers-kill-emacs您将看到没有用户选项可以关闭此问题.
所以我担心得到你想要的最简单的方法就是写你自己的版本save-buffers-kill-emacs跳过确认(参见Trey Jackson 对这看起来如何的答案).
但是,我认为更好的方法是改变你的工作习惯,这样你就不必经常退出Emacs.如果您经常退出Emacs,则表明您没有充分利用Emacs的客户端/服务器功能,或者能够运行交互式shell,在远程计算机上编辑文件,连接到多个终端等等.
您可以将此添加到.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)
Run Code Online (Sandbox Code Playgroud)