[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use defadvice without infinite loop
From: |
Klaus Berndl |
Subject: |
Re: How to use defadvice without infinite loop |
Date: |
28 Sep 2003 07:14:27 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
On 27 Sep 2003, Ivan Kanis wrote:
> I want to save VM files to _always_ be saved before calling the function
> save-some buffers.
>
> I am tired of answering 'yes' for these files when grepping, compiling
> or quiting emacs.
>
> I came up with a defadvice function but the proble is that it's
> calling save-some-buffers and it produces an infinite loop. Is there a
> way to avoid that?
>
> (defadvice save-some-buffers(before my-save-some-buffers activate)
> "Ask to save buffers."
> (interactive)
> (save-some-buffers nil 'my-always-save))
The infinite loop comes because the `save-some-buffers' in your advice calls
the adviced version of `save-some-buffers' again and then again and then
again.... Normally i should write here: RTFM ;-) You should definitely read
the advice info-manual - there are some very simple and helpful examples in
it!
(defadvice save-some-buffers(before my-save-some-buffers activate)
"Ask to save buffers."
(ad-set-arg 1 'my-always-save))
This is all...test it!
>
> (defun my-always-save()
> "Files to always save."
> (when buffer-file-name
> (when (string-match "^/home/ivank/mail" buffer-file-name)
> (save-buffer))))
Ciao,
Klaus
--
Klaus Berndl mailto: klaus.berndl@sdm.de
sd&m AG http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220