Subject: [bug#75817] [PATCH] profiles: emacs-subdirs: Avoid building list with a loop

From: Liliana Marie Prikler <[email-masked]>
Date: Sat, 25 Jan 2025 01:30:45 +0100

Am Freitag, dem 24.01.2025 um 20:01 -0300 schrieb Thiago Jung
Bauermann:
> If the EMACSNATIVELOADPATH environment variable (by mistake) has
> duplicated paths, Emacs fails to load with:
> 
>   $ emacs
>   List contains a loop:
>   ("/home/user/.guix-profile/lib/emacs/native-site-lisp"
>    "/gnu/store/…-emacs-lsp-mode-9.0.0/lib/emacs/native-site-lisp"
>    "/home/user/.guix-profile/lib/emacs/native-site-lisp"
>    "/home/user/.guix-profile/lib/emacs/native-site-lisp"
>    "/gnu/store/…-emacs-lsp-mode-9.0.0/lib/emacs/native-site-lisp" .
> #2)
>   $ echo $?
>   255
> 
> A git bisect in Guix to find when the problem was introduced arrived
> at commit e9b13294700d ("profiles: emacs-subdirs: Also expand
> native-comp-eln-load-path.").
> 
> Fix the problem by applying Liliana's suggestion of changing 'nconc'
> to 'append' in the Elisp code written to subdirs.el.
It's better to describe the bug in code so that folks won't stumble
over it again.  E.g. "Note: needle may be found multiple times, so
don't use destructive procedures like nconc."
> * guix/profiles.scm (emacs-subdirs): Use 'append' rather than
> 'nconc'.
> 
> Change-Id: If646b806f24666b5247850d30d2819c7482c130b
> Fixes: <https://issues.guix.gnu.org/75709>
You have some horizontal space here to name the bug :)
> Suggested-by: Liliana Marie Prikler <[email-masked]>
> ---
>  guix/profiles.scm | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/guix/profiles.scm b/guix/profiles.scm
> index 87b9543ac01f..63b2a08a48d4 100644
> --- a/guix/profiles.scm
> +++ b/guix/profiles.scm
> @@ -1230,8 +1230,8 @@ (define build
>                          (setq native-comp-eln-load-path
>                                (mapcan (lambda (dir)
>                                          (if (equal dir needle)
> -                                            (nconc ',native-comp-
> dirs
> -                                                   (list dir))
> +                                            (append ',native-comp-
> dirs
> +                                                    (list dir))
>                                              (list dir)))
>                                        native-comp-eln-load-path))))
>                     port)

Cheers