From mboxrd@z Thu Jan 1 00:00:00 1970 From: Achim Gratz Subject: bug#10125: RFE: require and load-path-shadowing Date: Sat, 12 Jan 2013 11:15:40 +0100 Message-ID: <87ip72n1v7.fsf@Rainer.invalid> References: <87sj68eogm.fsf@Rainer.invalid> <87wqvjd7qa.fsf@Rainer.invalid> <87bocvcx9f.fsf__44551.6247455545$1357934081$gmane$org@Rainer.invalid> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:36133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtyxL-0008Ll-Bm for emacs-orgmode@gnu.org; Sat, 12 Jan 2013 06:08:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TtyxG-0000rV-G5 for emacs-orgmode@gnu.org; Sat, 12 Jan 2013 06:08:55 -0500 In-Reply-To: <81pqgh90sp.fsf@gmail.com> Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-Message-ID: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: 10125@debbugs.gnu.org Achim Gratz writes: > Stefan Monnier writes: >> Yes, this subroutine is never directly called from C, so placing an >> advice should work just fine. > > OK, I'll give it a try. Here's what I've come up with: --8<---------------cut here---------------start------------->8--- ;; some parts of Org might already have been used from a different ;; place, try to reload these parts from the current load-path (defadvice require (before org-require-reload-when-shadowed (feature &optional filename noerror) activate compile preactivate) "Check whether a required feature has been shadowed by changing `load-path' after it has been loaded and reload that feature from current load-path in this case." (when (featurep feature) (let ((feature-name (or filename (symbol-name feature)))) (when (string-match "^\\(org\\|ob\\)[.-]" feature-name) (let ((feature-lib (file-name-directory (or (locate-library feature-name) ""))) (feature-dir (file-name-directory (feature-file feature)))) ;(message "require-reload-when shadowed %s\n\t%s\n\t%s" feature-name feature-lib feature-dir) (when (not (string= feature-lib feature-dir)) (message "Reloading %s" feature-name) (unload-feature feature t))))))) (require 'org-macs) (require 'org-compat) (require 'org-entities) (require 'org-faces) (require 'org-list) (require 'org-pcomplete) (require 'org-src) (require 'org-footnote) ;; babel (require 'ob) (eval-and-compile (ad-unadvise 'require)) --8<---------------cut here---------------end--------------->8--- This takes care of a situation when Org is activated after some parts of it have already been loaded (maybe via autoload) and the load-path has been changed inbetween. This uses unload-feature although it would probably work to just (setq features (delq feature features)). For package manager, a slightly more general version of the above (not conditionalized on the feature starting with "org" or "ob") could be used around the package compilation. I haven't yet tried this, though. Regards, Achim. -- +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ Wavetables for the Waldorf Blofeld: http://Synth.Stromeko.net/Downloads.html#BlofeldUserWavetables