Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

flet is obsolete, but...

135 views
Skip to first unread message

Sebastien Vauban

unread,
Oct 10, 2012, 8:39:23 AM10/10/12
to
Hello,

`flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.

But doing so in the following code:

--8<---------------cut here---------------start------------->8---
(defun my/revert-buffer ()
"Unconditionally revert current buffer."
(interactive)
(flet ((yes-or-no-p (msg) t))
(revert-buffer)))
--8<---------------cut here---------------end--------------->8---

does not lead to the right things:

- use cl-flet, and the code doesn't behave as it should (i.e., it does ask for
a confirmation, before reverting)

- use cl-letf, and you've got an error:
cl-letf: `let' bindings can have only one value-form: yes-or-no-p, (msg), t

What should I do?

Best regards,
Seb

--
Sebastien Vauban

Jambunathan K

unread,
Oct 10, 2012, 9:17:57 AM10/10/12
to Help GNU Emacs

> Hello,
>
> `flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
>
> But doing so in the following code:
>
>
> (defun my/revert-buffer ()
> "Unconditionally revert current buffer."
> (interactive)
> (flet ((yes-or-no-p (msg) t))
> (revert-buffer)))
>
>
> does not lead to the right things:
>
> - use cl-flet, and the code doesn't behave as it should (i.e., it does ask for
> a confirmation, before reverting)
>
> - use cl-letf, and you've got an error:
> cl-letf: `let' bindings can have only one value-form: yes-or-no-p, (msg), t
>
> What should I do?

Use the NOCONFIRM of revert-buffer.

> Best regards,
> Seb

--

Jambunathan K

unread,
Oct 10, 2012, 9:18:15 AM10/10/12
to Help GNU Emacs

> Hello,
>
> `flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
>
> But doing so in the following code:
>
>
> (defun my/revert-buffer ()
> "Unconditionally revert current buffer."
> (interactive)
> (flet ((yes-or-no-p (msg) t))
> (revert-buffer)))
>
>
> does not lead to the right things:
>
> - use cl-flet, and the code doesn't behave as it should (i.e., it does ask for
> a confirmation, before reverting)
>
> - use cl-letf, and you've got an error:
> cl-letf: `let' bindings can have only one value-form: yes-or-no-p, (msg), t
>
> What should I do?

Use the NOCONFIRM argument of revert-buffer.

> Best regards,
> Seb

--

Barry Margolin

unread,
Oct 10, 2012, 10:31:18 AM10/10/12
to
In article <804nm2z...@somewhere.org>,
"Sebastien Vauban" <wxhgmq...@spammotel.com> wrote:

> Hello,
>
> `flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
>
> But doing so in the following code:
>
> --8<---------------cut here---------------start------------->8---
> (defun my/revert-buffer ()
> "Unconditionally revert current buffer."
> (interactive)
> (flet ((yes-or-no-p (msg) t))
> (revert-buffer)))
> --8<---------------cut here---------------end--------------->8---
>
> does not lead to the right things:
>
> - use cl-flet, and the code doesn't behave as it should (i.e., it does ask for
> a confirmation, before reverting)'

cl-flet does lexical binding, not dynamic.

>
> - use cl-letf, and you've got an error:
> cl-letf: `let' bindings can have only one value-form: yes-or-no-p, (msg), t
>
> What should I do?

Sounds like you didn't write your cl-letf correctly. Did you read its
documentation? It's not a drop-in replacement for flet, since it's more
general than this (it's used to temporarily assign to any place that can
be set with setf).

(letf (((symbol-function 'yes-or-no-p)
#'(lambda (msg) t)))
(revert-buffer))

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Sebastien Vauban

unread,
Oct 11, 2012, 4:04:21 AM10/11/12
to
Hi Jambunathan,

Jambunathan K wrote:
>> `flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
>>
>> But doing so in the following code:
>>
>> (defun my/revert-buffer ()
>> "Unconditionally revert current buffer."
>> (interactive)
>> (flet ((yes-or-no-p (msg) t))
>> (revert-buffer)))
>>
>> does not lead to the right things:
>> What should I do?
>
> Use the NOCONFIRM argument of revert-buffer.

I tried another way:

--8<---------------cut here---------------start------------->8---
(defun my/revert-buffer ()
"Unconditionally revert current buffer."
(interactive)
(let ((revert-without-query t))
(revert-buffer)))
--8<---------------cut here---------------end--------------->8---

but I don't understand why it does not work:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument listp t)
byte-code(" \304\211\205 \n@\305 \"\203

Tassilo Horn

unread,
Oct 11, 2012, 4:10:24 AM10/11/12
to help-gn...@gnu.org
"Sebastien Vauban"
<wxhgmq...@spammotel.com> writes:

>> Use the NOCONFIRM argument of revert-buffer.
>
> I tried another way:

What's wrong with NOCONFIRM?

> (defun my/revert-buffer ()
> "Unconditionally revert current buffer."
> (interactive)
> (let ((revert-without-query t))
> (revert-buffer)))
>
> but I don't understand why it does not work:
>
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument listp t)
> byte-code(" \304\211\205 \n@\305 \"\203

Because t is not a list. The docs clearly state that
`revert-without-query' has to be a list of regular expressions.

,----[ C-h v revert-without-query RET ]
| revert-without-query is a variable defined in `files.el'.
| Its value is nil
|
| Documentation:
| Specify which files should be reverted without query.
| The value is a list of regular expressions.
| If the file name matches one of these regular expressions,
| then `revert-buffer' reverts the file without querying
| if the file has changed on disk and you have not edited the buffer.
`----

Bye,
Tassilo


Jambunathan K

unread,
Oct 11, 2012, 4:17:34 AM10/11/12
to Help GNU Emacs
"Sebastien Vauban"
<wxhgmqzgwmuf-geNe...@public.gmane.org> writes:

> Hi Jambunathan,
>
> Jambunathan K wrote:
>>> `flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
>>>
>>> But doing so in the following code:
>>>
>>> (defun my/revert-buffer ()
>>> "Unconditionally revert current buffer."
>>> (interactive)
>>> (flet ((yes-or-no-p (msg) t))
>>> (revert-buffer)))
>>>
>>> does not lead to the right things:
>>> What should I do?
>>
>> Use the NOCONFIRM argument of revert-buffer.
>
> I tried another way:
>
>
> (defun my/revert-buffer ()
> "Unconditionally revert current buffer."
> (interactive)
> (let ((revert-without-query t))
> (revert-buffer)))
>
>
> but I don't understand why it does not work:
>
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument listp t)
> byte-code(" \304\211\205 \n@\305 \"\203
>

listp in above Lisp error gives a clue that a list is expected.

A describe variable confirms that it is indeed a list regexes. Regex is
a Emacs regex and NOT a shell-regex.

,----[ C-h v revert-without-query RET ]
| revert-without-query is a variable defined in `files.el'.
| Its value is nil
|
| Documentation:
| Specify which files should be reverted without query.
| The value is a list of regular expressions.
| If the file name matches one of these regular expressions,
| then `revert-buffer' reverts the file without querying
| if the file has changed on disk and you have not edited the buffer.
|
| You can customize this variable.
|
| [back]
`----


--

Drew Adams

unread,
Oct 11, 2012, 9:48:48 AM10/11/12
to Sebastien Vauban, help-gn...@gnu.org
> (defun my/revert-buffer ()
> "Unconditionally revert current buffer."
> (interactive)
> (let ((revert-without-query t)) (revert-buffer)))
>
> but I don't understand why it does not work:

Others have explained why it does not work.
Here's another way:

(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive) (revert-buffer t t))

(I bind it to `f5', in keeping with the MS Windows use of that key.)


Ludwig, Mark

unread,
Oct 11, 2012, 10:33:41 AM10/11/12
to Drew Adams, Sebastien Vauban, help-gn...@gnu.org
> -----Original Message-----
> From: Drew Adams
> Sent: Thursday, October 11, 2012 8:49 AM
> To: 'Sebastien Vauban'; help-gn...@gnu.org
> Subject: RE: flet is obsolete, but...
>
> (I bind [revert-buffer-no-confirm] to `f5', in keeping with the MS Windows use of that key.)

That's the best idea I've seen in a /long/ time. Why didn't /I/ think of that?!

Thanks!
Mark

Sebastien Vauban

unread,
Oct 11, 2012, 10:55:22 AM10/11/12
to
Hello all,
Thanks for your answers. It helped a lot, even if the above is still a bit
cryptic to me.

And, yes, I thought that the replacement was purely a syntaxical exchange of
words...

Drew Adams

unread,
Oct 11, 2012, 11:18:16 AM10/11/12
to Ludwig, Mark, Sebastien Vauban, help-gn...@gnu.org
> > (I bind [revert-buffer-no-confirm] to `f5', in keeping with
> > the MS Windows use of that key.)
>
> That's the best idea I've seen in a /long/ time.
> Why didn't /I/ think of that?!

You're welcome. Sometimes a trivial change can make a difference.

I must say that "wasting" an easy, repeatable key such as `f5' on this (as
opposed to binding it to a command that could take advantage of holding down the
key to repeat) goes against my general guidelines.

But in this case I made an exception because I already have the habit of using
it in Windows apps, so it is handy (for me).


0 new messages