all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#65575: guix-emacs-autoload-packages does not autoreload newly installed packages
@ 2023-08-28  4:50 Maxim Cournoyer
  2023-08-28  5:07 ` bug#65575: [PATCH 1/3] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28  4:50 UTC (permalink / raw)
  To: 65575

Hi,

Since some time, our guix-emacs-autoload-packages in Emacs stopped being
useful at refreshing newly installed packages.

I'll send a proposed change to address this.

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 1/3] gnu: emacs: Use lexical binding for guix-emacs.el startup library.
  2023-08-28  4:50 bug#65575: guix-emacs-autoload-packages does not autoreload newly installed packages Maxim Cournoyer
@ 2023-08-28  5:07 ` Maxim Cournoyer
  2023-08-28  5:11 ` Maxim Cournoyer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28  5:07 UTC (permalink / raw)
  To: 65575; +Cc: Maxim Cournoyer

* gnu/packages/aux-files/emacs/guix-emacs.el: Declare LEXCICAL-BINDING file
variable to true.
---

 gnu/packages/aux-files/emacs/guix-emacs.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 708093267d..c98e7fe369 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -1,3 +1,4 @@
+;;; -*- lexical-binding: t; -*-
 ;;; guix-emacs.el --- Emacs packages installed with Guix
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>

base-commit: 0aa74bebe31907c4abc71468319b220f908edd90
prerequisite-patch-id: 592cc2d7ba9ac74a0c6bcd140e1ced345f614a1b
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 1/3] gnu: emacs: Use lexical binding for guix-emacs.el startup library.
  2023-08-28  4:50 bug#65575: guix-emacs-autoload-packages does not autoreload newly installed packages Maxim Cournoyer
  2023-08-28  5:07 ` bug#65575: [PATCH 1/3] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
@ 2023-08-28  5:11 ` Maxim Cournoyer
  2023-08-28  5:11   ` bug#65575: [PATCH 2/3] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
  2023-08-28  5:11   ` bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
  2023-08-28 15:16 ` bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  2023-09-01  4:53 ` bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  3 siblings, 2 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28  5:11 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el: Declare LEXCICAL-BINDING file
variable to true.
---

 gnu/packages/aux-files/emacs/guix-emacs.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 708093267d..c98e7fe369 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -1,3 +1,4 @@
+;;; -*- lexical-binding: t; -*-
 ;;; guix-emacs.el --- Emacs packages installed with Guix
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>

base-commit: 0aa74bebe31907c4abc71468319b220f908edd90
prerequisite-patch-id: 319f4581076b0c137330d5d59e6436ab9f1cdafb
prerequisite-patch-id: 592cc2d7ba9ac74a0c6bcd140e1ced345f614a1b
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 2/3] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure.
  2023-08-28  5:11 ` Maxim Cournoyer
@ 2023-08-28  5:11   ` Maxim Cournoyer
  2023-08-28  5:11   ` bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
  1 sibling, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28  5:11 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el
(guix-emacs--subdirs-files): New procedure.
(guix-emacs-load-package-descriptors): Use it.
---

 gnu/packages/aux-files/emacs/guix-emacs.el | 33 +++++++++++++---------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index c98e7fe369..ed0c913163 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -3,7 +3,7 @@
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
 ;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
-;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;; Copyright © 2019, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 
 ;; This file is part of GNU Guix.
 
@@ -47,6 +47,13 @@ The files in the list do not have extensions (.el, .elc)."
                 (string-match-p "/share/emacs/site-lisp" dir))
               load-path))
 
+(defun guix-emacs--subdirs-files ()
+  "Return the Guix subdirs.el files found on the (non-core) load path."
+  (seq-filter #'file-exists-p
+              (mapcar (lambda (dir)
+                        (expand-file-name "subdirs.el" dir))
+                      (guix-emacs--non-core-load-path))))
+
 ;;;###autoload
 (defun guix-emacs-autoload-packages ()
   "Autoload Emacs packages found in EMACSLOADPATH.
@@ -63,19 +70,17 @@ The files in the list do not have extensions (.el, .elc)."
 ;;;###autoload
 (defun guix-emacs-load-package-descriptors ()
   "Load descriptors for packages found in EMACSLOADPATH via subdirs.el."
-  (dolist (dir (guix-emacs--non-core-load-path))
-    (let ((subdirs-file (expand-file-name "subdirs.el" dir)))
-     (when (file-exists-p subdirs-file)
-      (with-temp-buffer
-        (insert-file-contents subdirs-file)
-        (goto-char (point-min))
-        (let ((subdirs (read (current-buffer))))
-          (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
-               (equal (car-safe (cadr subdirs)) 'list)
-               (dolist (subdir (cdadr subdirs))
-                 (let ((pkg-dir (expand-file-name subdir dir)))
-                   (when (file-directory-p pkg-dir)
-                     (package-load-descriptor pkg-dir)))))))))))
+  (dolist (subdirs-file (guix-emacs--subdirs-files))
+    (with-temp-buffer
+      (insert-file-contents subdirs-file)
+      (goto-char (point-min))
+      (let ((subdirs (read (current-buffer))))
+        (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
+             (equal (car-safe (cadr subdirs)) 'list)
+             (dolist (subdir (cdadr subdirs))
+               (let ((pkg-dir (expand-file-name subdir dir)))
+                 (when (file-directory-p pkg-dir)
+                   (package-load-descriptor pkg-dir)))))))))
 
 ;; If emacs built with tree-sitter, read the value of the environment variable
 ;; to make tree-sitter grammars available in emacs out-of-the-box.
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-08-28  5:11 ` Maxim Cournoyer
  2023-08-28  5:11   ` bug#65575: [PATCH 2/3] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
@ 2023-08-28  5:11   ` Maxim Cournoyer
  2023-08-28  6:16     ` Liliana Marie Prikler
  1 sibling, 1 reply; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28  5:11 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

This fixes a regression introduced with 79cfe30f3 ("build-system: emacs: Use
subdirectories again.") which caused the 'guix-emacs-autoload-packages' to no
longer be able to autoload all packages.

* gnu/packages/aux-files/emacs/guix-emacs.el
(guix-emacs-autoload-packages-called): New variable.
(guix-emacs-autoload-packages): Reload subdirs.el files an all but the first
call of this procedure.
* doc/guix.texi (Application Setup): Document that
'guix-emacs-autoload-packages' can be invoked interactively to auto-reload
newly installed Emacs packages.

---

 doc/guix.texi                              | 11 +++++++----
 gnu/packages/aux-files/emacs/guix-emacs.el | 12 ++++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f82bb99069..66da4f9cd4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2167,12 +2167,15 @@ Application Setup
 Emacs through the @env{EMACSLOADPATH} environment variable, which is
 set when installing Emacs itself.
 
+@cindex guix-emacs-autoload-packages, refreshing Emacs packages
 Additionally, autoload definitions are automatically evaluated at the
 initialization of Emacs, by the Guix-specific
-@code{guix-emacs-autoload-packages} procedure.  If, for some reason, you
-want to avoid auto-loading the Emacs packages installed with Guix, you
-can do so by running Emacs with the @option{--no-site-file} option
-(@pxref{Init File,,, emacs, The GNU Emacs Manual}).
+@code{guix-emacs-autoload-packages} procedure.  This procedure can be
+interactively invoked to have newly installed Emacs packages discovered,
+without having to restart Emacs.  If, for some reason, you want to avoid
+auto-loading the Emacs packages installed with Guix, you can do so by
+running Emacs with the @option{--no-site-file} option (@pxref{Init
+File,,, emacs, The GNU Emacs Manual}).
 
 @quotation Note
 Emacs can now compile packages natively.  Under the default
diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index ed0c913163..b4a4fd1d91 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -54,6 +54,9 @@ The files in the list do not have extensions (.el, .elc)."
                         (expand-file-name "subdirs.el" dir))
                       (guix-emacs--non-core-load-path))))
 
+(defvar guix-emacs-autoload-packages-called nil
+  "True if `guix-emacs-autoload-packages' was already run.")
+
 ;;;###autoload
 (defun guix-emacs-autoload-packages ()
   "Autoload Emacs packages found in EMACSLOADPATH.
@@ -61,6 +64,15 @@ The files in the list do not have extensions (.el, .elc)."
 'Autoload' means to load the 'autoloads' files matching
 `guix-emacs-autoloads-regexp'."
   (interactive)
+  ;; Reload the subdirs.el files such as the one generated by the Guix profile
+  ;; hook, so that newly installed Emacs packages located under
+  ;; sub-directories are put on the load-path without having to restart Emacs.
+  (if guix-emacs-autoload-packages-called
+      (progn
+        (mapc #'load-file (guix-emacs--subdirs-files))
+        (setq load-path (delete-dups load-path)))
+    (setq guix-emacs-autoload-packages-called t))
+
   (let ((autoloads (mapcan #'guix-emacs-find-autoloads
                            (guix-emacs--non-core-load-path))))
     (mapc (lambda (f)
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-08-28  5:11   ` bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
@ 2023-08-28  6:16     ` Liliana Marie Prikler
  2023-08-28 15:20       ` Maxim Cournoyer
  0 siblings, 1 reply; 22+ messages in thread
From: Liliana Marie Prikler @ 2023-08-28  6:16 UTC (permalink / raw)
  To: Maxim Cournoyer, 65575

Hi Maxim,

Am Montag, dem 28.08.2023 um 01:11 -0400 schrieb Maxim Cournoyer:
> This fixes a regression introduced with 79cfe30f3 ("build-system:
> emacs: Use subdirectories again.") which caused the
> 'guix-emacs-autoload-packages' to no
> longer be able to autoload all packages.
> 
> * gnu/packages/aux-files/emacs/guix-emacs.el
> (guix-emacs-autoload-packages-called): New variable.
> (guix-emacs-autoload-packages): Reload subdirs.el files an all but
> the first call of this procedure.
> * doc/guix.texi (Application Setup): Document that
> 'guix-emacs-autoload-packages' can be invoked interactively to auto-
> reload newly installed Emacs packages.
> 
> ---
Thank you for looking at this.  I agree that even if we don't want to
generally load new packages into existing Emacs processes for the
breakages they might induce, not being able to do so at all is also not
a great option.  However, I don't think that tracking is the right
solution here, see below.

>  doc/guix.texi                              | 11 +++++++----
>  gnu/packages/aux-files/emacs/guix-emacs.el | 12 ++++++++++++
>  2 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/guix.texi b/doc/guix.texi
> index f82bb99069..66da4f9cd4 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -2167,12 +2167,15 @@ Application Setup
>  Emacs through the @env{EMACSLOADPATH} environment variable, which is
>  set when installing Emacs itself.
>  
> +@cindex guix-emacs-autoload-packages, refreshing Emacs packages
>  Additionally, autoload definitions are automatically evaluated at
> the
>  initialization of Emacs, by the Guix-specific
> -@code{guix-emacs-autoload-packages} procedure.  If, for some reason,
> you
> -want to avoid auto-loading the Emacs packages installed with Guix,
> you
> -can do so by running Emacs with the @option{--no-site-file} option
> -(@pxref{Init File,,, emacs, The GNU Emacs Manual}).
> +@code{guix-emacs-autoload-packages} procedure.  This procedure can
> be
> +interactively invoked to have newly installed Emacs packages
> discovered,
> +without having to restart Emacs.  If, for some reason, you want to
> avoid
> +auto-loading the Emacs packages installed with Guix, you can do so
> by
> +running Emacs with the @option{--no-site-file} option (@pxref{Init
> +File,,, emacs, The GNU Emacs Manual}).
>  
>  @quotation Note
>  Emacs can now compile packages natively.  Under the default
> diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el
> b/gnu/packages/aux-files/emacs/guix-emacs.el
> index ed0c913163..b4a4fd1d91 100644
> --- a/gnu/packages/aux-files/emacs/guix-emacs.el
> +++ b/gnu/packages/aux-files/emacs/guix-emacs.el
> @@ -54,6 +54,9 @@ The files in the list do not have extensions (.el,
> .elc)."
>                          (expand-file-name "subdirs.el" dir))
>                        (guix-emacs--non-core-load-path))))
>  
> +(defvar guix-emacs-autoload-packages-called nil
> +  "True if `guix-emacs-autoload-packages' was already run.")
> +
>  ;;;###autoload
>  (defun guix-emacs-autoload-packages ()
>    "Autoload Emacs packages found in EMACSLOADPATH.
> @@ -61,6 +64,15 @@ The files in the list do not have extensions (.el,
> .elc)."
>  'Autoload' means to load the 'autoloads' files matching
>  `guix-emacs-autoloads-regexp'."
>    (interactive)
> +  ;; Reload the subdirs.el files such as the one generated by the
> Guix profile
> +  ;; hook, so that newly installed Emacs packages located under
> +  ;; sub-directories are put on the load-path without having to
> restart Emacs.
> +  (if guix-emacs-autoload-packages-called
> +      (progn
> +        (mapc #'load-file (guix-emacs--subdirs-files))
> +        (setq load-path (delete-dups load-path)))
> +    (setq guix-emacs-autoload-packages-called t))
> +
Rather than keeping track of whether the function was already called
(which would make debugging more tedious if you also have e.g. broken
packages from another source on your EMACSLOADPATH), I think the user
ought to signal their intent to reload the subdirs files via the
universal argument.

e.g. 
(defun guix-emacs-autoload-packages (&optional reload)
  "..."
  (interactive "P")
  (when reload (mapc #'load-file (guix-emacs--subdirs-files)))
  ...)

WDYT?




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library.
  2023-08-28  4:50 bug#65575: guix-emacs-autoload-packages does not autoreload newly installed packages Maxim Cournoyer
  2023-08-28  5:07 ` bug#65575: [PATCH 1/3] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  2023-08-28  5:11 ` Maxim Cournoyer
@ 2023-08-28 15:16 ` Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
                     ` (2 more replies)
  2023-09-01  4:53 ` bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  3 siblings, 3 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28 15:16 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el: Declare LEXCICAL-BINDING file
variable to true.
---

(no changes since v1)

 gnu/packages/aux-files/emacs/guix-emacs.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 708093267d..c98e7fe369 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -1,3 +1,4 @@
+;;; -*- lexical-binding: t; -*-
 ;;; guix-emacs.el --- Emacs packages installed with Guix
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>

base-commit: 0aa74bebe31907c4abc71468319b220f908edd90
prerequisite-patch-id: 319f4581076b0c137330d5d59e6436ab9f1cdafb
prerequisite-patch-id: 592cc2d7ba9ac74a0c6bcd140e1ced345f614a1b
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v2 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure.
  2023-08-28 15:16 ` bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
@ 2023-08-28 15:16   ` Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
  2 siblings, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28 15:16 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el
(guix-emacs--subdirs-files): New procedure.
(guix-emacs-load-package-descriptors): Use it.

---

Changes in v2:
- Fix unbound 'dir' variable

 gnu/packages/aux-files/emacs/guix-emacs.el | 34 +++++++++++++---------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index c98e7fe369..4db7ec28c9 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -3,7 +3,7 @@
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
 ;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
-;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;; Copyright © 2019, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 
 ;; This file is part of GNU Guix.
 
@@ -47,6 +47,13 @@ The files in the list do not have extensions (.el, .elc)."
                 (string-match-p "/share/emacs/site-lisp" dir))
               load-path))
 
+(defun guix-emacs--subdirs-files ()
+  "Return the Guix subdirs.el files found on the (non-core) load path."
+  (seq-filter #'file-exists-p
+              (mapcar (lambda (dir)
+                        (expand-file-name "subdirs.el" dir))
+                      (guix-emacs--non-core-load-path))))
+
 ;;;###autoload
 (defun guix-emacs-autoload-packages ()
   "Autoload Emacs packages found in EMACSLOADPATH.
@@ -63,19 +70,18 @@ The files in the list do not have extensions (.el, .elc)."
 ;;;###autoload
 (defun guix-emacs-load-package-descriptors ()
   "Load descriptors for packages found in EMACSLOADPATH via subdirs.el."
-  (dolist (dir (guix-emacs--non-core-load-path))
-    (let ((subdirs-file (expand-file-name "subdirs.el" dir)))
-     (when (file-exists-p subdirs-file)
-      (with-temp-buffer
-        (insert-file-contents subdirs-file)
-        (goto-char (point-min))
-        (let ((subdirs (read (current-buffer))))
-          (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
-               (equal (car-safe (cadr subdirs)) 'list)
-               (dolist (subdir (cdadr subdirs))
-                 (let ((pkg-dir (expand-file-name subdir dir)))
-                   (when (file-directory-p pkg-dir)
-                     (package-load-descriptor pkg-dir)))))))))))
+  (dolist (subdirs-file (guix-emacs--subdirs-files))
+    (with-temp-buffer
+      (insert-file-contents subdirs-file)
+      (goto-char (point-min))
+      (let ((subdirs (read (current-buffer))))
+        (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
+             (equal (car-safe (cadr subdirs)) 'list)
+             (dolist (subdir (cdadr subdirs))
+               (let ((pkg-dir (expand-file-name
+                               subdir (file-name-directory subdirs-file))))
+                 (when (file-directory-p pkg-dir)
+                   (package-load-descriptor pkg-dir)))))))))
 
 ;; If emacs built with tree-sitter, read the value of the environment variable
 ;; to make tree-sitter grammars available in emacs out-of-the-box.
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v2 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads.
  2023-08-28 15:16 ` bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
@ 2023-08-28 15:16   ` Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
  2 siblings, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28 15:16 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el: Expound commentary.
(guix-emacs-verbose): New variable.
(guix-emacs--load-file-no-error): New procedure.
(guix-emacs-autoload-packages): Use it.

---

Changes in v2:
- New commit

 gnu/packages/aux-files/emacs/guix-emacs.el | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 4db7ec28c9..84284dde39 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -22,8 +22,9 @@
 
 ;;; Commentary:
 
-;; This file provides auxiliary code to autoload Emacs packages
-;; installed with Guix.
+;; This file provides auxiliary code to autoload Emacs packages installed with
+;; Guix.  To produce verbose messages useful while debugging, set the
+;; GUIX-EMACS-VERBOSE variable to true.
 
 ;;; Code:
 (require 'seq)
@@ -41,6 +42,15 @@ The files in the list do not have extensions (.el, .elc)."
                        (directory-files directory 'full-name
                                         guix-emacs-autoloads-regexp))))
 
+(defcustom guix-emacs-verbose nil
+  "Set to true to provide verbose messages, such as when loading packages."
+  :type 'boolean
+  :group 'guix-emacs)
+
+(defun guix-emacs--load-file-no-error (file)
+  "Load FILE, ignoring any errors"
+  (load file 'noerror (not guix-emacs-verbose)))
+
 (defun guix-emacs--non-core-load-path ()
   ;; Filter out core Elisp directories, which are already handled by Emacs.
   (seq-filter (lambda (dir)
@@ -63,9 +73,7 @@ The files in the list do not have extensions (.el, .elc)."
   (interactive)
   (let ((autoloads (mapcan #'guix-emacs-find-autoloads
                            (guix-emacs--non-core-load-path))))
-    (mapc (lambda (f)
-            (load f 'noerror t))
-          autoloads)))
+    (mapc #'guix-emacs--load-file-no-error autoloads)))
 
 ;;;###autoload
 (defun guix-emacs-load-package-descriptors ()
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v2 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-08-28 15:16 ` bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
  2023-08-28 15:16   ` bug#65575: [PATCH v2 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads Maxim Cournoyer
@ 2023-08-28 15:16   ` Maxim Cournoyer
  2023-08-28 16:55     ` Liliana Marie Prikler
  2 siblings, 1 reply; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28 15:16 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

This fixes a regression introduced with 79cfe30f3 ("build-system: emacs: Use
subdirectories again.") which caused the 'guix-emacs-autoload-packages' to no
longer be able to autoload all packages.

* gnu/packages/aux-files/emacs/guix-emacs.el
(guix-emacs-autoload-packages-called): New variable.
(guix-emacs-autoload-packages): Reload subdirs.el files on all but the first
call of this procedure, or when a prefix argument is provided.  Update doc.
* doc/guix.texi (Application Setup): Document that
'guix-emacs-autoload-packages' can be invoked interactively to auto-reload
newly installed Emacs packages.

---

Changes in v2:
- Safely load subdirs.el files
- Add 'reload' prefix argument as override for guix-emacs-autoload-packages

 doc/guix.texi                              | 11 +++++++----
 gnu/packages/aux-files/emacs/guix-emacs.el | 21 ++++++++++++++++++---
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f82bb99069..66da4f9cd4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2167,12 +2167,15 @@ Application Setup
 Emacs through the @env{EMACSLOADPATH} environment variable, which is
 set when installing Emacs itself.
 
+@cindex guix-emacs-autoload-packages, refreshing Emacs packages
 Additionally, autoload definitions are automatically evaluated at the
 initialization of Emacs, by the Guix-specific
-@code{guix-emacs-autoload-packages} procedure.  If, for some reason, you
-want to avoid auto-loading the Emacs packages installed with Guix, you
-can do so by running Emacs with the @option{--no-site-file} option
-(@pxref{Init File,,, emacs, The GNU Emacs Manual}).
+@code{guix-emacs-autoload-packages} procedure.  This procedure can be
+interactively invoked to have newly installed Emacs packages discovered,
+without having to restart Emacs.  If, for some reason, you want to avoid
+auto-loading the Emacs packages installed with Guix, you can do so by
+running Emacs with the @option{--no-site-file} option (@pxref{Init
+File,,, emacs, The GNU Emacs Manual}).
 
 @quotation Note
 Emacs can now compile packages natively.  Under the default
diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 84284dde39..aeb85f8487 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -64,13 +64,28 @@ The files in the list do not have extensions (.el, .elc)."
                         (expand-file-name "subdirs.el" dir))
                       (guix-emacs--non-core-load-path))))
 
+(defvar guix-emacs-autoload-packages-called nil
+  "True if `guix-emacs-autoload-packages' was already run.")
+
 ;;;###autoload
-(defun guix-emacs-autoload-packages ()
+(defun guix-emacs-autoload-packages (&optional reload)
   "Autoload Emacs packages found in EMACSLOADPATH.
 
 'Autoload' means to load the 'autoloads' files matching
-`guix-emacs-autoloads-regexp'."
-  (interactive)
+`guix-emacs-autoloads-regexp'.  When the optional RELOAD prefix
+argument is true, reload the subdirs.el files found on the load
+path; this behavior is active by default unless you've started
+Emacs with the '--no-site-file' option."
+  (interactive "P")
+  ;; Reload the subdirs.el files such as the one generated by the Guix profile
+  ;; hook, so that newly installed Emacs packages located under
+  ;; sub-directories are put on the load-path without having to restart Emacs.
+  (if (or reload guix-emacs-autoload-packages-called)
+      (progn
+        (mapc #'guix-emacs--load-file-no-error (guix-emacs--subdirs-files))
+        (setq load-path (delete-dups load-path)))
+    (setq guix-emacs-autoload-packages-called t))
+
   (let ((autoloads (mapcan #'guix-emacs-find-autoloads
                            (guix-emacs--non-core-load-path))))
     (mapc #'guix-emacs--load-file-no-error autoloads)))
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-08-28  6:16     ` Liliana Marie Prikler
@ 2023-08-28 15:20       ` Maxim Cournoyer
  2023-08-29 20:07         ` Liliana Marie Prikler
  0 siblings, 1 reply; 22+ messages in thread
From: Maxim Cournoyer @ 2023-08-28 15:20 UTC (permalink / raw)
  To: Liliana Marie Prikler; +Cc: Liliana Marie Prikler, 65575

Hi Liliana,

Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:

> Hi Maxim,
>
> Am Montag, dem 28.08.2023 um 01:11 -0400 schrieb Maxim Cournoyer:
>> This fixes a regression introduced with 79cfe30f3 ("build-system:
>> emacs: Use subdirectories again.") which caused the
>> 'guix-emacs-autoload-packages' to no
>> longer be able to autoload all packages.
>>
>> * gnu/packages/aux-files/emacs/guix-emacs.el
>> (guix-emacs-autoload-packages-called): New variable.
>> (guix-emacs-autoload-packages): Reload subdirs.el files an all but
>> the first call of this procedure.
>> * doc/guix.texi (Application Setup): Document that
>> 'guix-emacs-autoload-packages' can be invoked interactively to auto-
>> reload newly installed Emacs packages.
>>
>> ---
> Thank you for looking at this.  I agree that even if we don't want to
> generally load new packages into existing Emacs processes for the
> breakages they might induce, not being able to do so at all is also not
> a great option.  However, I don't think that tracking is the right
> solution here, see below.

[...]

>> diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el
>> b/gnu/packages/aux-files/emacs/guix-emacs.el
>> index ed0c913163..b4a4fd1d91 100644
>> --- a/gnu/packages/aux-files/emacs/guix-emacs.el
>> +++ b/gnu/packages/aux-files/emacs/guix-emacs.el
>> @@ -54,6 +54,9 @@ The files in the list do not have extensions (.el,
>> .elc)."
>>                          (expand-file-name "subdirs.el" dir))
>>                        (guix-emacs--non-core-load-path))))
>>  
>> +(defvar guix-emacs-autoload-packages-called nil
>> +  "True if `guix-emacs-autoload-packages' was already run.")
>> +
>>  ;;;###autoload
>>  (defun guix-emacs-autoload-packages ()
>>    "Autoload Emacs packages found in EMACSLOADPATH.
>> @@ -61,6 +64,15 @@ The files in the list do not have extensions (.el,
>> .elc)."
>>  'Autoload' means to load the 'autoloads' files matching
>>  `guix-emacs-autoloads-regexp'."
>>    (interactive)
>> +  ;; Reload the subdirs.el files such as the one generated by the
>> Guix profile
>> +  ;; hook, so that newly installed Emacs packages located under
>> +  ;; sub-directories are put on the load-path without having to
>> restart Emacs.
>> +  (if guix-emacs-autoload-packages-called
>> +      (progn
>> +        (mapc #'load-file (guix-emacs--subdirs-files))
>> +        (setq load-path (delete-dups load-path)))
>> +    (setq guix-emacs-autoload-packages-called t))
>> +
> Rather than keeping track of whether the function was already called
> (which would make debugging more tedious if you also have e.g. broken
> packages from another source on your EMACSLOADPATH), I think the user
> ought to signal their intent to reload the subdirs files via the
> universal argument.
>
> e.g. 
> (defun guix-emacs-autoload-packages (&optional reload)
>   "..."
>   (interactive "P")
>   (when reload (mapc #'load-file (guix-emacs--subdirs-files)))
>   ...)
>
> WDYT?

The reason for avoiding loading the subdirs.el files on the first call
is just an optimization, since it would at this time duplicate work
already done by Emacs itself when it first executes.  This shouldn't
fail; I've now employed the same 'noerror strategy as used for autoloads
to ensure that.

There's one edge case I've just thought though, which is if a user
invoked emacs with the documented '--no-site-file' option disabling
loading autoloads; this would cause guix-emacs-autoload-packages-called
to be nil.

To balance between making things both convenient and flexible, I've
preserved the tracking but also added the reload override you suggested.
Let me know what you think.

Thank you for the review!

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v2 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-08-28 15:16   ` bug#65575: [PATCH v2 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
@ 2023-08-28 16:55     ` Liliana Marie Prikler
  0 siblings, 0 replies; 22+ messages in thread
From: Liliana Marie Prikler @ 2023-08-28 16:55 UTC (permalink / raw)
  To: Maxim Cournoyer, 65575; +Cc: Katherine Cox-Buday, Andrew Tropin

Am Montag, dem 28.08.2023 um 11:16 -0400 schrieb Maxim Cournoyer:
> This fixes a regression introduced with 79cfe30f3 ("build-system:
> emacs: Use subdirectories again.") which caused the
> 'guix-emacs-autoload-packages' to no longer be able to autoload all
> packages.
> 
> * gnu/packages/aux-files/emacs/guix-emacs.el
> (guix-emacs-autoload-packages-called): New variable.
> (guix-emacs-autoload-packages): Reload subdirs.el files on all but
> the first call of this procedure, or when a prefix argument is
> provided.
What's the reason to still keep the variable?   Even if we call load-
file with 'noerror, the way in which it is set is quite weird and imho,
it would keep things simpler if we had the clear semantics of
  universal-argument → reload
  no universal-argument → no reload
or the other way round.






^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-08-28 15:20       ` Maxim Cournoyer
@ 2023-08-29 20:07         ` Liliana Marie Prikler
  0 siblings, 0 replies; 22+ messages in thread
From: Liliana Marie Prikler @ 2023-08-29 20:07 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: 65575

Am Montag, dem 28.08.2023 um 11:20 -0400 schrieb Maxim Cournoyer:
> > e.g. 
> > (defun guix-emacs-autoload-packages (&optional reload)
> >   "..."
> >   (interactive "P")
> >   (when reload (mapc #'load-file (guix-emacs--subdirs-files)))
> >   ...)
> > 
> > WDYT?
> 
> The reason for avoiding loading the subdirs.el files on the first
> call is just an optimization, since it would at this time duplicate
> work already done by Emacs itself when it first executes.  This
> shouldn't fail; I've now employed the same 'noerror strategy as used
> for autoloads to ensure that.
> 
> There's one edge case I've just thought though, which is if a user
> invoked emacs with the documented '--no-site-file' option disabling
> loading autoloads; this would cause guix-emacs-autoload-packages-
> called to be nil.
> 
> To balance between making things both convenient and flexible, I've
> preserved the tracking but also added the reload override you
> suggested.  Let me know what you think.
Assuming convenience equates to not needing to type C-u, we can also
achieve that without tracking:

(defun guix-emacs-autoload-packages (&optional noexpand)
  "Autoload Emacs packages found in EMACSLOADPATH.

'Autoload' means to load the 'autoloads' files matching 
`guix-emacs-autoloads-regexp'.  Before doing so, expand load-path by
loading subdirs.el files found in it, unless NOEXPAND is given."
  (interactive "P")
  (unless noexpand (mapc #'load-file (guix-emacs--subdirs-files)))
  ...)

In our own init code, we should simply call it as 
  (guix-emacs-autoload-packages 'noexpand)
then, since this expansion is already done earlier by Emacs.

Cheers




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library.
  2023-08-28  4:50 bug#65575: guix-emacs-autoload-packages does not autoreload newly installed packages Maxim Cournoyer
                   ` (2 preceding siblings ...)
  2023-08-28 15:16 ` bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
@ 2023-09-01  4:53 ` Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
                     ` (2 more replies)
  3 siblings, 3 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-09-01  4:53 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el: Declare LEXCICAL-BINDING file
variable to true.
---

(no changes since v1)

 gnu/packages/aux-files/emacs/guix-emacs.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 708093267d..c98e7fe369 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -1,3 +1,4 @@
+;;; -*- lexical-binding: t; -*-
 ;;; guix-emacs.el --- Emacs packages installed with Guix
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>

base-commit: f66fa5f917e76935187935b09ae7ac037b8b35f8
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure.
  2023-09-01  4:53 ` bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
@ 2023-09-01  4:53   ` Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
  2 siblings, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-09-01  4:53 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el
(guix-emacs--subdirs-files): New procedure.
(guix-emacs-load-package-descriptors): Use it.

---

(no changes since v2)

Changes in v2:
- Fix unbound 'dir' variable

 gnu/packages/aux-files/emacs/guix-emacs.el | 34 +++++++++++++---------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index c98e7fe369..4db7ec28c9 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -3,7 +3,7 @@
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
 ;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
-;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;; Copyright © 2019, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 
 ;; This file is part of GNU Guix.
 
@@ -47,6 +47,13 @@ The files in the list do not have extensions (.el, .elc)."
                 (string-match-p "/share/emacs/site-lisp" dir))
               load-path))
 
+(defun guix-emacs--subdirs-files ()
+  "Return the Guix subdirs.el files found on the (non-core) load path."
+  (seq-filter #'file-exists-p
+              (mapcar (lambda (dir)
+                        (expand-file-name "subdirs.el" dir))
+                      (guix-emacs--non-core-load-path))))
+
 ;;;###autoload
 (defun guix-emacs-autoload-packages ()
   "Autoload Emacs packages found in EMACSLOADPATH.
@@ -63,19 +70,18 @@ The files in the list do not have extensions (.el, .elc)."
 ;;;###autoload
 (defun guix-emacs-load-package-descriptors ()
   "Load descriptors for packages found in EMACSLOADPATH via subdirs.el."
-  (dolist (dir (guix-emacs--non-core-load-path))
-    (let ((subdirs-file (expand-file-name "subdirs.el" dir)))
-     (when (file-exists-p subdirs-file)
-      (with-temp-buffer
-        (insert-file-contents subdirs-file)
-        (goto-char (point-min))
-        (let ((subdirs (read (current-buffer))))
-          (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
-               (equal (car-safe (cadr subdirs)) 'list)
-               (dolist (subdir (cdadr subdirs))
-                 (let ((pkg-dir (expand-file-name subdir dir)))
-                   (when (file-directory-p pkg-dir)
-                     (package-load-descriptor pkg-dir)))))))))))
+  (dolist (subdirs-file (guix-emacs--subdirs-files))
+    (with-temp-buffer
+      (insert-file-contents subdirs-file)
+      (goto-char (point-min))
+      (let ((subdirs (read (current-buffer))))
+        (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
+             (equal (car-safe (cadr subdirs)) 'list)
+             (dolist (subdir (cdadr subdirs))
+               (let ((pkg-dir (expand-file-name
+                               subdir (file-name-directory subdirs-file))))
+                 (when (file-directory-p pkg-dir)
+                   (package-load-descriptor pkg-dir)))))))))
 
 ;; If emacs built with tree-sitter, read the value of the environment variable
 ;; to make tree-sitter grammars available in emacs out-of-the-box.
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads.
  2023-09-01  4:53 ` bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
@ 2023-09-01  4:53   ` Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
  2 siblings, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-09-01  4:53 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

* gnu/packages/aux-files/emacs/guix-emacs.el: Expound commentary.
(guix-emacs-verbose): New variable.
(guix-emacs--load-file-no-error): New procedure.
(guix-emacs-autoload-packages): Use it.

---

(no changes since v2)

Changes in v2:
- New commit

 gnu/packages/aux-files/emacs/guix-emacs.el | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 4db7ec28c9..84284dde39 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -22,8 +22,9 @@
 
 ;;; Commentary:
 
-;; This file provides auxiliary code to autoload Emacs packages
-;; installed with Guix.
+;; This file provides auxiliary code to autoload Emacs packages installed with
+;; Guix.  To produce verbose messages useful while debugging, set the
+;; GUIX-EMACS-VERBOSE variable to true.
 
 ;;; Code:
 (require 'seq)
@@ -41,6 +42,15 @@ The files in the list do not have extensions (.el, .elc)."
                        (directory-files directory 'full-name
                                         guix-emacs-autoloads-regexp))))
 
+(defcustom guix-emacs-verbose nil
+  "Set to true to provide verbose messages, such as when loading packages."
+  :type 'boolean
+  :group 'guix-emacs)
+
+(defun guix-emacs--load-file-no-error (file)
+  "Load FILE, ignoring any errors"
+  (load file 'noerror (not guix-emacs-verbose)))
+
 (defun guix-emacs--non-core-load-path ()
   ;; Filter out core Elisp directories, which are already handled by Emacs.
   (seq-filter (lambda (dir)
@@ -63,9 +73,7 @@ The files in the list do not have extensions (.el, .elc)."
   (interactive)
   (let ((autoloads (mapcan #'guix-emacs-find-autoloads
                            (guix-emacs--non-core-load-path))))
-    (mapc (lambda (f)
-            (load f 'noerror t))
-          autoloads)))
+    (mapc #'guix-emacs--load-file-no-error autoloads)))
 
 ;;;###autoload
 (defun guix-emacs-load-package-descriptors ()
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-09-01  4:53 ` bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
  2023-09-01  4:53   ` bug#65575: [PATCH v3 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads Maxim Cournoyer
@ 2023-09-01  4:53   ` Maxim Cournoyer
  2023-09-02  4:49     ` Liliana Marie Prikler
  2 siblings, 1 reply; 22+ messages in thread
From: Maxim Cournoyer @ 2023-09-01  4:53 UTC (permalink / raw)
  To: 65575
  Cc: Maxim Cournoyer, Andrew Tropin, Katherine Cox-Buday,
	Liliana Marie Prikler

This fixes a regression introduced with 79cfe30f3 ("build-system: emacs: Use
subdirectories again.") which caused the 'guix-emacs-autoload-packages' to no
longer be able to autoload all packages.

* gnu/packages/aux-files/emacs/guix-emacs.el
(guix-emacs-autoload-packages): Reload subdirs.el files unless NO-RELOAD is
provided.  Update doc.
* doc/guix.texi (Application Setup): Document that
'guix-emacs-autoload-packages' can be invoked interactively to auto-reload
newly installed Emacs packages.
* gnu/packages/emacs.scm (emacs) [arguments] <phases>: Call
guix-emacs-autoload-packages with an argument in the site-start.el file.

---

Changes in v3:
- Invert argument logic of guix-emacs-autoload-packages
- Drop the guix-emacs-autoload-packages-called state variable
- Adjust site-start.el file in Emacs package

Changes in v2:
- Safely load subdirs.el files
- Add 'reload' prefix argument as override for guix-emacs-autoload-packages

 doc/guix.texi                              | 11 +++++++----
 gnu/packages/aux-files/emacs/guix-emacs.el | 15 ++++++++++++---
 gnu/packages/emacs.scm                     |  2 +-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 04e5875925..939e669fee 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2167,12 +2167,15 @@ Application Setup
 Emacs through the @env{EMACSLOADPATH} environment variable, which is
 set when installing Emacs itself.
 
+@cindex guix-emacs-autoload-packages, refreshing Emacs packages
 Additionally, autoload definitions are automatically evaluated at the
 initialization of Emacs, by the Guix-specific
-@code{guix-emacs-autoload-packages} procedure.  If, for some reason, you
-want to avoid auto-loading the Emacs packages installed with Guix, you
-can do so by running Emacs with the @option{--no-site-file} option
-(@pxref{Init File,,, emacs, The GNU Emacs Manual}).
+@code{guix-emacs-autoload-packages} procedure.  This procedure can be
+interactively invoked to have newly installed Emacs packages discovered,
+without having to restart Emacs.  If, for some reason, you want to avoid
+auto-loading the Emacs packages installed with Guix, you can do so by
+running Emacs with the @option{--no-site-file} option (@pxref{Init
+File,,, emacs, The GNU Emacs Manual}).
 
 @quotation Note
 Emacs can now compile packages natively.  Under the default
diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 84284dde39..c253e64df8 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -65,12 +65,21 @@ The files in the list do not have extensions (.el, .elc)."
                       (guix-emacs--non-core-load-path))))
 
 ;;;###autoload
-(defun guix-emacs-autoload-packages ()
+(defun guix-emacs-autoload-packages (&optional no-reload)
   "Autoload Emacs packages found in EMACSLOADPATH.
 
 'Autoload' means to load the 'autoloads' files matching
-`guix-emacs-autoloads-regexp'."
-  (interactive)
+`guix-emacs-autoloads-regexp'.  By default, the subdirs.el files
+found on the load path are reloaded to discover newly installed
+packages, unless NO-RELOAD is provided."
+  (interactive "P")
+  ;; Reload the subdirs.el files such as the one generated by the Guix profile
+  ;; hook, so that newly installed Emacs packages located under
+  ;; sub-directories are put on the load-path without having to restart Emacs.
+  (unless no-reload
+    (mapc #'guix-emacs--load-file-no-error (guix-emacs--subdirs-files))
+    (setq load-path (delete-dups load-path)))
+
   (let ((autoloads (mapcan #'guix-emacs-find-autoloads
                            (guix-emacs--non-core-load-path))))
     (mapc #'guix-emacs--load-file-no-error autoloads)))
diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index d3689c2474..d9af6b96a7 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -244,7 +244,7 @@ (define-public emacs
                     (display
                      (string-append
                       "(when (require 'guix-emacs nil t)\n"
-                      "  (guix-emacs-autoload-packages)\n"
+                      "  (guix-emacs-autoload-packages 'no-reload)\n"
                       "  (advice-add 'package-load-all-descriptors"
                       " :after #'guix-emacs-load-package-descriptors))"))))
                 ;; Remove the extraneous subdirs.el file, as it causes Emacs to
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-09-01  4:53   ` bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
@ 2023-09-02  4:49     ` Liliana Marie Prikler
  2023-09-03 14:51       ` Maxim Cournoyer
  0 siblings, 1 reply; 22+ messages in thread
From: Liliana Marie Prikler @ 2023-09-02  4:49 UTC (permalink / raw)
  To: Maxim Cournoyer, 65575; +Cc: Katherine Cox-Buday, Andrew Tropin

Am Freitag, dem 01.09.2023 um 00:53 -0400 schrieb Maxim Cournoyer:
> This fixes a regression introduced with 79cfe30f3 ("build-system:
> emacs: Use subdirectories again.") which caused the
> 'guix-emacs-autoload-packages' to no longer be able to autoload all
> packages.
> 
> * gnu/packages/aux-files/emacs/guix-emacs.el
> (guix-emacs-autoload-packages): Reload subdirs.el files unless NO-
> RELOAD is provided.  Update doc.
> * doc/guix.texi (Application Setup): Document that
> 'guix-emacs-autoload-packages' can be invoked interactively to auto-
> reload newly installed Emacs packages.
> * gnu/packages/emacs.scm (emacs) [arguments] <phases>: Call
> guix-emacs-autoload-packages with an argument in the site-start.el
> file.
> 
> ---
> 
> Changes in v3:
> - Invert argument logic of guix-emacs-autoload-packages
> - Drop the guix-emacs-autoload-packages-called state variable
> - Adjust site-start.el file in Emacs package
> 
> Changes in v2:
> - Safely load subdirs.el files
> - Add 'reload' prefix argument as override for guix-emacs-autoload-
> packages
> 
>  doc/guix.texi                              | 11 +++++++----
>  gnu/packages/aux-files/emacs/guix-emacs.el | 15 ++++++++++++---
>  gnu/packages/emacs.scm                     |  2 +-
>  3 files changed, 20 insertions(+), 8 deletions(-)
Thanks, LGTM.  I've tested this by dropping almost all parts of load-
path and calling (guix-emacs-autoload-packages), it appears to do
what's promised.  Queued locally for emacs-next and followed up with a
patch that fixes the compilation warnings coming from the docstrings.

Cheers




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-09-02  4:49     ` Liliana Marie Prikler
@ 2023-09-03 14:51       ` Maxim Cournoyer
  2023-09-03 19:59         ` Liliana Marie Prikler
  0 siblings, 1 reply; 22+ messages in thread
From: Maxim Cournoyer @ 2023-09-03 14:51 UTC (permalink / raw)
  To: Liliana Marie Prikler; +Cc: Katherine Cox-Buday, Andrew Tropin, 65575

Hi Liliana,

Liliana Marie Prikler <liliana.prikler@gmail.com> writes:

[...]

> Thanks, LGTM.  I've tested this by dropping almost all parts of load-
> path and calling (guix-emacs-autoload-packages), it appears to do
> what's promised.  Queued locally for emacs-next and followed up with a
> patch that fixes the compilation warnings coming from the docstrings.

Sounds good, thank you for testing it!

About warnings, when I byte compile guix-emacs.el, all I see is:

--8<---------------cut here---------------start------------->8---
\f
Compiling file /home/maxim/src/guix/gnu/packages/aux-files/emacs/guix-emacs.el at Sun Sep  3 10:50:19 2023
guix-emacs.el:83:39: Warning: reference to free variable
    ‘treesit-extra-load-path’
guix-emacs.el:83:39: Warning: assignment to free variable
    ‘treesit-extra-load-path’
--8<---------------cut here---------------end--------------->8---

I don't know how to fix those; they seem harmless since their use is
enclosed in a (with-eval-after-load 'treesit ...) expression.

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-09-03 14:51       ` Maxim Cournoyer
@ 2023-09-03 19:59         ` Liliana Marie Prikler
  2023-09-09  8:20           ` Liliana Marie Prikler
  0 siblings, 1 reply; 22+ messages in thread
From: Liliana Marie Prikler @ 2023-09-03 19:59 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Katherine Cox-Buday, Andrew Tropin, 65575

Am Sonntag, dem 03.09.2023 um 10:51 -0400 schrieb Maxim Cournoyer:
> Hi Liliana,
> 
> Liliana Marie Prikler <liliana.prikler@gmail.com> writes:
> 
> [...]
> 
> > Thanks, LGTM.  I've tested this by dropping almost all parts of
> > load-path and calling (guix-emacs-autoload-packages), it appears to
> > do what's promised.  Queued locally for emacs-next and followed up
s/emacs-next/emacs-team/

Sorry for the confusion.
> > with a patch that fixes the compilation warnings coming from the
> > docstrings.
> 
> Sounds good, thank you for testing it!
> 
> About warnings, when I byte compile guix-emacs.el, all I see is:
> 
> --8<---------------cut here---------------start------------->8---
> \f
> Compiling file /home/maxim/src/guix/gnu/packages/aux-
> files/emacs/guix-emacs.el at Sun Sep  3 10:50:19 2023
> guix-emacs.el:83:39: Warning: reference to free variable
>     ‘treesit-extra-load-path’
> guix-emacs.el:83:39: Warning: assignment to free variable
>     ‘treesit-extra-load-path’
> --8<---------------cut here---------------end--------------->8---
> 
> I don't know how to fix those; they seem harmless since their use is
> enclosed in a (with-eval-after-load 'treesit ...) expression.
Yeah, I'm on Emacs 29 with tree-sitter baked in, so I see another set
of warnings (emacs-team vs master strikes again, it seems)

Cheers





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-09-03 19:59         ` Liliana Marie Prikler
@ 2023-09-09  8:20           ` Liliana Marie Prikler
  2023-09-09 13:04             ` Maxim Cournoyer
  0 siblings, 1 reply; 22+ messages in thread
From: Liliana Marie Prikler @ 2023-09-09  8:20 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: 65575-done, Katherine Cox-Buday, Andrew Tropin

Am Sonntag, dem 03.09.2023 um 21:59 +0200 schrieb Liliana Marie
Prikler:
> Am Sonntag, dem 03.09.2023 um 10:51 -0400 schrieb Maxim Cournoyer:
> > Hi Liliana,
> > 
> > Liliana Marie Prikler <liliana.prikler@gmail.com> writes:
> > 
> > [...]
> > 
> > > Queued locally for emacs-next and followed up
> s/emacs-next/emacs-team/
s/Queued locally/Pushed/

Cheers




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages'.
  2023-09-09  8:20           ` Liliana Marie Prikler
@ 2023-09-09 13:04             ` Maxim Cournoyer
  0 siblings, 0 replies; 22+ messages in thread
From: Maxim Cournoyer @ 2023-09-09 13:04 UTC (permalink / raw)
  To: Liliana Marie Prikler; +Cc: 65575-done, Katherine Cox-Buday, Andrew Tropin

Hello,

Liliana Marie Prikler <liliana.prikler@gmail.com> writes:

> Am Sonntag, dem 03.09.2023 um 21:59 +0200 schrieb Liliana Marie
> Prikler:
>> Am Sonntag, dem 03.09.2023 um 10:51 -0400 schrieb Maxim Cournoyer:
>> > Hi Liliana,
>> > 
>> > Liliana Marie Prikler <liliana.prikler@gmail.com> writes:
>> > 
>> > [...]
>> > 
>> > > Queued locally for emacs-next and followed up
>> s/emacs-next/emacs-team/
> s/Queued locally/Pushed/

Thank you!

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-09-09 13:18 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-28  4:50 bug#65575: guix-emacs-autoload-packages does not autoreload newly installed packages Maxim Cournoyer
2023-08-28  5:07 ` bug#65575: [PATCH 1/3] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
2023-08-28  5:11 ` Maxim Cournoyer
2023-08-28  5:11   ` bug#65575: [PATCH 2/3] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
2023-08-28  5:11   ` bug#65575: [PATCH 3/3] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
2023-08-28  6:16     ` Liliana Marie Prikler
2023-08-28 15:20       ` Maxim Cournoyer
2023-08-29 20:07         ` Liliana Marie Prikler
2023-08-28 15:16 ` bug#65575: [PATCH v2 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
2023-08-28 15:16   ` bug#65575: [PATCH v2 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
2023-08-28 15:16   ` bug#65575: [PATCH v2 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads Maxim Cournoyer
2023-08-28 15:16   ` bug#65575: [PATCH v2 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
2023-08-28 16:55     ` Liliana Marie Prikler
2023-09-01  4:53 ` bug#65575: [PATCH v3 1/4] gnu: emacs: Use lexical binding for guix-emacs.el startup library Maxim Cournoyer
2023-09-01  4:53   ` bug#65575: [PATCH v3 2/4] gnu: emacs: Factorize a 'guix-emacs--subdirs-files' procedure Maxim Cournoyer
2023-09-01  4:53   ` bug#65575: [PATCH v3 3/4] gnu: emacs: Allow producing verbose messages when loading autoloads Maxim Cournoyer
2023-09-01  4:53   ` bug#65575: [PATCH v3 4/4] gnu: emacs: Reload subdirs.el files in 'guix-emacs-autoload-packages' Maxim Cournoyer
2023-09-02  4:49     ` Liliana Marie Prikler
2023-09-03 14:51       ` Maxim Cournoyer
2023-09-03 19:59         ` Liliana Marie Prikler
2023-09-09  8:20           ` Liliana Marie Prikler
2023-09-09 13:04             ` Maxim Cournoyer

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.