From dd67ebfa2366ba5a275886c7c68f96643c59280b Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Sat, 12 Jan 2013 11:50:27 +0100 Subject: [PATCH 3/3] org.el: advice around require to defuse mixed-install scenario * lisp/org.el (require-reloads-when-shadowed): Advice around require to check and correct for the situation where some parts of Org have already been loaded, then the load-path has been changed and Org is now about to be activated. To do this, unload the previously loaded feature named "org", "ob" or starting with "org-" or "ob-" so that the original require function does load the requested feature from the current load-path. Move some requires up in the file so that the advice can be removed as early as possible. --- lisp/org.el | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index e979b35..e94442d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -78,8 +78,35 @@ (defvar org-table-formula-constants-local nil (require 'find-func) (require 'format-spec) +;; some parts of Org might already have been used from a different +;; place, try to reload these parts from the current load-path +(require 'loadhist) +(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)) (let ((load-suffixes (list ".el"))) (org-load-noerror-mustsuffix "org-loaddefs")) @@ -4991,17 +5018,6 @@ (defvar buffer-face-mode-face) (require 'easymenu) (require 'overlay) -;; (require 'org-macs) moved higher up in the file before it is first used -(require 'org-entities) -;; (require 'org-compat) moved higher up in the file before it is first used -(require 'org-faces) -(require 'org-list) -(require 'org-pcomplete) -(require 'org-src) -(require 'org-footnote) - -;; babel -(require 'ob) ;;;###autoload (define-derived-mode org-mode outline-mode "Org" -- 1.8.1