From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: automatically save a specific buffer on exit
Date: Wed, 04 Feb 2009 22:59:29 +0100 [thread overview]
Message-ID: <1233784831.640257@arno.fh-trier.de> (raw)
In-Reply-To: <mailman.21.1233782719.10249.help-gnu-emacs@gnu.org>
Thierry Volpiatto wrote:
> Hi,
> Andreas Politz <politza@fh-trier.de> writes:
>
>> Hi,
>>
>> I have a persistent scratch buffer with a file attached
>> and I would like emacs to have it saved whenever I
>> leave the editor.
>> 'kill-emacs-hook' runs to late and `write-file-functions'
>> doesn't seem to be aproppriate either.
>
> Kill-emacs-hook work fine here.
> Here the code i use:
>
> ,----
> | (defvar save-scratch-file "~/.emacs.d/save-scratch.el")
> | (defun tv-save-scratch (&optional append)
> | (interactive "P")
> | (with-current-buffer "*scratch*"
> | (widen)
> | (goto-char (point-min))
> | (forward-line 1)
> | (let* ((beg (point))
> | (end (point-max))
> | (buffer-contents (buffer-substring beg end)))
> | (save-excursion
> | (find-file save-scratch-file)
> | (if (or current-prefix-arg
> | append)
> | (progn
> | (goto-char (point-max))
> | (insert buffer-contents)
> | (save-buffer)
> | (kill-buffer (current-buffer)))
> | (erase-buffer)
> | (goto-char (point-min))
> | (insert buffer-contents)
> | (save-buffer)
> | (kill-buffer (current-buffer)))))))
> |
> | (defun tv-restore-scratch-buffer ()
> | (with-current-buffer "*scratch*"
> | (goto-char (point-max))
> | (forward-line)
> | (insert-file-contents save-scratch-file)))
> |
> | (add-hook 'kill-emacs-hook 'tv-save-scratch)
> | (add-hook 'emacs-startup-hook 'tv-restore-scratch-buffer)
> `----
>
>
Yes, I did it like this before (Btw append- and write-file would
make things easier). The problem here is, there is no auto-saving involved
in this setup and I am currently working with a system that crashes
frequently.
I just wrote a tiny function, which writes the scratch buffer and calls
save-buffers-kill-emacs and bound it to C-xC-c. That seems to be the easiest
solution (Which I haven't thought of before, since I was narrowed down
to finding the right hook).
-ap
next prev parent reply other threads:[~2009-02-04 21:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-04 20:26 automatically save a specific buffer on exit Andreas Politz
2009-02-04 21:11 ` Thierry Volpiatto
2009-02-04 21:30 ` Lennart Borgman
2009-02-06 2:42 ` Kevin Rodgers
[not found] ` <mailman.21.1233782719.10249.help-gnu-emacs@gnu.org>
2009-02-04 21:59 ` Andreas Politz [this message]
2009-02-05 7:41 ` Thierry Volpiatto
2009-02-06 8:53 ` Thierry Volpiatto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1233784831.640257@arno.fh-trier.de \
--to=politza@fh-trier.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.