help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible not to quit emacs when buffer is modified?


From: Xah Lee
Subject: Re: Is it possible not to quit emacs when buffer is modified?
Date: Wed, 19 Aug 2009 19:23:06 -0700 (PDT)
User-agent: G2/1.0

On Aug 19, 7:09 pm, Xah Lee <xah...@gmail.com> wrote:
> On Aug 19, 5:22 pm, YOUNG <breadn...@gmail.com> wrote:
>
> > Hi,
>
> > If a buffer does not connect to a file but it is modified, if you type
> > c-x c, emacs just quits and losts the data.
>
> > Is there a way to protect of it?
>
> I don't think there's a default way. This is one of the problem that
> pains me.
>
> But if you use ergoemacshttp://code.google.com/p/ergoemacs/
>
> it's fixed there.

O, just tried to reproduce your situation but there's a bit warning.

When you use ergoemacs, you can create buffers by Ctrl+n, which calls
new-empty-buffer. Then, in this buffer, if modified and not saved,
when you try to close it or quit emacs, emacs will prompt you to save
it.

However, it does not fix when if you just use switch-to-buffer (C-x b)
command to create a new buffer.

Here's the relevant source code. Note the line
(setq buffer-offer-save t).
Feel free to use it.

(defun new-empty-buffer ()
  "Opens a new empty buffer."
  (interactive)
  (let ((buf (generate-new-buffer "untitled")))
    (switch-to-buffer buf)
    (funcall (and initial-major-mode))
    (setq buffer-offer-save t)))
;; note: emacs won't offer to save a buffer that's
;; not associated with a file,
;; even if buffer-modified-p is true.
;; One work around is to define your own my-kill-buffer function
;; that wraps around kill-buffer, and check on the buffer modification
;; status to offer save
;; This custome kill buffer is close-current-buffer.

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]