* automatically save a specific buffer on exit
@ 2009-02-04 20:26 Andreas Politz
2009-02-04 21:11 ` Thierry Volpiatto
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andreas Politz @ 2009-02-04 20:26 UTC (permalink / raw
To: help-gnu-emacs
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.
-ap
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: automatically save a specific buffer on exit
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
[not found] ` <mailman.21.1233782719.10249.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2009-02-04 21:11 UTC (permalink / raw
To: help-gnu-emacs
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)
`----
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: automatically save a specific buffer on exit
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>
2 siblings, 1 reply; 7+ messages in thread
From: Lennart Borgman @ 2009-02-04 21:30 UTC (permalink / raw
To: Andreas Politz; +Cc: help-gnu-emacs
On Wed, Feb 4, 2009 at 9:26 PM, Andreas Politz <politza@fh-trier.de> wrote:
> 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-buffer-query-function?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: automatically save a specific buffer on exit
[not found] ` <mailman.21.1233782719.10249.help-gnu-emacs@gnu.org>
@ 2009-02-04 21:59 ` Andreas Politz
2009-02-05 7:41 ` Thierry Volpiatto
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Politz @ 2009-02-04 21:59 UTC (permalink / raw
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: automatically save a specific buffer on exit
2009-02-04 21:59 ` Andreas Politz
@ 2009-02-05 7:41 ` Thierry Volpiatto
2009-02-06 8:53 ` Thierry Volpiatto
0 siblings, 1 reply; 7+ messages in thread
From: Thierry Volpiatto @ 2009-02-05 7:41 UTC (permalink / raw
To: help-gnu-emacs
Hi Andreas,
Andreas Politz <politza@fh-trier.de> writes:
> 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.
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: automatically save a specific buffer on exit
2009-02-04 21:30 ` Lennart Borgman
@ 2009-02-06 2:42 ` Kevin Rodgers
0 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2009-02-06 2:42 UTC (permalink / raw
To: help-gnu-emacs
Lennart Borgman wrote:
> On Wed, Feb 4, 2009 at 9:26 PM, Andreas Politz <politza@fh-trier.de> wrote:
>> 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-buffer-query-function?
The variable name is plural: kill-buffer-query-functions
But wouldn't kill-emacs-query-functions be better suited for this?
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: automatically save a specific buffer on exit
2009-02-05 7:41 ` Thierry Volpiatto
@ 2009-02-06 8:53 ` Thierry Volpiatto
0 siblings, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2009-02-06 8:53 UTC (permalink / raw
To: help-gnu-emacs
Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
> Hi Andreas,
> Andreas Politz <politza@fh-trier.de> writes:
>
>> 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.
>
> 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#
Cleaner, avoid these files in home directory:
,----
| (defun run-autosave-in-scratch ()
| (with-current-buffer "*scratch*"
| (make-auto-save-file-name)
| (auto-save-mode 1)
| (setq buffer-auto-save-file-name "~/.scratch-autosave/scratch.el")))
`----
`buffer-auto-save-file-name' will become buffer local variable.
>> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-02-06 8:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2009-02-05 7:41 ` Thierry Volpiatto
2009-02-06 8:53 ` Thierry Volpiatto
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.