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

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

Re: automatically save a specific buffer on exit


From: Thierry Volpiatto
Subject: Re: automatically save a specific buffer on exit
Date: Thu, 05 Feb 2009 08:41:12 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux)

Hi Andreas,
Andreas Politz <address@hidden> writes:

> Thierry Volpiatto wrote:
>> Hi,
>> Andreas Politz <address@hidden> 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.

May be you can run something like that when you start working in
scratch:

,----
| (defun run-autosave-in-scratch ()
|   (with-current-buffer "*scratch*"
|     (make-auto-save-file-name)
|     (auto-save-mode 1)))
`----

That make an autosave of your scratch in your /home/you
like that: #%2Ascratch%2A#5973UHu#

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

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





reply via email to

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