 minimum requirement for `eless'.  So set the environment
 variable ELESS_DEFAULT_ORG to a value like 1 if using emacs 26
 or newer.")
+
+(defvar eless-default-share-directory nil
+  "Share directory for this Emacs installation.")
+
+(defvar eless-default-lisp-directory nil
+  "Directory containing lisp files for the Emacs installation.
+
+This value must match the path to the lisp/ directory of the
+Emacs installation.  If Emacs is installed using
+--prefix=\"${PREFIX_DIR}\" this value would typically be
+\"${PREFIX_DIR}/share/emacs/<VERSION>/lisp/\".")
+
+;; Remove Org that ships with Emacs from the `load-path' if installing
+;; it from Elpa.
+(when eless-install-org-from-elpa
+  (let* ((bin-dir (when (and invocation-directory
+                             (file-exists-p invocation-directory))
+                    (file-truename invocation-directory)))
+         (prefix-dir (when bin-dir        ;Because bin-dir = prefix-dir + "bin/"
+                       (file-name-directory (directory-file-name bin-dir))))
+         (share-dir (when prefix-dir
+                      (let ((share-dir-1 (file-name-as-directory (expand-file-name "share" prefix-dir))))
+                        (when (file-exists-p share-dir-1)
+                          (setq eless-default-share-directory share-dir-1))
+                        share-dir-1)))
+         (version-dir (when share-dir
+                        (let* ((emacs-dir (file-name-as-directory (expand-file-name "emacs" share-dir)))
+                               ;; Possibility where the lisp dir is something like
+                               ;; ../emacs/26.0.50/lisp/.  If `emacs-version' is
+                               ;; x.y.z.w, remove the ".w" portion.
+                               ;; http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=22b2207471807bda86534b4faf1a29b3a6447536
+                               (version (replace-regexp-in-string "\\([0-9]+\\.[0-9]+\\.[0-9]+\\).*" "\\1" emacs-version))
+                               (version-dir-1 (file-name-as-directory (expand-file-name version emacs-dir))))
+                          (if (file-exists-p version-dir-1)
+                              version-dir-1
+                            ;; Possibility where the lisp dir is something like
+                            ;; ../emacs/25.2/lisp/.  If `emacs-version' is x.y.z,
+                            ;; remove the ".z" portion.
+                            (setq version (replace-regexp-in-string "\\([0-9]+\\.[0-9]+\\).*" "\\1" emacs-version))
+                            (setq version-dir-1 (file-name-as-directory (expand-file-name version emacs-dir)))
+                            (when (file-exists-p version-dir-1)
+                              version-dir-1))))))
+    (when version-dir
+      (let ((lisp-dir-1 (file-name-as-directory (expand-file-name "lisp" version-dir))))
+        (when (file-exists-p lisp-dir-1)
+          (setq eless-default-lisp-directory lisp-dir-1)))))
+  (when eless-test-setup-verbose
+    (message "eless-default-share-directory: %s" eless-default-share-directory)
+    (message "eless-default-lisp-directory: %s" eless-default-lisp-directory))
+
+  (with-eval-after-load 'package
+    ;; Remove Org that ships with Emacs from the `load-path'.
+    (let ((default-org-path (expand-file-name "org" eless-default-lisp-directory)))
+      (setq load-path (delete default-org-path load-path)))
+
+    ;; Remove Org installed in `site-lisp' directory from the `load-path'.
+    (let ((site-lisp-org-path (expand-file-name "emacs/site-lisp/org" eless-default-share-directory)))
+      (setq load-path (delete site-lisp-org-path load-path)))
+
+    ;; Remove Org from `package--builtin-versions'.
+    (setq package--builtin-versions (delete (assoc 'org package--builtin-versions) package--builtin-versions))
+    ;; Remove Org from `package--builtins'.
+    (require 'finder-inf nil t)         ;Populate `package--builtins'
+    (setq package--builtins (delete (assoc 'org package--builtins) package--builtins))
+
+    (when eless-test-setup-verbose
+      (message "org detected as installed initially? %S" (package-installed-p 'org))
+      (message "load-path: %s" load-path)
+      ;; (message "`load-path' Shadows:")
+      ;; (message (list-load-path-shadows :stringp))
+      )))
 
 (defvar eless-elpa (let ((dir (getenv "ELESS_ELPA")))
                      (unless dir


(defvar eless-packages '(htmlize rainbow-delimiters))
(when eless-install-org-from-elpa
  ;; `org' will always be detected as installed, so use
  ;; `org-plus-contrib'.
  ;; Fri Sep 22 18:24:19 EDT 2017 - kmodi
  ;; Install the packages in the specified order. We do not want
  ;; `toc-org' to be installed first. If that happens, `org' will be
  ;; required before the newer version of Org gets installed and we
  ;; will end up with mixed Org version.  So put `org-plus-contrib' at
  ;; the beginning of `eless-packages'.
  (add-to-list 'eless-packages 'org-plus-contrib))

(defvar eless-git-root (progn
                         (require 'vc-git)

;; Time-stamp: <2022-02-15 21:31:04 kmodi>

;; Setup to build eless and its documentation in an "emacs -Q" environment.

