Subject: [bug#55420] [PATCH 1/2] guix: emacs-utils: Add emacs-batch-script.

From: Fredrik Salomonsson <[email-masked]>
Date: Sat, 14 May 2022 23:05:07 +0000

* guix/build/emacs-utils.scm (emacs-batch-script): New procedure.
---
 guix/build/emacs-utils.scm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm
index 60a754b9e9..8d40b9e139 100644
--- a/guix/build/emacs-utils.scm
+++ b/guix/build/emacs-utils.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2014 Alex Kost <[email-masked]>
 ;;; Copyright © 2018, 2020, 2022 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2019 Liliana Marie Prikler <[email-masked]>
+;;; Copyright © 2022 Fredrik Salomonsson <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,10 +23,13 @@
 (define-module (guix build emacs-utils)
   #:use-module (guix build utils)
   #:use-module (ice-9 format)
+  #:use-module (ice-9 popen)
+  #:use-module (ice-9 rdelim)
   #:export (%emacs
             emacs-batch-eval
             emacs-batch-edit-file
             emacs-batch-disable-compilation
+            emacs-batch-script
             emacs-generate-autoloads
             emacs-byte-compile-directory
 
@@ -69,6 +73,15 @@ (define (emacs-batch-disable-compilation file)
       (add-file-local-variable 'no-byte-compile t)
       (basic-save-buffer))))
 
+(define (emacs-batch-script expr)
+  "Execute the Elisp code EXPR in Emacs batch mode and return output."
+  (call-with-port
+      (open-pipe*
+       OPEN_READ
+       (%emacs) "--quick" "--batch"
+       (string-append "--eval=" (expr->string expr)))
+    read-string))
+
 (define (emacs-generate-autoloads name directory)
   "Generate autoloads for Emacs package NAME placed in DIRECTORY."
   (let* ((file (string-append directory "/" name "-autoloads.el"))
-- 
2.36.0