Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Emacs from asking "modified buffers exist; exit anyway?"

Tags:

emacs

Whenever I try to quit Emacs it will ask me if I want to save any modified buffers. In the case where I answer "no" it will ask me:

Modified buffers exist; exit anyway? (y or n)

Is there any way to prevent Emacs from asking me the last question?

like image 510
Tassos Avatar asked Jul 20 '11 13:07

Tassos


3 Answers

There are a number of ways you can do this:

You could advise the save-buffers-kill-emacs function:

(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))

The downside of doing this is that it will also bypass the check for active processes in Emacs (which is done after the file buffer check). So, it is probably safest to write your own version of 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)))

and either bind it to the standard C-x C-c key binding:

(global-set-key (kbd "C-x C-c") 'my-save-buffers-kill-emacs)

or fset it to "save-buffers-kill-emacs":

(fset 'save-buffers-kill-emacs 'my-save-buffers-kill-emacs)
like image 66
zev Avatar answered Nov 09 '22 10:11

zev


You can add this to your .emacs, which will prompt you to save unsaved changes to files, and then exit w/out further confirmation:

(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)
like image 36
Trey Jackson Avatar answered Nov 09 '22 10:11

Trey Jackson


If you look at the source for save-buffers-kill-emacs you'll see that there's no user option to turn off this question.

So I'm afraid that the simplest way to get what you want is to write your own version of save-buffers-kill-emacs that skips the confirmation (see Trey Jackson's answer for how this would look).

However, I think a better approach is to change your working habits so that you don't have to quit Emacs very often. If you are often quitting Emacs, it's a sign that you're not making the most of Emacs' client/server capabilities, or its ability to run interactive shells, edit files on remote machines, connect to multiple terminals, and so on.

like image 35
Gareth Rees Avatar answered Nov 09 '22 10:11

Gareth Rees