From a17f389ce6af7600714d0cadf925a9bcd5a6ccb1 Mon Sep 17 00:00:00 2001 From: Lin Sun 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 | 34 +++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 293c1c39ca..46de846b80 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..631c35140b 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) @@ -1279,6 +1282,7 @@ Info-dir-file-name ;; default-directory to the first directory we actually get any text ;; from. (defun Info-insert-dir () + (info-initialize) (if (and Info-dir-contents Info-dir-file-attributes ;; Verify that none of the files we used has changed ;; since we used it. -- 2.20.5