summaryrefslogtreecommitdiff
path: root/guix/build/emacs-utils.scm
diff options
context:
space:
mode:
authorFredrik Salomonsson <plattfot@posteo.net>2022-06-05 19:51:42 +0000
committerLudovic Courtès <ludo@gnu.org>2022-06-17 23:39:31 +0200
commitf8275916fc6fcb3dd9bd8ef7dc4ddce2dca98c7d (patch)
treea888f9cbbf8b72deed9e9de4a5700abe0eb6c761 /guix/build/emacs-utils.scm
parent6013f808102e7e2093b41fc71324cdd89bb607a0 (diff)
guix: emacs-utils: Add emacs-batch-script.
* guix/build/emacs-utils.scm (emacs-batch-script): New procedure. * tests/build-emacs-utils.scm: New file. * Makefile.am (TESTS): Add `tests/build-emacs-utils.scm'. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'guix/build/emacs-utils.scm')
-rw-r--r--guix/build/emacs-utils.scm30
1 files changed, 30 insertions, 0 deletions
diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm
index 60a754b9e9..1684bf3262 100644
--- a/guix/build/emacs-utils.scm
+++ b/guix/build/emacs-utils.scm
@@ -3,6 +3,7 @@
;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
;;; Copyright © 2018, 2020, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2019 Liliana Marie Prikler <liliana.prikler@gmail.com>
+;;; Copyright © 2022 Fredrik Salomonsson <plattfot@posteo.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -22,10 +23,19 @@
(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)
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-35)
#:export (%emacs
emacs-batch-eval
emacs-batch-edit-file
emacs-batch-disable-compilation
+ emacs-batch-script
+
+ emacs-batch-error?
+ emacs-batch-error-message
+
emacs-generate-autoloads
emacs-byte-compile-directory
@@ -69,6 +79,26 @@ true, evaluate using dynamic scoping."
(add-file-local-variable 'no-byte-compile t)
(basic-save-buffer))))
+(define-condition-type &emacs-batch-error &error
+ emacs-batch-error?
+ (message emacs-batch-error-message))
+
+(define (emacs-batch-script expr)
+ "Execute the Elisp code EXPR in Emacs batch mode and return output."
+ (let* ((error-pipe (pipe))
+ (port (parameterize ((current-error-port (cdr error-pipe)))
+ (open-pipe*
+ OPEN_READ
+ (%emacs) "--quick" "--batch"
+ (string-append "--eval=" (expr->string expr)))))
+ (output (read-string port))
+ (status (close-pipe port)))
+ (close-port (cdr error-pipe))
+ (unless (zero? status)
+ (raise (condition (&emacs-batch-error
+ (message (read-string (car error-pipe)))))))
+ output))
+
(define (emacs-generate-autoloads name directory)
"Generate autoloads for Emacs package NAME placed in DIRECTORY."
(let* ((file (string-append directory "/" name "-autoloads.el"))