GNU bug report logs -
#12895
24.3.50; Replacement for flet
Previous Next
Reported by: Antoine Levitt <antoine.levitt <at> gmail.com>
Date: Thu, 15 Nov 2012 13:37:02 UTC
Severity: normal
Tags: notabug
Found in version 24.3.50
Done: Marcin Borkowski <mbork <at> mbork.pl>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12895 in the body.
You can then email your comments to 12895 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 13:37:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Antoine Levitt <antoine.levitt <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 15 Nov 2012 13:37:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
I'm trying to dynamically bind a function, and used flet
previously. flet is now apparently obsolete. The docstring suggests
using cl-flet. But cl-flet does lexical binding, not dynamic. How do I
get the old behavior (dynamic binding) without using the now-obsolete
flet? I'm confused by the number of subtly different functions to do the
same thing - letf, flet, labels, cl-labels, cl-letf, cl-flet - and find
the docstrings to be unclear. If I understand correctly, letf is what I
need, but the following does not do what I expect it to (ie suppress the
message)
(defun something ()
(message "hi"))
(letf ((message (lambda () (&rest args) nil)))
(something))
Is this because message is a built-in?
Sorry if this has been covered elsewhere, I couldn't find it.
Antoine
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 14:48:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 12895 <at> debbugs.gnu.org (full text, mbox):
> (defun something ()
> (message "hi"))
> (letf ((message (lambda () (&rest args) nil)))
> (something))
> Is this because message is a built-in?
No, it's because what you want is not a local function, but an override
of an existing function. Such override should be done with an advice.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 15:03:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 12895 <at> debbugs.gnu.org (full text, mbox):
11/15/2012 15:46, Stefan Monnier
>> (defun something ()
>> (message "hi"))
>> (letf ((message (lambda () (&rest args) nil)))
>> (something))
>> Is this because message is a built-in?
>
> No, it's because what you want is not a local function, but an override
> of an existing function.
Ah, sorry. Letf redirects to cl-letf, which says
Temporarily bind to PLACEs. This is the analogue of `let', but with
generalized variables
If it excludes overrides, I think it should say so explicitely. Right
now I'm led to think it's like let for functions, and I've been using
let for overriding just fine.
> Such override should be done with an advice.
Unless I'm missing something easier, using an advice would be cumbersome
(define the advice, activate it, run the function, then deactivate the
advice, protecting for errors). Would you consider un-obsoleting flet?
It isn't deprecated by either cl-flet or cl-letf.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 18:37:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 12895 <at> debbugs.gnu.org (full text, mbox):
tags 12895 notabug
thanks
> Temporarily bind to PLACEs. This is the analogue of `let', but with
> generalized variables
> If it excludes overrides, I think it should say so explicitely. Right
> now I'm led to think it's like let for functions, and I've been using
> let for overriding just fine.
letf and cl-letf do not exclude overrides: it only does overrides
(well, pretty much, except if PLACE is a variable, in which case it's
just like a let).
But, indeed, the docstring of cl-flet was wrong since it said "Make
temporary function definitions" whereas these are not temporarily but local.
I just fixed it now, thank you.
>> Such override should be done with an advice.
> Unless I'm missing something easier, using an advice would be cumbersome
> (define the advice, activate it, run the function, then deactivate the
> advice, protecting for errors). Would you consider un-obsoleting flet?
> It isn't deprecated by either cl-flet or cl-letf.
Overriding a function is bad. It can mess things up and throw you
majorly off-course when debugging the problem. So it's good if
it's cumbersome.
Check my recent patch to js.el to see how I replaced flet with advices.
Stefan
Added tag(s) notabug.
Request was from
Stefan Monnier <monnier <at> iro.umontreal.ca>
to
control <at> debbugs.gnu.org
.
(Thu, 15 Nov 2012 18:37:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 22:44:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 12895 <at> debbugs.gnu.org (full text, mbox):
11/15/2012 19:35, Stefan Monnier
>>> Such override should be done with an advice.
>> Unless I'm missing something easier, using an advice would be cumbersome
>> (define the advice, activate it, run the function, then deactivate the
>> advice, protecting for errors). Would you consider un-obsoleting flet?
>> It isn't deprecated by either cl-flet or cl-letf.
>
> Overriding a function is bad. It can mess things up and throw you
> majorly off-course when debugging the problem.
So are advices. I have lots of flet in my .emacs, usually to suppress
messages from functions which are defined elsewhere. For instance,
(defun my-org-agenda-to-appt ()
(interactive)
(flet ((message (&rest args) ))
(org-agenda-to-appt)))
The point is I do not want to redefine org-agenda-to-appt, because I
don't want to have to maintain a parallel copy of it. To get away with
it without too much effort, I'm just going to have to redefine flet
without the obsolete part in my .emacs, which is suboptimal.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 23:06:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 12895 <at> debbugs.gnu.org (full text, mbox):
Antoine Levitt wrote:
> I have lots of flet in my .emacs, usually to suppress messages from
> functions which are defined elsewhere.
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12849
may interest you then.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 23:26:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 12895 <at> debbugs.gnu.org (full text, mbox):
11/16/2012 00:05, Glenn Morris
> Antoine Levitt wrote:
>
>> I have lots of flet in my .emacs, usually to suppress messages from
>> functions which are defined elsewhere.
>
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12849
>
> may interest you then.
Ah, nice. But I don't want to prevent messages from going to the
*Messages* buffer, I want to prevent them from appearing in the
minibuffer. For instance, I use this to automatically save the desktop
without being bothered by it
(run-with-timer (* 10 60) (* 10 60)
(lambda ()
(flet ((message (&rest args) nil))
(desktop-save-in-desktop-dir))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 23:46:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 12895 <at> debbugs.gnu.org (full text, mbox):
Antoine Levitt wrote:
> But I don't want to prevent messages from going to the *Messages*
> buffer, I want to prevent them from appearing in the minibuffer.
[...]
> (flet ((message (&rest args) nil))
? But this _does_ prevent messages from going to the *Messages* buffer,
as well as to the echo area. And so does binding message-log-max to nil.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 23:49:01 GMT)
Full text and
rfc822 format available.
Message #31 received at 12895 <at> debbugs.gnu.org (full text, mbox):
11/16/2012 00:44, Glenn Morris
> Antoine Levitt wrote:
>
>> But I don't want to prevent messages from going to the *Messages*
>> buffer, I want to prevent them from appearing in the minibuffer.
> [...]
>> (flet ((message (&rest args) nil))
>
>
> ? But this _does_ prevent messages from going to the *Messages* buffer,
> as well as to the echo area. And so does binding message-log-max to nil.
Sorry if I wasn't clear. I don't care about the *Messages* buffer. What
I do care about is the echo area. Binding message-log-max to nil only
affects logging, not the displaying of the message.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Thu, 15 Nov 2012 23:53:01 GMT)
Full text and
rfc822 format available.
Message #34 received at 12895 <at> debbugs.gnu.org (full text, mbox):
Antoine Levitt wrote:
> Sorry if I wasn't clear. I don't care about the *Messages* buffer. What
> I do care about is the echo area. Binding message-log-max to nil only
> affects logging, not the displaying of the message.
My fault, I was misunderstanding things.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Fri, 16 Nov 2012 01:22:01 GMT)
Full text and
rfc822 format available.
Message #37 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
> I'm trying to dynamically bind a function, and used flet
> previously. flet is now apparently obsolete. The docstring suggests
> using cl-flet. But cl-flet does lexical binding, not dynamic. How do I
> get the old behavior (dynamic binding) without using the now-obsolete
> flet? I'm confused by the number of subtly different functions to do the
> same thing - letf, flet, labels, cl-labels, cl-letf, cl-flet - and find
> the docstrings to be unclear. If I understand correctly, letf is what I
> need, but the following does not do what I expect it to (ie suppress the
> message)
No general answer to your question, but something like this my be good
enough for what you want:
(defmacro suppressing-messages (&rest body)
`(let (message-log-max)
(with-temp-message ""
,@body)))
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Fri, 16 Nov 2012 07:06:02 GMT)
Full text and
rfc822 format available.
Message #40 received at 12895 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier wrote:
> Such override should be done with an advice.
But why I haven't yet replaced flet used in
message-read-from-minibuffer is that I don't yet have a solution
better than this:
(flet ((mail-abbrev-in-expansion-header-p nil t))
(read-from-minibuffer prompt initial-contents))
;; This makes mail-abbrev-expand work even in a minibuffer, not
;; in a message header.
Not only this, there will probably be lots of situations where
flet is handy to use. Here's the one I've implemented in a
certain package so as to silence the byte compiler:
(defmacro my-flet (bindings &rest body)
"Make temporary overriding function definitions.
\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
`(let (fn origs)
(dolist (bind ',bindings)
(setq fn (car bind))
(push (cons fn (and (fboundp fn) (symbol-function fn))) origs)
(fset fn (cons 'lambda (cdr bind))))
(unwind-protect
(progn ,@body)
(dolist (orig origs)
(if (cdr orig)
(fset (car orig) (cdr orig))
(fmakunbound (car orig)))))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Fri, 16 Nov 2012 14:35:02 GMT)
Full text and
rfc822 format available.
Message #43 received at 12895 <at> debbugs.gnu.org (full text, mbox):
> But why I haven't yet replaced flet used in
> message-read-from-minibuffer is that I don't yet have a solution
> better than this:
> (flet ((mail-abbrev-in-expansion-header-p nil t))
> (read-from-minibuffer prompt initial-contents))
How 'bout
(defadvice mail-abbrev-in-expansion-header-p (around t-in-minibuffer activate)
(if (minibufferp) (setq ad-return-value t) ad-do-it))
Or how 'bout filing a feature request?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Fri, 16 Nov 2012 14:36:01 GMT)
Full text and
rfc822 format available.
Message #46 received at 12895 <at> debbugs.gnu.org (full text, mbox):
>> Overriding a function is bad. It can mess things up and throw you
>> majorly off-course when debugging the problem.
> So are advices.
But advices are much more visible (e.g. they appear in C-h f).
> I have lots of flet in my .emacs, usually to suppress
> messages from functions which are defined elsewhere. For instance,
So you need just one advice that adds an `inhibit-message' variable and
then you can let-bind this variable wherever you used flet message.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Fri, 16 Nov 2012 14:50:02 GMT)
Full text and
rfc822 format available.
Message #49 received at 12895 <at> debbugs.gnu.org (full text, mbox):
11/16/2012 15:34, Stefan Monnier
>>> Overriding a function is bad. It can mess things up and throw you
>>> majorly off-course when debugging the problem.
>> So are advices.
>
> But advices are much more visible (e.g. they appear in C-h f).
>
>> I have lots of flet in my .emacs, usually to suppress
>> messages from functions which are defined elsewhere. For instance,
>
> So you need just one advice that adds an `inhibit-message' variable and
> then you can let-bind this variable wherever you used flet message.
Ah, I didn't see that's what you were doing in js.el. Fair enough, I'll
do that, thanks!
I did like flet, though, and in general, I think it's annoying to users
to remove/deprecate functionality that are neat ways to get inside lisp
code from outside (dynamic-scoping overrides, advices, etc.) just
because they are bad practice and make debugging harder. Some of us are
quite happy not modifying emacs source code but hacking into it from the
comfort of our .emacs. But I do understand your reasons for obsoleting
it.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Fri, 16 Nov 2012 15:26:01 GMT)
Full text and
rfc822 format available.
Message #52 received at 12895 <at> debbugs.gnu.org (full text, mbox):
> I did like flet, though, and in general, I think it's annoying to
> users to remove/deprecate functionality that are neat ways to get
> inside lisp code from outside (dynamic-scoping overrides, advices,
> etc.) just because they are bad practice and make debugging harder.
The problem with flet is not only that it's doing dangerous things but
also that it's used in code that does not need those dangerous things.
And do not that it was not removed. It was just marked obsolete.
The main purpose of this obsolescence warning is to change the coding
style so that overrides are used explicitly where they're needed and
non-overriding local definitions are used where the override is not
needed, so the code is more clear.
Advising is definitely not on the way out. I even just added a new
lighter weight advice package.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Sun, 31 Jan 2016 14:20:02 GMT)
Full text and
rfc822 format available.
Message #55 received at 12895 <at> debbugs.gnu.org (full text, mbox):
Hi all,
just asking: should this "bug report" (which is clearly not a bug report
per se) be closed?
Best,
--
Marcin Borkowski
http://mbork.pl/en
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Sun, 31 Jan 2016 16:52:02 GMT)
Full text and
rfc822 format available.
Message #58 received at 12895 <at> debbugs.gnu.org (full text, mbox):
> From: Marcin Borkowski <mbork <at> mbork.pl>
> Date: Sun, 31 Jan 2016 15:19:12 +0100
>
> just asking: should this "bug report" (which is clearly not a bug report
> per se) be closed?
Yes, please.
Thanks.
Reply sent
to
Marcin Borkowski <mbork <at> mbork.pl>
:
You have taken responsibility.
(Sun, 31 Jan 2016 17:11:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Antoine Levitt <antoine.levitt <at> gmail.com>
:
bug acknowledged by developer.
(Sun, 31 Jan 2016 17:11:02 GMT)
Full text and
rfc822 format available.
Message #63 received at 12895-done <at> debbugs.gnu.org (full text, mbox):
On 2016-01-31, at 17:51, Eli Zaretskii <eliz <at> gnu.org> wrote:
>> From: Marcin Borkowski <mbork <at> mbork.pl>
>> Date: Sun, 31 Jan 2016 15:19:12 +0100
>>
>> just asking: should this "bug report" (which is clearly not a bug report
>> per se) be closed?
>
> Yes, please.
>
> Thanks.
Closing (it's not a bug).
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Sun, 31 Jan 2016 17:48:02 GMT)
Full text and
rfc822 format available.
Message #66 received at 12895 <at> debbugs.gnu.org (full text, mbox):
Antoine Levitt <antoine.levitt <at> gmail.com> writes:
> I did like flet, though, and in general, I think it's annoying to users
> to remove/deprecate functionality that are neat ways to get inside lisp
> code from outside (dynamic-scoping overrides, advices, etc.) just
> because they are bad practice and make debugging harder.
BTW, let me add to the (valid) warnings that this can still be achieved
with cl-letf:
(cl-letf (((symbol-function 'some-function) #'some-other-function))
code...)
The created binding to the symbol-function place is dynamical.
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#12895
; Package
emacs
.
(Tue, 09 Feb 2016 20:37:02 GMT)
Full text and
rfc822 format available.
Message #69 received at 12895 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
That does the trick, thanks for taking the time to respond to such an old
bug report :-)
On 31 January 2016 at 18:42, Michael Heerdegen <michael_heerdegen <at> web.de>
wrote:
> Antoine Levitt <antoine.levitt <at> gmail.com> writes:
>
> > I did like flet, though, and in general, I think it's annoying to users
> > to remove/deprecate functionality that are neat ways to get inside lisp
> > code from outside (dynamic-scoping overrides, advices, etc.) just
> > because they are bad practice and make debugging harder.
>
> BTW, let me add to the (valid) warnings that this can still be achieved
> with cl-letf:
>
> (cl-letf (((symbol-function 'some-function) #'some-other-function))
> code...)
>
> The created binding to the symbol-function place is dynamical.
>
>
> Michael.
>
[Message part 2 (text/html, inline)]
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 09 Mar 2016 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 9 years and 106 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.