unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: lin Sun via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>,
	monnier@iro.umontreal.ca, philipk@posteo.net
Cc: 62767@debbugs.gnu.org
Subject: bug#62767: 29.0.90; [PATCH] *lisp/emacs-lisp/package.el: set variables after info package
Date: Thu, 25 May 2023 00:46:58 +0000	[thread overview]
Message-ID: <CABCREdr2Kh=vzrXXboPxTp3JoBfWeBL7wQgeCSeJyN5yRpgFWQ@mail.gmail.com> (raw)
In-Reply-To: <83edn6new6.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2807 bytes --]

On Wed, May 24, 2023 at 11:32 AM Eli Zaretskii <eliz@gnu.org> wrote:
> ...
> Could you please describe how this makes sure Info-directory-list will
> be set to a correct value, in the various scenarios that are relevant?
>
> In particular, Info-directory-list is not the right variable to tweak
> here, as it is computed by info.el.  I think we need a separate
> variable.
In the original function `info-initialize', it will rely on the value
`Info-directory-list' to indicate function initialization and parse
the "INFOPATH" or get system info dirs as the initialized value.

The bug comes for: package.el will add several paths into
`Info-directory-list', that maybe lead function `info-initialize'
return without parsing the "INFOPATH" or getting the system info dires
as initial value.

So package.el required the entire `info.el` and called function
`info-initialize' to initialize the value first (by parsing the
"INFOPATH" or get system info dir), then the package.el modify the
`Info-directory-list'.

The patch  will allow users to set the `Info-directory-list' before
calling function `info-initialize'; when info.el use the
`Info-directory-list' variable to read plain *.info file, will call
function `info-initialize' to add system info dirs.

Two functions `Info-insert-dir' and `Info-find-file', will use
(get/read) the value of `Info-directory-list' to read the plain *.info
files.
In the patch file, both functions will call the function
`info-initialize' at their entry to ensure the `Info-directory-list'
is initialized with the "INFOPATH" env string.
Users will just insert/remove dirs from/to `Info-directory-list', but
won't use the list to read/get plain *.info files.
So users can define the `Info-directory-list' and modify its value on
their elisp files.

> > +      (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)))
>
> Using 'append' here could cause duplicate directories in
> Info-directory-list.
The `delete-dups' will avoid that.

> > +(defvar Info--initialized nil
> > +  "Non-nil if `info-initialize' has been run.")
> There's no need to capitalize the first letter of the name of an
> internal variable.  We capitalize 'I' in "Info" so that it would be
> easier to type info.el commands with completion (other commands that
> begin with 'i' use lower-case 'i').  This is not a factor for internal
> variables.
Very helpful to understand the naming rules. And rename it to
`info--initialized', new patch attached, please review again.

Best Regards
Lin

[-- Attachment #2: 0001-avoid-to-load-the-entire-info-package-V3.patch --]
[-- Type: text/x-patch, Size: 4950 bytes --]

From a17f389ce6af7600714d0cadf925a9bcd5a6ccb1 Mon Sep 17 00:00:00 2001
From: Lin Sun <sunlin7@hotmail.com>
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 "\f
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


  reply	other threads:[~2023-05-25  0:46 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1181651021.466162.1581309285621.ref@mail.yahoo.com>
2020-02-10  4:34 ` bug#39539: 27.0.60; [PATCH] Fix error message "Invalid function: with-connection-local-variables" Sun Lin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-02-10  6:46   ` bug#39539: Acknowledgement (27.0.60; [PATCH] Fix error message "Invalid function: with-connection-local-variables") Sun Lin
2020-02-10  8:23     ` Sun Lin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-02-10 16:04       ` Sun Lin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-02-10 16:22         ` Stefan Kangas
2020-02-10 16:44         ` Eli Zaretskii
2022-09-27 21:10   ` bug#58127: 29.0.50; [PATCH] Fix the calc load calc-loaddefs.el without suffix sensitive lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-27 21:15     ` Lars Ingebrigtsen
2022-09-27 22:23     ` bug#58129: 29.0.50; [PATCH] Fix (package-update) always install package due to invalid version comparison lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-28 11:05       ` Lars Ingebrigtsen
2022-10-22  5:16     ` bug#58708: 29.0.50; [PATCH] Fix build error that gflags.will_dump_ not surround by the directives as its definition lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-22  7:00       ` Eli Zaretskii
2022-10-25  5:32       ` lin Sun
2022-10-25 11:57         ` Eli Zaretskii
2022-10-25 22:03           ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-29  5:01       ` bug#58860: 29.0.50; [PATCH] semantic/fw.el: speed up the 'semantic-find-file-noselect' lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-29  6:31         ` Eli Zaretskii
2022-10-29 15:06         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-30  6:56           ` Eli Zaretskii
2022-10-30 12:37             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-30 17:13               ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-31 13:22                 ` Eli Zaretskii
2022-11-13  4:26         ` bug#59236: 29.0.50; [PATCH] bytecomp.el: (byte-recompile-directory): Fix negated ignore lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-13  7:12           ` Eli Zaretskii
2022-11-13  7:22             ` Philip Kaludercic
2022-11-09  1:19               ` bug#59139: 29.0.50; batch-byte-recompile-directory doesn't recompile file as expected David Ponce
2022-11-09  9:41                 ` bug#59139: Acknowledgement (29.0.50; batch-byte-recompile-directory doesn't recompile file as expected) David Ponce
2022-11-12 16:01                 ` bug#59139: 29.0.50; batch-byte-recompile-directory doesn't recompile file as expected David Ponce
     [not found]                 ` <handler.59139.D59236.16683241653696.notifdone@debbugs.gnu.org>
2022-11-13 10:12                   ` bug#59139: closed (Re: bug#59236: 29.0.50; [PATCH] bytecomp.el: (byte-recompile-directory): Fix negated ignore) David Ponce
2022-11-14 11:50                     ` Philip Kaludercic
2022-11-13  7:45               ` bug#59236: 29.0.50; [PATCH] bytecomp.el: (byte-recompile-directory): Fix negated ignore lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-14 17:52                 ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-16 19:21                   ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-16 19:30                     ` Philip Kaludercic
2022-11-16 19:43                       ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-19 22:39           ` bug#60209: 29.0.50; [PATCH] lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-02  5:13             ` bug#62609: 29.0.60; [PATCH] src/comp.c: New variable `comp-el-to-eln-strip-prefix` for `comp-el-to-eln-rel-filename` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-02  6:02               ` Eli Zaretskii
2023-04-03  0:53               ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-03 12:33                 ` Eli Zaretskii
2023-04-03 14:08                   ` Andrea Corallo
2023-04-03 14:37                     ` Eli Zaretskii
2023-04-11  5:15               ` bug#62767: 29.0.90; [PATCH] *lisp/emacs-lisp/package.el: set variables after info package lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-14 20:07                 ` Philip Kaludercic
2023-04-14 22:12                   ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-15  9:15                   ` Eli Zaretskii
2023-04-15 10:43                     ` Philip Kaludercic
2023-04-15 10:58                       ` Eli Zaretskii
2023-04-17  6:13                       ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17  6:53                         ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17  6:59                           ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17 13:24                         ` Philip Kaludercic
2023-04-17 15:27                           ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17 16:03                             ` Philip Kaludercic
2023-04-17 17:25                             ` Eli Zaretskii
2023-04-17 16:30                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-19  5:11                             ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-20  9:12                               ` Eli Zaretskii
2023-04-20 16:16                               ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-23 22:11                                 ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found]                                   ` <CABCREdpha5W_phrK8iLVN973-m5BjahNgMhpHDC=oA-X4Vvj9A@mail.gmail.com>
2023-05-24  2:53                                     ` lin Sun
2023-05-24 11:32                                       ` Eli Zaretskii
2023-05-25  0:46                                         ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-05-26  9:37                                           ` Eli Zaretskii
2023-05-30  3:56                                             ` lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-30 10:25                                               ` Eli Zaretskii
2023-05-23  4:28                 ` bug#63653: 29.0.91; [PATCH] More fix for loading SQLite extensions lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-23  4:36                   ` lin Sun
2023-05-23 11:33                     ` Eli Zaretskii
2023-05-23 13:40                       ` lin Sun
2023-05-23 14:54                         ` Eli Zaretskii
2023-05-23 15:01                           ` lin Sun
2023-05-23  4:52                   ` lin Sun
     [not found]                   ` <CABCREdoXGHXZPJJK7255c=DEAGqUtMc67Yj0VxwbS+GGXqciZQ@mail.gmail.com>
2023-06-30 21:55                     ` bug#64386: 29.0.91; [PATCH] *src/emacs.c: a comma for elements of usage_message Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-01  1:34                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-01  4:43                         ` Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-01 18:56                           ` Stefan Kangas
2023-07-01  6:10                       ` Eli Zaretskii
2023-08-16 19:39                       ` bug#65346: 30.0.50; *lisp/net/eww.el: new function 'eww-open-in-new-buffer-background' Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-17  7:49                         ` Eli Zaretskii
2023-08-17 22:51                           ` Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-18  5:52                             ` Eli Zaretskii
2023-08-18 19:03                               ` Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-20  8:50                                 ` Eli Zaretskii
2023-08-20 14:29                                   ` Lin Sun via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-20 16:44                                 ` Juri Linkov
2023-08-27 16:40                                   ` Eli Zaretskii
2023-08-18  2:15                           ` Michael Heerdegen
2023-08-18  6:07                             ` Eli Zaretskii
2023-10-23 17:15                       ` bug#66710: 29.0.1; [PATCH] *doc/misc/gnus.texi: Fix unmatched quote in gnus doc Lin Sun
2023-10-23 18:57                         ` Eli Zaretskii
2023-10-23 23:30                           ` bug#62767: " Lin Sun
2023-09-01 19:58             ` bug#60209: 29.0.50; [PATCH] lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABCREdr2Kh=vzrXXboPxTp3JoBfWeBL7wQgeCSeJyN5yRpgFWQ@mail.gmail.com' \
    --to=bug-gnu-emacs@gnu.org \
    --cc=62767@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=philipk@posteo.net \
    --cc=sunlin7@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).