If I am closing a file that has modifications, emacs warns me about this and says I should press y or n.

Even when I press 'n', it still tells me that modified buffers exist and asks if I want to save anyway.

Is there a way I can stop this second 'modified buffers exist' message from appearing? Once I have pressed 'n', it should be clear to emacs that I do not want to save.

I do want it to ask me the first 'y or n' question, though.


This warning is built into save-buffers-kill-emacs. You can't disable it easily.

A simple way to get rid of it is to tell Emacs to save all buffers, by passing a prefix argument to the save-buffers-kill-emacs command (or save-buffers-kill-terminal which calls it): type C-u C-x C-c instead of C-x C-c. However you may not want to do that.

You can use the advice facility to modify the behavior of functions. Here, it's cumbersome because the code calls a generic function (yes-or-no-p) right in the middle of some logic that's hard to hack.

(require 'cl)
(defadvice save-buffers-kill-emacs
  (around save-buffers-kill-emacs-no-modified-yes-no activate compile))
  (let ((real-yes-or-no-p (symbol-function 'yes-or-no-p)))
    (flet ((yes-or-no-p (msg)
             (or (equal msg "Modified buffers exist; exit anyway? ")
                 (funcall real-yes-or-no-p msg)))))

You may prefer to copy the definition and remove the offending call, however this is likely to require more maintenance as Emacs evolves.

Do you really need this? First, warning of unsaved changes is usually a good idea, which is why Emacs does it. Second, it's typical to start Emacs with your session and exit it when you log out, so exiting Emacs is something that happens rarely.

  • 1
    I agree that warning of unsave changes is good, and emacs is already doing this when it asks the first time if I want to save changes. I don't need it asking the second time, too. – Tola Odejayi Jan 8 '14 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.