Subject: bug#62767: 29.0.90; [PATCH] *lisp/emacs-lisp/package.el: set variables after info package

From: lin Sun <[email-masked]>
Date: Tue, 23 May 2023 22:11:21 +0000

Hi Eli, Stefan,

I am experimenting with a different approach to avoid the loading of
the entire info.el file using package.el.
Instead, I am adding the directories to the `Info-directory-list',
which will be utilized by other functions responsible for loading the
specific info files.

Please help review the patch I attached. Thanks.

Best regards
Lin
From efd3cbdb5ce5d7eeb2601557775ff3f93e86d476 Mon Sep 17 00:00:00 2001
From: Lin Sun <[email-masked]>
Date: Tue, 11 Apr 2023 00:00:13 +0000
Subject: [PATCH] avoid to load the entire info package

*lisp/emacs-lisp/package.el: don't require info package
*lisp/info.el: use explicit mark `Info--initialized'
---
 lisp/emacs-lisp/package.el | 17 ++++++-----------
 lisp/info.el               | 33 ++++++++++++++++++---------------
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 293c1c39ca..70e995e3dc 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -907,9 +907,6 @@ package-activate-1
         (add-to-list 'load-path (directory-file-name pkg-dir)))
       ;; Add info node.
       (when (file-exists-p (expand-file-name "dir" pkg-dir))
-        ;; FIXME: not the friendliest, but simple.
-        (require 'info)
-        (info-initialize)
         (add-to-list 'Info-directory-list pkg-dir))
       (push name package-activated-list)
       ;; Don't return nil.
@@ -4478,7 +4475,6 @@ package-quickstart-refresh
   "(Re)Generate the `package-quickstart-file'."
   (interactive)
   (package-initialize 'no-activate)
-  (require 'info)
   (let ((package--quickstart-pkgs ())
         ;; Pretend we haven't activated anything yet!
         (package-activated-list ())
@@ -4521,13 +4517,12 @@ package-quickstart-refresh
                   (append ',(mapcar #'package-desc-name package--quickstart-pkgs)
                           package-activated-list)))
           (current-buffer))
-      (let ((info-dirs (butlast Info-directory-list)))
-        (when info-dirs
-          (pp `(progn (require 'info)
-                      (info-initialize)
-                      (setq Info-directory-list
-                            (append ',info-dirs Info-directory-list)))
-              (current-buffer))))
+      (when-let ((info-dirs (butlast Info-directory-list)))
+        (pp `(defvar Info-directory-list) (current-buffer))
+        (pp `(setq Info-directory-list
+                   (delete-dups
+                    (append ',info-dirs Info-directory-list)))
+            (current-buffer)))
       ;; Use `\s' instead of a space character, so this code chunk is not
       ;; mistaken for an actual file-local section of package.el.
       (insert "
diff --git a/lisp/info.el b/lisp/info.el
index 035dff66e7..8f53240dab 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -400,6 +400,9 @@ Info-virtual-nodes
 (defvar-local Info-current-node-virtual nil
   "Non-nil if the current Info node is virtual.")
 
+(defvar Info--initialized nil
+  "Non-nil if `info-initialize' has been run.")
+
 (defun Info-virtual-file-p (filename)
   "Check if Info file FILENAME is virtual."
   (Info-virtual-fun 'find-file filename nil))
@@ -700,29 +703,29 @@ Info-default-dirs
 
 (defun info-initialize ()
   "Initialize `Info-directory-list', if that hasn't been done yet."
-  (unless Info-directory-list
+  (unless Info--initialized
     (let ((path (getenv "INFOPATH"))
 	  (sep (regexp-quote path-separator)))
-      (setq Info-directory-list
-	    (prune-directory-list
-	     (if path
-		 (if (string-match-p (concat sep "\\'") path)
-		     (append (split-string (substring path 0 -1) sep)
-			     (Info-default-dirs))
-		   (split-string path sep))
-	       (Info-default-dirs))))
+      (dolist (dir
+	       (prune-directory-list
+	        (if path
+		    (if (string-match-p (concat sep "\\'") path)
+		        (append (split-string (substring path 0 -1) sep)
+			        (Info-default-dirs))
+		      (split-string path sep))
+	          (Info-default-dirs))))
+        (add-to-list 'Info-directory-list dir))
       ;; For a self-contained (ie relocatable) NS build, AFAICS we
       ;; always want the included info directory to be at the head of
       ;; the search path, unless it's already in INFOPATH somewhere.
       ;; It's at the head of Info-default-directory-list,
       ;; but there's no way to get it at the head of Info-directory-list
       ;; except by doing it here.
-      (and path
-	   (featurep 'ns)
-	   (let ((dir (expand-file-name "../info" data-directory)))
-	     (and (file-directory-p dir)
-		  (not (member dir (split-string path ":" t)))
-		  (push dir Info-directory-list)))))))
+      (when (and path (featurep 'ns))
+        (when-let* ((dir (expand-file-name "../info" data-directory))
+                    ((file-directory-p dir)))
+	  (add-to-list 'Info-directory-list dir)))))
+  (setq Info--initialized t))
 
 ;;;###autoload
 (defun info-other-window (&optional file-or-node buffer)
-- 
2.20.5