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

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

Re: Catching redefinitions


From: Elena
Subject: Re: Catching redefinitions
Date: Sat, 27 Nov 2010 14:40:38 -0800 (PST)
User-agent: G2/1.0

On Nov 26, 3:09 pm, Elena <egarr...@gmail.com> wrote:
> Hello,
>
> some time ago, I asked about catching functions redefinitions for
> troubleshooting both .emacs and third-party packages.  Thanks to those
> who answered, I've been able to write some code to accomplish such
> goal.  Here it is:
>
> (defadvice defun (before redefinition-warning (name arglist docstring
> &rest body) activate)
>                         "Checks whether `name' has already been defined as 
> function.
>                         If so, output debugging information to a dedicated 
> buffer."
>         (let ((name (ad-get-arg 0)))
>                         ;; We are only looking for redefinition happening 
> into loaded
> files,
>                         ;; since users must be allowed to redefine functions 
> interactively.
>                         (when (and load-file-name
>                                            (fboundp name))
>                                 (with-current-buffer (get-buffer-create 
> "*Redefinitions*")
>                                         (insert (format "
>
> FUNCTION:  %s
> ORIGINAL FILE:  %s
> REDEFINITION FILE: %s"
>                                                                         name
>                                                                         
> (find-lisp-object-file-name name (symbol-function name))
>                                                                         
> (abbreviate-file-name load-file-name)))))))
>
> This advice works, but it chokes on `define-slime-contrib'.  Can
> anyone check it?  Thanks.

It turned out some packages were defining function like this:

(defun f nil)

Thus, changing defun's arguments list from:

 (name arglist docstring &rest body)

to:

 (name arglist &rest docstring body)

made things work.  This code has catched quite a bit of redefinitions
in packages loaded by my init file.  I'm seeing some warnings about
functions being redefined in the same files, which I think depend on
autoloads.

It would be nice to have such a debugging aid for variables too.
Writing a similar advice for "defvar", "defconst", etc. is easy, but I
don't know how the argument list of "setq" looks like.


reply via email to

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