Subject: [PATCH 4/4] Use #:lisp-directory instead of a custom phase

From: Morgan Smith <[email-masked]>
Date: Sun, 2 Mar 2025 16:04:59 -0500

Using a custom phase might not order the 'chdir' at the correct time and might
cause problems with some of the early phases in the 'emacs-build-system' (like
'ensure-package-description', 'expand-load-path', etc...)

* gnu/packages/agda.scm (emacs-agda2-mode):
* gnu/packages/cmake.scm (emacs-cmake-mode):
* gnu/packages/emacs-xyz.scm (emacs-casual-avy, emacs-casual-calc,
emacs-casual-dired, emacs-casual-info, emacs-chronometrist, emacs-edit-server,
emacs-epkg, emacs-exwm-firefox, emacs-flymake-collection, emacs-forge,
emacs-ghub, emacs-know-your-http-well, emacs-org-contrib, emacs-php-mode,
emacs-stumpwm-mode, emacs-telega-contrib, emacs-transient, emacs-treemacs,
emacs-treemacs-extra, emacs-with-editor, emacs-xenops):
* gnu/packages/engineering.scm (emacs-scad-mode):
* gnu/packages/erlang.scm (emacs-erlang):
* gnu/packages/mail.scm (emacs-notmuch):
* gnu/packages/music.scm (emacs-lilypond-mode):
* gnu/packages/protobuf.scm (emacs-protobuf-mode):
* gnu/packages/scheme.scm (emacs-gerbil-mode):
* gnu/packages/version-control.scm (emacs-stgit): Use '#:lisp-directory'
instead of a custom phase.
---
 gnu/packages/agda.scm            |   5 +-
 gnu/packages/cmake.scm           |   7 +-
 gnu/packages/emacs-xyz.scm       | 144 +++++++++----------------------
 gnu/packages/engineering.scm     |   8 +-
 gnu/packages/erlang.scm          |   5 +-
 gnu/packages/mail.scm            |   6 +-
 gnu/packages/music.scm           |   5 +-
 gnu/packages/protobuf.scm        |   5 +-
 gnu/packages/scheme.scm          |   5 +-
 gnu/packages/version-control.scm |   4 +-
 10 files changed, 49 insertions(+), 145 deletions(-)

diff --git a/gnu/packages/agda.scm b/gnu/packages/agda.scm
index c20549888d..ff23278469 100644
--- a/gnu/packages/agda.scm
+++ b/gnu/packages/agda.scm
@@ -150,10 +150,7 @@ (define-public emacs-agda2-mode
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'enter-elisp-dir
-            (lambda _ (chdir "src/data/emacs-mode"))))))
+      #:lisp-directory "src/data/emacs-mode"))
     (home-page "https://agda.readthedocs.io/en/latest/tools/emacs-mode.html")
     (synopsis "Emacs mode for Agda")
     (description "This Emacs mode enables interactive development with
diff --git a/gnu/packages/cmake.scm b/gnu/packages/cmake.scm
index 1ddcfa4d80..8c1ee61338 100644
--- a/gnu/packages/cmake.scm
+++ b/gnu/packages/cmake.scm
@@ -532,12 +532,7 @@ (define-public emacs-cmake-mode
     (outputs '("out"))
     (build-system emacs-build-system)
     (arguments
-     (list #:phases
-           #~(modify-phases %standard-phases
-               (add-after 'unpack 'chdir-elisp
-                 ;; Elisp directory is not in root of the source.
-                 (lambda _
-                   (chdir "Auxiliary"))))))
+     (list #:lisp-directory "Auxiliary"))
     (synopsis "Emacs major mode for editing Cmake expressions")
     (description "@code{cmakeos-mode} provides an Emacs major mode for editing
 Cmake files.  It supports syntax highlighting, indenting and refilling of
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 272be3a275..9bd0846a55 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -1703,11 +1703,9 @@ (define-public emacs-with-editor
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "lisp"
       #:phases
       #~(modify-phases %standard-phases
-          (add-before 'install 'enter-lisp-directory
-            (lambda _
-              (chdir "lisp")))
           (add-before 'install 'make-info
             (lambda _
               (with-directory-excursion "../docs"
@@ -2679,20 +2677,12 @@ (define-public emacs-ghub
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "lisp"
       #:phases
       #~(modify-phases %standard-phases
           (add-before 'install 'make-info
             (lambda _
-              (invoke "make" "info")))
-          (add-after 'make-info 'enter-lisp-directory
-            (lambda _
-              (chdir "lisp")))
-          (add-after 'expand-load-path 'add-el-dir-to-emacs-load-path
-            (lambda _
-              (setenv "EMACSLOADPATH"
-                      (string-append (getcwd)
-                                     "/lisp:"
-                                     (getenv "EMACSLOADPATH")))))
+              (invoke "make" "--directory=.." "info")))
           (add-after 'install 'install-info
             (lambda _
               (let ((info (string-append #$output "/share/info")))
@@ -3143,12 +3133,10 @@ (define-public emacs-flymake-collection
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "src"
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _
-              (chdir "src")))
-          (add-after 'chdir 'move-checkers
+          (add-after 'unpack 'move-checkers
             (lambda _
               ;; Move checkers to the top level, which is in the
               ;; EMACSLOADPATH.
@@ -5046,12 +5034,12 @@ (define-public emacs-xenops
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "lisp"
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
+          (add-after 'unpack 'set-home
             (lambda _
-              (setenv "HOME" "/tmp")
-              (chdir "lisp"))))))
+              (setenv "HOME" "/tmp"))))))
     (synopsis "WYSIWYG LaTeX environment")
     (description "This package provides a WYSIWYG LaTeX environment.
 It uses @command{dvisvgm}, @command{xclip}, @command{pngpaste} and
@@ -5337,12 +5325,9 @@ (define-public emacs-chronometrist
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "elisp"
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir-elisp
-            ;; Elisp directory is not in root of the source.
-            (lambda _
-              (chdir "elisp")))
           (add-after 'install 'install-doc
             ;; Documentation consists of several Markdown files.
             (lambda _
@@ -18593,11 +18578,7 @@ (define-public emacs-org-contrib
         (base32 "08m3aa8vsrlkacbvindjwqzviv5r8i9a0vzsrl8rx01xq5b0zd42"))))
     (build-system emacs-build-system)
     (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'enter-source-directory
-           (lambda _
-             (chdir "lisp"))))))
+     (list #:lisp-directory "lisp"))
     (propagated-inputs
      (list emacs-org))
     (home-page "https://git.sr.ht/~bzg/org-contrib")
@@ -20870,6 +20851,7 @@ (define-public emacs-php-mode
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "lisp"
       #:tests? #true
       #:test-command #~(list "emacs" "-Q" "--batch"
                              "-l" "../tests/php-mode-test.el"
@@ -20879,11 +20861,8 @@ (define-public emacs-php-mode
           (add-after 'unpack 'prepare-testing-bed
             (lambda _
               ;; This file is necessary for `php-project-root' test.
-              (call-with-output-file "tests/project/1/.git"
-                (const #t))))
-          (add-after 'prepare-testing-bed 'enter-source-directory
-            (lambda _
-              (chdir "lisp"))))))
+              (call-with-output-file "../tests/project/1/.git"
+                (const #t)))))))
     (propagated-inputs (list emacs-projectile))
     (synopsis "Major mode for editing PHP code")
     (description
@@ -25026,26 +25005,17 @@ (define-public emacs-epkg
         (base32 "0zdlymx44jgrzm68cnh636mpdazihqiakf5m3v1c2rhvh6cb6yg6"))))
     (build-system emacs-build-system)
     (arguments
-     `(#:phases
+     `(#:lisp-directory "lisp"
+       #:phases
        (modify-phases %standard-phases
          (add-before 'install 'make-info
            ;; Documentation is located in "docs/".
            (lambda* (#:key outputs #:allow-other-keys)
-             (with-directory-excursion "docs"
+             (with-directory-excursion "../docs"
                (invoke "makeinfo" "-o" "epkg.info" "epkg.texi")
                (let ((info (string-append (assoc-ref outputs "out")
                                           "/share/info")))
-                 (install-file "epkg.info" info)))))
-         (add-after 'make-info 'move-to-lisp-directory
-           ;; Source code is located in "lisp/".
-           (lambda _
-             (chdir "lisp")))
-         (add-after 'expand-load-path 'add-el-dir-to-emacs-load-path
-           (lambda _
-             (setenv "EMACSLOADPATH"
-                     (string-append (getcwd)
-                                    "/lisp:"
-                                    (getenv "EMACSLOADPATH"))))))))
+                 (install-file "epkg.info" info))))))))
     (native-inputs
      (list texinfo))
     (propagated-inputs
@@ -26522,12 +26492,7 @@ (define-public emacs-edit-server
         (base32 "0m7gj224sqxjjw5sxky92fnrxg9jy4nf33kwf0aqxnfhqlgh545k"))))
     (build-system emacs-build-system)
     (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'chdir-elisp
-           ;; Elisp directory is not in root of the source.
-           (lambda _
-             (chdir "servers"))))))
+     (list #:lisp-directory "servers"))
     (propagated-inputs (list emacs-ert-async))
     (home-page "https://github.com/stsquad/emacs_chrome")
     (synopsis "Server that responds to edit requests from Chromium")
@@ -27449,20 +27414,17 @@ (define-public emacs-know-your-http-well
        (sha256
         (base32 "1p4ibx0qgznv8ard4a9m7345ay8ij2qzmqdqiqlllndqq6mz62x5"))))
     (arguments
-     `(#:phases
+     `(#:lisp-directory "emacs"
+       #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'install-json-files
            (lambda* (#:key outputs #:allow-other-keys)
              (for-each (lambda (directory)
-                         (copy-recursively directory
+                         (copy-recursively (string-append "../" directory)
                                            (string-append
-                                            (assoc-ref outputs "out")
+                                            (assoc-ref outputs "out") "/"
                                             directory)))
-                       '("js" "json"))))
-         (add-after 'unpack 'chdir-elisp
-           ;; Elisp directory is not in root of the source.
-           (lambda _
-             (chdir "emacs"))))))
+                       '("js" "json")))))))
     (build-system emacs-build-system)
     (home-page "https://github.com/for-GET/know-your-http-well")
     (synopsis "Meaning of HTTP headers codes")
@@ -28285,12 +28247,7 @@ (define-public emacs-stumpwm-mode
                   "0giac390bq95ag41xkxqp8jjrhfx1wpgglz7jg5rkm0wjhcwmyml"))))
       (build-system emacs-build-system)
       (arguments
-       `(#:phases
-         (modify-phases %standard-phases
-           (add-after 'unpack 'chdir-elisp
-             ;; Elisp directory is not in root of the source.
-             (lambda _
-               (chdir "util/swm-emacs"))))))
+       (list #:lisp-directory "util/swm-emacs"))
       (home-page "https://github.com/stumpwm/stumpwm-contrib")
       (synopsis "Emacs minor-mode for Stumpwm")
       (description "Emacs minor-mode for Stumpwm")
@@ -33318,20 +33275,17 @@ (define-public emacs-treemacs
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "src/elisp"
       #:tests? #t
       #:test-command #~(list "make" "-C" "../.." "test")
       #:phases
       #~(modify-phases %standard-phases
           (add-after 'unpack 'fix-makefile
             (lambda _
-              (substitute* "Makefile"
+              (substitute* "../../Makefile"
                 (("@\\$\\(CASK\\) exec ") "")
                 ;; Guix does not need to prepare dependencies before testing.
                 (("test: prepare") "test:"))))
-          (add-after 'fix-makefile 'chdir-elisp
-            ;; Elisp directory is not in root of the source.
-            (lambda _
-              (chdir "src/elisp")))
           (add-before 'install 'patch-paths
             (lambda* (#:key inputs #:allow-other-keys)
               (make-file-writable "treemacs-core-utils.el")
@@ -33390,7 +33344,7 @@ (define-public emacs-treemacs-extra
          (package-arguments emacs-treemacs)
        ((#:phases phases)
         #~(modify-phases #$phases
-            (add-after 'chdir-elisp 'copy-extra
+            (add-after 'unpack 'copy-extra
               (lambda _
                 (copy-recursively "../extra" ".")))))))
     (propagated-inputs
@@ -33727,16 +33681,14 @@ (define-public emacs-transient
     (build-system emacs-build-system)
     (arguments
      `(#:tests? #f ;no test suite
+       #:lisp-directory "lisp"
        #:phases (modify-phases %standard-phases
                   (add-after 'unpack 'build-info-manual
                     (lambda _
-                      (invoke "make" "info")
+                      (invoke "make" "--directory=.." "info")
                       ;; Move the info file to lisp so that it gets
                       ;; installed by the emacs-build-system.
-                      (rename-file "docs/transient.info" "lisp/transient.info")))
-                  (add-after 'build-info-manual 'enter-lisp-directory
-                    (lambda _
-                      (chdir "lisp"))))))
+                      (rename-file "../docs/transient.info" "transient.info"))))))
     (native-inputs (list texinfo))
     (propagated-inputs (list emacs-compat))
     (home-page "https://magit.vc/manual/transient")
@@ -33765,17 +33717,15 @@ (define-public emacs-forge
      (build-system emacs-build-system)
      (arguments
       `(#:tests? #f                     ;no tests
+        #:lisp-directory "lisp"
         #:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'build-info-manual
             (lambda _
-              (invoke "make" "info")
+              (invoke "make" "--directory=.." "info")
               ;; Move the info file to lisp so that it gets installed by the
               ;; emacs-build-system.
-              (rename-file "docs/forge.info" "lisp/forge.info")))
-          (add-after 'build-info-manual 'chdir-lisp
-            (lambda _
-              (chdir "lisp"))))))
+              (rename-file "../docs/forge.info" "forge.info"))))))
      (native-inputs
       (list texinfo))
      (propagated-inputs
@@ -34358,10 +34308,7 @@ (define-public emacs-exwm-firefox
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _ (chdir "lisp"))))
+      #:lisp-directory "lisp"
       #:tests? #true
       #:test-command #~(list "emacs" "-Q" "--batch"
                              "-l" "../test/exwm-firefox--tests.el"
@@ -34962,10 +34909,7 @@ (define-public emacs-casual-avy
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _ (chdir "lisp"))))))
+      #:lisp-directory "lisp"))
     (propagated-inputs (list emacs-casual-lib emacs-avy))
     (home-page "https://github.com/kickingvegas/casual-avy")
     (synopsis "Transient-based porcelain for avy")
@@ -34989,10 +34933,7 @@ (define-public emacs-casual-calc
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _ (chdir "lisp"))))))
+      #:lisp-directory "lisp"))
     (propagated-inputs (list emacs-casual-lib))
     (home-page "https://github.com/kickingvegas/casual-calc")
     (synopsis "Transient-based porcelain for calc")
@@ -35016,10 +34957,7 @@ (define-public emacs-casual-dired
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _ (chdir "lisp"))))))
+      #:lisp-directory "lisp"))
     (propagated-inputs (list emacs-casual-lib))
     (home-page "https://github.com/kickingvegas/casual-dired")
     (synopsis "Transient-based porcelain for Dired")
@@ -35043,10 +34981,7 @@ (define-public emacs-casual-info
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _ (chdir "lisp"))))))
+      #:lisp-directory "lisp"))
     (propagated-inputs (list emacs-casual-lib))
     (home-page "https://github.com/kickingvegas/casual-info")
     (synopsis "Transient-based porcelain for info reader")
@@ -37641,11 +37576,10 @@ (define-public emacs-telega-contrib
     (name "emacs-telega-contrib")
     (arguments
      (list
+      #:lisp-directory "contrib"
       #:exclude #~(list "telega-live-location.el")
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'enter-subdirectory
-            (lambda _ (chdir "contrib")))
           (add-before 'install-license-files 'leave-subdirectory
             (lambda _ (chdir ".."))))))
     (inputs '())
diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index 234f4a2b03..3442705149 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -3121,13 +3121,7 @@ (define-public emacs-scad-mode
     (inputs '())
     (build-system emacs-build-system)
     (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'chdir-elisp
-           ;; Elisp directory is not in root of the source.
-           (lambda _
-             (chdir "contrib")
-             #t)))))
+     (list #:lisp-directory "contrib"))
     (synopsis "Emacs major mode for editing editing OpenSCAD code")
     (description "@code{scad-mode} provides an Emacs major mode for editing
 OpenSCAD code.  It supports syntax highlighting, indenting and refilling of
diff --git a/gnu/packages/erlang.scm b/gnu/packages/erlang.scm
index 8ca46e8bdc..0d86863c94 100644
--- a/gnu/packages/erlang.scm
+++ b/gnu/packages/erlang.scm
@@ -204,10 +204,7 @@ (define-public emacs-erlang
     (source (package-source erlang))
     (build-system emacs-build-system)
     (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-before 'expand-load-path 'change-working-directory
-           (lambda _ (chdir "lib/tools/emacs") #t)))))
+     (list #:lisp-directory "lib/tools/emacs"))
     (home-page "https://www.erlang.org/")
     (synopsis "Erlang major mode for Emacs")
     (description
diff --git a/gnu/packages/mail.scm b/gnu/packages/mail.scm
index cffbca087a..16763ebd44 100644
--- a/gnu/packages/mail.scm
+++ b/gnu/packages/mail.scm
@@ -1533,14 +1533,12 @@ (define-public emacs-notmuch
      (list notmuch))
     (arguments
      (list
+      #:lisp-directory "emacs"
       #:exclude #~(cons* "make-deps.el" "rstdoc.el" %default-exclude)
       #:include #~(cons* "notmuch-logo.svg" %default-include)
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _
-              (chdir "emacs")))
-          (add-after 'chdir 'patch-paths
+          (add-after 'unpack 'patch-paths
             (lambda* (#:key inputs #:allow-other-keys)
               (let ((notmuch (search-input-file inputs "/bin/notmuch")))
                 (substitute* "notmuch-lib.el"
diff --git a/gnu/packages/music.scm b/gnu/packages/music.scm
index bf47489d34..b8a6a2375f 100644
--- a/gnu/packages/music.scm
+++ b/gnu/packages/music.scm
@@ -1759,10 +1759,7 @@ (define-public emacs-lilypond-mode
     (build-system emacs-build-system)
     (arguments
      (list
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-before 'expand-load-path 'change-working-directory
-            (lambda _ (chdir "elisp"))))))
+      #:lisp-directory "elisp"))
     (home-page (package-home-page lilypond))
     (synopsis "Major mode for editing GNU LilyPond music scores")
     (description
diff --git a/gnu/packages/protobuf.scm b/gnu/packages/protobuf.scm
index d4b48e585b..310fd1dde0 100644
--- a/gnu/packages/protobuf.scm
+++ b/gnu/packages/protobuf.scm
@@ -579,10 +579,7 @@ (define-public emacs-protobuf-mode
     (source (package-source protobuf))
     (build-system emacs-build-system)
     (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-before 'expand-load-path 'change-working-directory
-           (lambda _ (chdir "editors") #t)))))
+     (list #:lisp-directory "editors"))
     (home-page "https://github.com/protocolbuffers/protobuf")
     (synopsis "Protocol buffers major mode for Emacs")
     (description
diff --git a/gnu/packages/scheme.scm b/gnu/packages/scheme.scm
index 811f74e6d6..8340198135 100644
--- a/gnu/packages/scheme.scm
+++ b/gnu/packages/scheme.scm
@@ -1346,10 +1346,7 @@ (define-public emacs-gerbil-mode
     (version "1.0")
     (build-system emacs-build-system)
     (arguments
-     (list #:phases #~(modify-phases %standard-phases
-                        (add-before 'install 'change-directory
-                          (lambda _
-                            (chdir "etc"))))))
+     (list #:lisp-directory "etc"))
     (synopsis "Emacs major-mode for editing Gerbil code")
     (description
      "Gerbil mode provides font-lock, indentation, navigation, and REPL for
diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index 9ecb5cf98a..068b7f41d5 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -2170,11 +2170,9 @@ (define-public emacs-stgit
     (build-system emacs-build-system)
     (arguments
      (list
+      #:lisp-directory "contrib"
       #:phases
       #~(modify-phases %standard-phases
-          (add-before 'install 'enter-lisp-directory
-            (lambda _
-              (chdir "contrib")))
           (add-before 'install-license-files 'leave-lisp-directory
             (lambda _
               (chdir ".."))))))
-- 
2.48.1