每当我尝试退出Emacs时,它都会询问我是否要保存任何已修改的缓冲区。如果我回答“否”,它将会问我:
有没有办法阻止Emacs询问我最后一个问题呢?存在已修改的缓冲区; 确认退出吗?(y or n)
有没有办法阻止Emacs询问我最后一个问题呢?存在已修改的缓冲区; 确认退出吗?(y or n)
有多种方法可以实现这一点:
您可以建议使用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))
(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)
(fset 'save-buffers-kill-emacs 'my-save-buffers-kill-emacs)
yes-or-no-p
,那么它不仅会影响到save-buffers-kill-emacs
中的调用(这是OP想要更改的),而且还会影响到save-some-buffers
中的调用(据我所知,OP并不想更改)。 - Gareth Reessave-some-buffers
使用 map-y-or-n-p
而不是 y-or-n-p
,所以你的建议对它没有影响。 - Gareth Rees(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)