* make emacs ask to save modified non-file buffers
@ 2008-06-23 0:23 Xah
2008-06-23 0:48 ` Lennart Borgman (gmail)
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Xah @ 2008-06-23 0:23 UTC (permalink / raw)
To: help-gnu-emacs
when i create a new buffer, how can i make emacs ask to save if it is
modified?
for example, i have this function:
(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)
))
after calling, it'll create a new buffer. Then, if user edit the
buffer, then close it (using either kill-buffer or kill-this-buffer),
then i want emacs to ask whether to save it if the buffer has been
modified.
according to the manual, the var buffer-offer-save will do it only if
the buffer is a visiting buffer. Then the manual talks about save-some-
buffers second argument but i don't see how this fits together, since
i don't actually want to call save-some-buffers.
Thanks.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: make emacs ask to save modified non-file buffers
2008-06-23 0:23 make emacs ask to save modified non-file buffers Xah
@ 2008-06-23 0:48 ` Lennart Borgman (gmail)
[not found] ` <mailman.13718.1214182118.18990.help-gnu-emacs@gnu.org>
2008-06-23 8:48 ` Juanma Barranquero
2 siblings, 0 replies; 5+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-23 0:48 UTC (permalink / raw)
To: Xah; +Cc: help-gnu-emacs
Xah wrote:
> when i create a new buffer, how can i make emacs ask to save if it is
> modified?
>
> for example, i have this function:
>
> (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)
> ))
>
> after calling, it'll create a new buffer. Then, if user edit the
> buffer, then close it (using either kill-buffer or kill-this-buffer),
> then i want emacs to ask whether to save it if the buffer has been
> modified.
>
> according to the manual, the var buffer-offer-save will do it only if
> the buffer is a visiting buffer. Then the manual talks about save-some-
> buffers second argument but i don't see how this fits together, since
> i don't actually want to call save-some-buffers.
(info "(elisp) Killing Buffers")
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: make emacs ask to save modified non-file buffers
[not found] ` <mailman.13718.1214182118.18990.help-gnu-emacs@gnu.org>
@ 2008-06-23 4:02 ` Xah
2008-06-23 6:26 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 5+ messages in thread
From: Xah @ 2008-06-23 4:02 UTC (permalink / raw)
To: help-gnu-emacs
> (info "(elisp) Killing Buffers")
I was already reading that page but it doesn't seems to suggest a
solution.
Namely, how to make kill-buffer ask user to save, for buffers that's
not associated with file.
looking at Aquamacs's source... looks like the “solved” it by actually
define its own kill-buffer wrapper, e.g. close-current-window-
asktosave.
Xah
∑ http://xahlee.org/
☄
On Jun 22, 5:48 pm, "Lennart Borgman (gmail)"
<lennart.borg...@gmail.com> wrote:
> Xah wrote:
> > when i create a new buffer, how can i make emacs ask to save if it is
> > modified?
>
> > for example, i have this function:
>
> > (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)
> > ))
>
> > after calling, it'll create a new buffer. Then, if user edit the
> > buffer, then close it (using either kill-buffer or kill-this-buffer),
> > then i want emacs to ask whether to save it if the buffer has been
> > modified.
>
> > according to the manual, the var buffer-offer-save will do it only if
> > the buffer is a visiting buffer. Then the manual talks about save-some-
> > buffers second argument but i don't see how this fits together, since
> > i don't actually want to call save-some-buffers.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: make emacs ask to save modified non-file buffers
2008-06-23 4:02 ` Xah
@ 2008-06-23 6:26 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 5+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-23 6:26 UTC (permalink / raw)
To: Xah; +Cc: help-gnu-emacs
Xah wrote:
>> (info "(elisp) Killing Buffers")
>
> I was already reading that page but it doesn't seems to suggest a
> solution.
What about the hooks there?
> Namely, how to make kill-buffer ask user to save, for buffers that's
> not associated with file.
>
> looking at Aquamacs's source... looks like the “solved” it by actually
> define its own kill-buffer wrapper, e.g. close-current-window-
> asktosave.
>
> Xah
> ∑ http://xahlee.org/
>
> ☄
>
>
> On Jun 22, 5:48 pm, "Lennart Borgman (gmail)"
> <lennart.borg...@gmail.com> wrote:
>> Xah wrote:
>>> when i create a new buffer, how can i make emacs ask to save if it is
>>> modified?
>>> for example, i have this function:
>>> (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)
>>> ))
>>> after calling, it'll create a new buffer. Then, if user edit the
>>> buffer, then close it (using either kill-buffer or kill-this-buffer),
>>> then i want emacs to ask whether to save it if the buffer has been
>>> modified.
>>> according to the manual, the var buffer-offer-save will do it only if
>>> the buffer is a visiting buffer. Then the manual talks about save-some-
>>> buffers second argument but i don't see how this fits together, since
>>> i don't actually want to call save-some-buffers.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: make emacs ask to save modified non-file buffers
2008-06-23 0:23 make emacs ask to save modified non-file buffers Xah
2008-06-23 0:48 ` Lennart Borgman (gmail)
[not found] ` <mailman.13718.1214182118.18990.help-gnu-emacs@gnu.org>
@ 2008-06-23 8:48 ` Juanma Barranquero
2 siblings, 0 replies; 5+ messages in thread
From: Juanma Barranquero @ 2008-06-23 8:48 UTC (permalink / raw)
To: Xah; +Cc: help-gnu-emacs
On Mon, Jun 23, 2008 at 02:23, Xah <xahlee@gmail.com> wrote:
> according to the manual, the var buffer-offer-save will do it only if
> the buffer is a visiting buffer.
Uh? describe-variable's output for `buffer-offer-save':
[...]
Non-nil in a buffer means always offer to save buffer on exit.
Do so even if the buffer is not visiting a file. <--- ???????
[...]
and the Emacs Lisp Reference's entry for `buffer-offer-save':
-- Variable: buffer-offer-save
This variable, if non-`nil' in a particular buffer, tells
`save-buffers-kill-emacs' and `save-some-buffers' (if the second
optional argument to that function is `t') to offer to save that
buffer, just as they offer to save file-visiting buffers. <--- ???????
The problem here is that `buffer-offer-save' affects the two functions
mentioned above (`save-buffers-kill-emacs' and `save-some-buffers'),
not `kill-buffer'. As Lennart says, you'll have to use
`kill-emacs-hook' or `kill-emacs-query-functions' and add a function
to ask the user and save if appropriate.
Juanma
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-06-23 8:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-23 0:23 make emacs ask to save modified non-file buffers Xah
2008-06-23 0:48 ` Lennart Borgman (gmail)
[not found] ` <mailman.13718.1214182118.18990.help-gnu-emacs@gnu.org>
2008-06-23 4:02 ` Xah
2008-06-23 6:26 ` Lennart Borgman (gmail)
2008-06-23 8:48 ` Juanma Barranquero
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).