emacs - 防止 Emacs 询问 "modified buffers exist; exit anyway?"

标签 emacs

每当我尝试退出 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/

相关文章:

emacs - 如何从另一个 Emacs Lisp 函数调用带有前缀参数的交互式 Emacs Lisp 函数?

emacs - 仅使用邪恶包中的两个函数作为键绑定(bind)

emacs - 如何在 evil-mode 下映射 `q:i`

Emacs:当我到达 View 的最后一行时,如何只显示下一行?

Emacs:你如何禁用自动重新居中?

python - 为 emacs 更改 python 解释器

emacs - 如何使用 scp 或 rsync 使用 Tramp 传输文件

emacs - Emacs 中如果没有行号模式,人们如何生活?

emacs - 如何在 Windows 上将 ssh 与 Emacs 一起使用

emacs - 是否可以让语义(emacs)自动访问所有文件?