From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sylvain Rousseau Newsgroups: gmane.emacs.help Subject: Re: Failing to advice `require' Date: Tue, 21 Aug 2012 11:19:05 +0200 Message-ID: References: <80r4r18ttc.fsf@somewhere.org> <80zk5ou2r0.fsf@somewhere.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d0401fe592608c304c7c31ea1 X-Trace: ger.gmane.org 1345540758 22085 80.91.229.3 (21 Aug 2012 09:19:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Aug 2012 09:19:18 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Sebastien Vauban Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 21 11:19:19 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 1T3kcF-000098-TY for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Aug 2012 11:19:16 +0200 Original-Received: from localhost ([::1]:34183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3kcE-0001eR-5C for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Aug 2012 05:19:14 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:32826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3kc8-0001eK-IJ for help-gnu-emacs@gnu.org; Tue, 21 Aug 2012 05:19:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3kc7-0006sT-6D for help-gnu-emacs@gnu.org; Tue, 21 Aug 2012 05:19:08 -0400 Original-Received: from mail-lpp01m010-f41.google.com ([209.85.215.41]:60665) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3kc6-0006s7-Ue for help-gnu-emacs@gnu.org; Tue, 21 Aug 2012 05:19:07 -0400 Original-Received: by lahd3 with SMTP id d3so3846088lah.0 for ; Tue, 21 Aug 2012 02:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZrSPBuCJRF3ZZDDAJlqFgh1Aeb0C2qbcGqRmVbBocZY=; b=A/6EDnHWi+sAuHZPRBS/t0+8Jp8B+JoeuIxMpnJI+fD1An+1eHlMqeK1oGf362CMZA 2OreFviawMQq5/wrJUclscYsIJXNhEsy9GU8U/FJmJY+WwAVccIFeEfq6/zPoDl2c7i7 Hnwr5mJdgxBGAb/bEW7YcK9XMtY7K9QCntqhiDQbJl2az9alQ7TYgtFsYpXY9girFUXs FXBuWV+D86gTtaNxpiV0/llo9iFogfSxlW87f/hIBYHGEKn1gwe9evVFwQ/FZdmou+iG ZFDRnj2zHk3hn+fK98e7zZnDhrBxmhKXxhPEEC+Q8YRyTMeJ5KxY0U4TtcgzZH4k9ecj i/3Q== Original-Received: by 10.112.50.106 with SMTP id b10mr634358lbo.51.1345540745201; Tue, 21 Aug 2012 02:19:05 -0700 (PDT) Original-Received: by 10.114.23.232 with HTTP; Tue, 21 Aug 2012 02:19:05 -0700 (PDT) In-Reply-To: <80zk5ou2r0.fsf@somewhere.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.215.41 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:86447 Archived-At: --f46d0401fe592608c304c7c31ea1 Content-Type: text/plain; charset=ISO-8859-1 The adviced require still not has the right signature, in the case ad-do-it is not called, you have to set the return value yourself! (setq ad-return-value feature) in your case. You can also get rid of the defvar but it's a little far fetched. Here is what I come up with: (defadvice require (around require-around) "Leave a trace of packages being loaded." (let* ((feature (ad-get-arg 0)) (require-depth (or (and (boundp 'require-depth) require-depth) 0)) (prefix (concat (make-string (* 2 require-depth) ? ) "+-> "))) (cond ((featurep feature) (message "(info) %sRequiring `%s'... already loaded" prefix feature) (setq ad-return-value feature)) (t (let ((my/time-start)) (message "(info) %sRequiring `%s'..." prefix feature) (setq my/time-start (float-time)) (let ((require-depth (1+ require-depth))) ad-do-it) (message "(info) %sRequiring `%s'... %s (loaded in %.2f s)" prefix feature (locate-library (symbol-name feature)) (- (float-time) my/time-start))))))) (ad-activate 'require) Anyway, very useful advice! Let me know if it works with this version. --f46d0401fe592608c304c7c31ea1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The adviced require still not has the right signature, in the case ad-do-it= is not called, you have to set the return value yourself!

=A0 (setq= ad-return-value feature)

in your case.

You can also get rid = of the defvar but it's a little far fetched. Here is what I come up wit= h:

=A0 (defadvice require (around require-around)
=A0=A0=A0 "Leave= a trace of packages being loaded."
=A0=A0=A0 (let* ((feature (ad-g= et-arg 0))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (require-depth (or (and (bound= p 'require-depth) require-depth) 0))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (prefix (concat (make-string (* 2 require-de= pth) ? ) "+-> ")))
=A0=A0=A0=A0=A0 (cond ((featurep feature= )
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (message "(info) %sRequiring= `%s'... already loaded"
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 prefix feature)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (setq ad-return-value feature))
=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (t
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (= let ((my/time-start))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (messag= e "(info) %sRequiring `%s'..." prefix feature)
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (setq my/time-start (float-time))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (let ((require-depth (1+ require= -depth)))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ad-do-it)
= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (message "(info) %sRequirin= g `%s'... %s (loaded in %.2f s)"
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 prefix feature
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (loca= te-library (symbol-name feature))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (- (float-time) my/time-start)))))))
= =A0
=A0 (ad-activate 'require)

Anyway, very useful advice! L= et me know if it works with this version.
--f46d0401fe592608c304c7c31ea1--