all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: flet is obsolete, but...
Date: Wed, 10 Oct 2012 10:31:18 -0400	[thread overview]
Message-ID: <barmar-210B15.10311810102012@news.eternal-september.org> (raw)
In-Reply-To: 804nm2zekk.fsf@somewhere.org

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


  parent reply	other threads:[~2012-10-10 14:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-10 12:39 flet is obsolete, but Sebastien Vauban
2012-10-10 13:17 ` Jambunathan K
2012-10-10 13:18 ` Jambunathan K
2012-10-10 14:31 ` Barry Margolin [this message]
2012-10-11 14:55   ` Sebastien Vauban
     [not found] ` <mailman.10697.1349875031.855.help-gnu-emacs@gnu.org>
2012-10-11  8:04   ` Sebastien Vauban
2012-10-11  8:10     ` Tassilo Horn
2012-10-11  8:17     ` Jambunathan K
2012-10-11 13:48     ` Drew Adams
2012-10-11 14:33       ` Ludwig, Mark
2012-10-11 15:18         ` `f5' for refreshing/reverting without confirmation [was: flet is obsolete, but...] Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=barmar-210B15.10311810102012@news.eternal-september.org \
    --to=barmar@alum.mit.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.