From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Redefining functions and variables
Date: Wed, 28 Jul 2010 02:35:03 +0200 [thread overview]
Message-ID: <876300fnpk.fsf@fh-trier.de> (raw)
In-Reply-To: 76fd4dc4-a964-4629-90e2-329e1b83fd8d@h25g2000vba.googlegroups.com
Elena <egarrulo@gmail.com> writes:
> On 27 Lug, 22:21, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
>> > I wonder whether there is a way to catch such redefinitions whenever
>> > they happen (which also would help when accidentally redefining
>> > something)
>>
>> Not sure what you mean by that.
>
> Let's assume we have two definitions for the same function:
>
> ;; File A (loaded first)
> (defun foo ()
> ...
>
> ;; File B (loaded later)
> (defun foo () ;; This is a redefinition: I'd like to get a warning.
> ...
>
> Since redefining functions is the heart of interactive programming,
> such a warning should be issued only while loading files. That way,
> you could consider whether to rename the second function or to rewrite
> it as an advice (as you suggested).
>
I think `defun' does not take no advice.
> If such a goal can only be achieved by rewriting "defun" and checking
> by means of "fboundp" whether the function has already been defined,
> here is my (failed, as noted) attempt:
>
> (defmacro defun (name args &rest body)
> `(progn
> ;; `load-file-name' is not null only if we are loading a file.
> (when (and load-file-name
> ;; FAIL: I don't know how to quote the value of `name'.
> (fboundp ,name))
(fboundp ',name))
Why not use `quote'.
> (message "Warning: %s is being redefined in %s."
> ;; FAIL: I don't know how to quote the value of `name'.
> (symbol-name ,name)
> load-file-name)
> (defun ,name ,args
Of course this leads to an endless recursive loop, expanding your macro
again and again ...
(funcall (symbol-function 'defun) 'foo nil)
does not seem to work either, which would mean that you can't save
`defun's definition.
>
> ,@body))))
>
> Any suggestions? Thanks.
-ap
next prev parent reply other threads:[~2010-07-28 0:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-27 15:12 Redefining functions and variables Elena
2010-07-27 20:21 ` Stefan Monnier
2010-07-27 22:16 ` Elena
2010-07-28 0:35 ` Andreas Politz [this message]
2010-07-28 7:51 ` Elena
2010-07-28 14:29 ` Elena
2010-07-28 18:48 ` Andreas Politz
2010-07-28 20:37 ` Pascal J. Bourguignon
2010-07-29 8:32 ` Elena
2010-07-29 9:57 ` Stefan Monnier
2010-07-29 10:16 ` Elena
2010-07-29 13:14 ` Stefan Monnier
2010-07-30 19:32 ` Uday S Reddy
2010-07-29 10:31 ` Andreas Politz
2010-07-29 11:46 ` Johan Bockgård
2010-07-29 15:54 ` Andreas Politz
2010-07-29 12:41 ` Tim X
2010-07-29 10:03 ` Pascal J. Bourguignon
2010-07-29 10:28 ` Elena
2010-07-29 20:35 ` Johan Bockgård
2010-07-29 22:22 ` Tim X
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=876300fnpk.fsf@fh-trier.de \
--to=politza@fh-trier.de \
--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.
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).