* How to rescind a defun?
@ 2012-05-18 20:13 kj
2012-05-18 20:36 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: kj @ 2012-05-18 20:13 UTC (permalink / raw)
To: help-gnu-emacs
If, during an Emacs session, one evaluates a defun that (inadvertently)
redefines an existing function, is it possible to undo this?
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: How to rescind a defun?
2012-05-18 20:13 How to rescind a defun? kj
@ 2012-05-18 20:36 ` Drew Adams
[not found] ` <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>
2012-05-19 2:52 ` Pascal J. Bourguignon
2 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2012-05-18 20:36 UTC (permalink / raw)
To: 'kj', help-gnu-emacs
> If, during an Emacs session, one evaluates a defun that
> (inadvertently) redefines an existing function, is it
> possible to undo this?
See function `fmakunbound'.
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>]
* Re: How to rescind a defun?
[not found] ` <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>
@ 2012-05-18 21:49 ` kj
2012-05-18 22:09 ` Drew Adams
2012-05-18 22:16 ` Barry Margolin
1 sibling, 1 reply; 6+ messages in thread
From: kj @ 2012-05-18 21:49 UTC (permalink / raw)
To: help-gnu-emacs
In <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org> "Drew Adams" <drew.adams@oracle.com> writes:
>> If, during an Emacs session, one evaluates a defun that
>> (inadvertently) redefines an existing function, is it
>> possible to undo this?
>See function `fmakunbound'.
Thanks, I would have never found this!
Unfortunately, it seems that the original definition is gone. (I
had hoped that the new definition was just shadowing the original
one, so that rescinding the former would "resurrect" the latter.)
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: How to rescind a defun?
2012-05-18 21:49 ` kj
@ 2012-05-18 22:09 ` Drew Adams
0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2012-05-18 22:09 UTC (permalink / raw)
To: 'kj', help-gnu-emacs
> >> If, during an Emacs session, one evaluates a defun that
> >> (inadvertently) redefines an existing function, is it
> >> possible to undo this?
>
> > See function `fmakunbound'.
>
> Thanks, I would have never found this!
>
> Unfortunately, it seems that the original definition is gone. (I
> had hoped that the new definition was just shadowing the original
> one, so that rescinding the former would "resurrect" the latter.)
I see now what you meant by "undo".
No, within a given namespace (obarray) and a given program scope (e.g. `flet' or
`labels' binding), a symbol has only one function definition.
And for a global function definition, assignment is used, not binding. So there
is no shadowing.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to rescind a defun?
[not found] ` <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>
2012-05-18 21:49 ` kj
@ 2012-05-18 22:16 ` Barry Margolin
1 sibling, 0 replies; 6+ messages in thread
From: Barry Margolin @ 2012-05-18 22:16 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>,
"Drew Adams" <drew.adams@oracle.com> wrote:
> > If, during an Emacs session, one evaluates a defun that
> > (inadvertently) redefines an existing function, is it
> > possible to undo this?
>
> See function `fmakunbound'.
That will remove the new definition, but not restore the old one.
The only way to do that is to find the old definition and evaluate it.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to rescind a defun?
2012-05-18 20:13 How to rescind a defun? kj
2012-05-18 20:36 ` Drew Adams
[not found] ` <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>
@ 2012-05-19 2:52 ` Pascal J. Bourguignon
2 siblings, 0 replies; 6+ messages in thread
From: Pascal J. Bourguignon @ 2012-05-19 2:52 UTC (permalink / raw)
To: help-gnu-emacs
kj <no.email@please.post> writes:
> If, during an Emacs session, one evaluates a defun that (inadvertently)
> redefines an existing function, is it possible to undo this?
If you do that a lot, you could implement defun to do that.
(require 'cl)
(setf (symbol-function 'emacs-defun) (symbol-function 'defun))
(defmacro defun (name lambda-list &rest body)
`(progn
(when (fboundp ',name)
(push (symbol-function ',name) (get ',name 'old-defuns)))
(emacs-defun ,name ,lambda-list ,@body)))
(defun pop-defun* (name)
(setf (symbol-function name) (pop (get name 'old-defuns))))
(defmacro pop-defun (name)
`(pop-defun* ',name))
(defun f () 42)
(f) --> 42
(defun f () 33)
(f) --> 33
(pop-defun f)
(f) --> 42
Now of course you need to define that early, and load all the libraries
after it, so that they use your defun instead of the native emacs-defun.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-19 2:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-18 20:13 How to rescind a defun? kj
2012-05-18 20:36 ` Drew Adams
[not found] ` <mailman.1365.1337373409.855.help-gnu-emacs@gnu.org>
2012-05-18 21:49 ` kj
2012-05-18 22:09 ` Drew Adams
2012-05-18 22:16 ` Barry Margolin
2012-05-19 2:52 ` Pascal J. Bourguignon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).