From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Failing to advice `require' Date: Tue, 21 Aug 2012 10:01:30 -0400 Organization: A noiseless patient Spider Message-ID: References: <80r4r18ttc.fsf@somewhere.org> <80zk5ou2r0.fsf@somewhere.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 X-Trace: ger.gmane.org 1345557919 4896 80.91.229.3 (21 Aug 2012 14:05:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Aug 2012 14:05:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 21 16:05:17 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T3p53-0002Jc-8r for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Aug 2012 16:05:17 +0200 Original-Received: from localhost ([::1]:59602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3p51-0003gC-IB for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Aug 2012 10:05:15 -0400 Original-Received: by 10.180.75.8 with SMTP id y8mr2464647wiv.4.1345557692009; Tue, 21 Aug 2012 07:01:32 -0700 (PDT) Original-Path: usenet.stanford.edu!7no33039924wig.0!news-out.google.com!n2ni243166941win.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!news.mixmin.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 129 Injection-Info: barmar.motzarella.org; posting-host="78fb7125a45724f15e21604c94a7d968"; logging-data="7479"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wr6ovaoTMHNwufhPxpCvG" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:SAB2Lqy8orKeUZeErHpl4WTTaHk= Original-Xref: usenet.stanford.edu gnu.emacs.help:194085 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:86451 Archived-At: In article <80zk5ou2r0.fsf@somewhere.org>, "Sebastien Vauban" wrote: > Hi Barry, > > Thanks for helping me... > > Barry Margolin wrote: > > In article <80r4r18ttc.fsf@somewhere.org>, > > "Sebastien Vauban" wrote: > >> > >> I tried to advice the require function, in order to get: > >> > >> - performance information (load time) > >> - call graph of `require' > >> > >> with the following code: > >> > >> (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? > > Right. > > >> (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). > > Not sure to understand, here, because I still want a global variable holding > the depth of the require calls. I'm not playing with a local variable, but > setting back and forth the value of the global var. Do I miss something? You can use 'let' to temporarily bind a global variable. This is a feature of dynamic scoping. > > >> (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)))) > >> > >> It works quite well, except for the following case: > >> > >> ;; (info) +-> Requiring `eieio'... already loaded [2 times] > >> ;; byte-code: eieio not found in `load-path' or gnus-fallback-lib/ > >> directory. > >> > >> 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; > > I did not think at that, yes... > > > 'prog1' is useful for this: > > > > (prog1 ad-do-it > > (message ...)) > > Hence my new version of the code: > > --8<---------------cut here---------------start------------->8--- > (defadvice require (around require-around activate) > "Leave a trace of packages being loaded." > (let ((feature (ad-get-arg 0)) > (prefix (concat (make-string (* 2 my/require-depth) ? ) "+-> > "))) > (setq my/require-depth (1+ my/require-depth)) > (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)) > (prog1 > 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--- > > Is the above what you suggested me to do? You're still not returning the feature name in the case where the feature is already loaded. > > However, with the above, I still have the same problem (here a little bit > more > trace): I don't really know if the above issue is related to the error you're getting. Maybe you should enable debugging. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***