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

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

Re: flet is obsolete, but...


From: Barry Margolin
Subject: Re: flet is obsolete, but...
Date: Wed, 10 Oct 2012 10:31:18 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <804nm2zekk.fsf@somewhere.org>,
 "Sebastien Vauban" <wxhgmqzgwmuf@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, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

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