From: Fredrik Salomonsson <plattfot@posteo.net>
To: 55420@debbugs.gnu.org
Cc: Fredrik Salomonsson <plattfot@posteo.net>
Subject: [bug#55420] [PATCH v3 1/2] guix: emacs-utils: Add emacs-batch-script.
Date: Sun, 5 Jun 2022 19:51:42 +0000 [thread overview]
Message-ID: <20220605195143.23591-1-plattfot@posteo.net> (raw)
In-Reply-To: <20220514230017.27372-1-plattfot@posteo.net>
* 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'.
---
Makefile.am | 1 +
guix/build/emacs-utils.scm | 30 ++++++++++++++++++++++++++
tests/build-emacs-utils.scm | 43 +++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+)
create mode 100644 tests/build-emacs-utils.scm
diff --git a/Makefile.am b/Makefile.am
index e8d4b7ef8a..4a8514ea3a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -469,6 +469,7 @@ SCM_TESTS = \
tests/boot-parameters.scm \
tests/bournish.scm \
tests/builders.scm \
+ tests/build-emacs-utils.scm \
tests/build-utils.scm \
tests/cache.scm \
tests/challenge.scm \
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 @@ (define (emacs-batch-disable-compilation file)
(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"))
diff --git a/tests/build-emacs-utils.scm b/tests/build-emacs-utils.scm
new file mode 100644
index 0000000000..27cff46c38
--- /dev/null
+++ b/tests/build-emacs-utils.scm
@@ -0,0 +1,43 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Fredrik Salomonsson <plattfot@posteo.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+
+(define-module (test build-emacs-utils)
+ #:use-module (guix tests)
+ #:use-module (guix build emacs-utils)
+ #:use-module (guix build utils)
+ #:use-module ((guix utils)
+ #:select (call-with-temporary-directory))
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-64))
+
+(test-begin "build-emacs-utils")
+;; Only run the following tests if emacs is present.
+(test-skip (if (which "emacs") 0 2))
+
+(test-equal "emacs-batch-script: print foo from emacs"
+ "foo"
+ (emacs-batch-script '(princ "foo")))
+
+(test-assert "emacs-batch-script: raise &emacs-batch-error on failure"
+ (guard (c ((emacs-batch-error? c)
+ (string-contains (emacs-batch-error-message c)
+ "Lisp error: (wrong-type-argument numberp \"three\")")))
+ (emacs-batch-script '(mapcar 'number-to-string (list 1 2 "three")))))
+
+(test-end "build-emacs-utils")
base-commit: 271736117e3f09b616a2dbd5d74c9595926c9297
--
2.36.1
next prev parent reply other threads:[~2022-06-05 19:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-14 23:00 [bug#55420] [PATCH 0/2] Add a function to parse emacs elisp's package header Fredrik Salomonsson
2022-05-14 23:05 ` [bug#55420] [PATCH 1/2] guix: emacs-utils: Add emacs-batch-script Fredrik Salomonsson
2022-05-14 23:05 ` [bug#55420] [PATCH 2/2] guix: emacs-utils: Add emacs-header-parse Fredrik Salomonsson
2022-06-01 20:39 ` [bug#55420] [PATCH 0/2] Add a function to parse emacs elisp's package header Ludovic Courtès
2022-06-01 20:38 ` Ludovic Courtès
2022-06-02 2:53 ` Fredrik Salomonsson
2022-06-02 13:44 ` Ludovic Courtès
2022-06-05 0:42 ` Fredrik Salomonsson
2022-06-05 0:19 ` [bug#55420] [PATCH v2 1/2] guix: emacs-utils: Add emacs-batch-script Fredrik Salomonsson
2022-06-05 0:19 ` [bug#55420] [PATCH v2 2/2] guix: emacs-utils: Add emacs-header-parse Fredrik Salomonsson
2022-06-05 9:52 ` [bug#55420] [PATCH v2 1/2] guix: emacs-utils: Add emacs-batch-script Maxime Devos
2022-06-05 20:02 ` Fredrik Salomonsson
2022-06-05 19:51 ` Fredrik Salomonsson [this message]
2022-06-05 19:51 ` [bug#55420] [PATCH v3 2/2] guix: emacs-utils: Add emacs-header-parse Fredrik Salomonsson
2022-06-17 20:29 ` bug#55420: [PATCH 0/2] Add a function to parse emacs elisp's package header Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220605195143.23591-1-plattfot@posteo.net \
--to=plattfot@posteo.net \
--cc=55420@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).