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

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

Re: Failing to advice `require'


From: Sylvain Rousseau
Subject: Re: Failing to advice `require'
Date: Tue, 21 Aug 2012 11:19:05 +0200

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.

reply via email to

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