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: Failing to advice `require'
Date: Mon, 20 Aug 2012 20:12:06 -0400	[thread overview]
Message-ID: <barmar-3DACA1.20120620082012@news.eternal-september.org> (raw)
In-Reply-To: 80r4r18ttc.fsf@somewhere.org

In article <80r4r18ttc.fsf@somewhere.org>,
 "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> wrote:

> Hello,
> 
> I tried to advice the require function, in order to get:
> 
> - performance information (load time)
> - call graph of `require'
> 
> with the following code:
> 
> --8<---------------cut here---------------start------------->8---
>   (defvar my/require-depth 0)
> 
>   (defadvice require (around require-around activate)
>     "Leave a trace of packages being loaded."
>     (let ((feature (ad-get-arg 0))
>           (filename (ad-get-arg 1))
>           (noerror (ad-get-arg 2))

You never use filename or noerror, why do you bother binding them?

>           (prefix (concat (make-string (* 2 my/require-depth) ? ) "+-> ")))
>       (setq my/require-depth (1+ my/require-depth))

You should bind my/require-depth in your 'let'. Then you don't need to 
restore it at the end, it will happen automatically (including if 
there's an error that aborts out).

>       (cond ((featurep feature)
>              (message "(info) %sRequiring `%s'... already loaded"
>                       prefix feature)
>              )
>             (t
>              (let ((my/time-start))
>                (message "(info) %sRequiring `%s'..." prefix feature)
>                (setq my/time-start (float-time))
>                ad-do-it
>                (message "(info) %sRequiring `%s'... %s (loaded in %.2f s)"
>                         prefix feature
>                         (locate-library (symbol-name feature))
>                         (- (float-time) my/time-start))
>                )))
>       (setq my/require-depth (1- my/require-depth))))
> --8<---------------cut here---------------end--------------->8---

> 
> It works quite well, except for the following case:
> 
> --8<---------------cut here---------------start------------->8---
> ;; Requiring `auth-source'...
> ;; (info)  +-> Requiring `password-cache'... 
> d:/home/sva/Downloads/emacs/site-lisp/gnus/lisp/password-cache.elc (loaded in 
> 0.11 s)
> ;; (info)  +-> Requiring `mm-util'... already loaded
> ;; (info)  +-> Requiring `gnus-util'... already loaded
> ;; (info)  +-> Requiring `eieio'... already loaded [2 times]
> ;; byte-code: eieio not found in `load-path' or gnus-fallback-lib/ directory.
> --8<---------------cut here---------------end--------------->8---
> 
> Guess what? `eieio' is in my default load path, in my GNU Emacs 24.1.1
> (i386-mingw-nt5.1.2600) of 2012-06-02 on MARVIN on Windows XP.
> 
> Do you have any idea why it's failing?

The real require returns the feature name, or nil if the package is not 
found and noerror is set, yours returns various other things. You need 
to ensure that you return the correct thing; 'prog1' is useful for this:

(prog1 ad-do-it
       (message ...))

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


  reply	other threads:[~2012-08-21  0:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-20 15:30 Failing to advice `require' Sebastien Vauban
2012-08-21  0:12 ` Barry Margolin [this message]
2012-08-21  7:24   ` Sebastien Vauban
2012-08-21  9:19     ` Sylvain Rousseau
2012-08-21 14:01     ` Barry Margolin

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-3DACA1.20120620082012@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.