unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Fredrik Salomonsson <plattfot@posteo.net>
To: 55420@debbugs.gnu.org
Cc: Fredrik Salomonsson <plattfot@posteo.net>
Subject: [bug#55420] [PATCH v2 2/2] guix: emacs-utils: Add emacs-header-parse.
Date: Sun,  5 Jun 2022 00:19:24 +0000	[thread overview]
Message-ID: <20220605001924.184934-2-plattfot@posteo.net> (raw)
In-Reply-To: <20220605001924.184934-1-plattfot@posteo.net>

* guix/build/emacs-utils.scm (emacs-header-parse): New procedure.

* tests/build-emacs-utils.scm ("emacs-header-parse: fetch version",
  "emacs-header-parse: fetch keywords", "emacs-header-parse: fetch
  nonexistent author"): New tests.
---
 guix/build/emacs-utils.scm  |  9 +++++++++
 tests/build-emacs-utils.scm | 30 ++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm
index 1684bf3262..8ee547f2b3 100644
--- a/guix/build/emacs-utils.scm
+++ b/guix/build/emacs-utils.scm
@@ -38,6 +38,7 @@ (define-module (guix build emacs-utils)
 
             emacs-generate-autoloads
             emacs-byte-compile-directory
+            emacs-header-parse
 
             as-display
             emacs-substitute-sexps
@@ -114,6 +115,14 @@ (define* (emacs-byte-compile-directory dir)
                 (byte-recompile-directory (file-name-as-directory ,dir) 0 1))))
     (emacs-batch-eval expr)))
 
+(define (emacs-header-parse section file)
+  "Parse the header SECTION in FILE and return it as a string."
+  (emacs-batch-script
+   `(progn
+     (require 'lisp-mnt)
+     (find-file ,file)
+     (princ (lm-header ,section)))))
+
 (define as-display         ;syntactic keyword for 'emacs-substitute-sexps'
   '(as display))
 
diff --git a/tests/build-emacs-utils.scm b/tests/build-emacs-utils.scm
index 03b73b1fed..57647caaa2 100644
--- a/tests/build-emacs-utils.scm
+++ b/tests/build-emacs-utils.scm
@@ -38,4 +38,34 @@ (define-module (test build-emacs-utils)
                               "Lisp error: (wrong-type-argument numberp \"three\")")))
     (emacs-batch-script '(mapcar 'number-to-string (list 1 2 "three")))))
 
+(define (test-emacs-header-parse section)
+  (call-with-temporary-directory
+   (lambda (directory)
+     (let ((mock-elisp-file (string-append directory "/foo.el")))
+       (call-with-output-file mock-elisp-file
+         (lambda (port)
+           (display ";;; foo --- mock emacs package -*- lexical-binding: t -*-
+
+;; Created: 4 Jun 2022
+;; Keywords: lisp test
+;; Version: 1.0.0
+;;; Commentary:
+;;; Code:
+;;; foo.el ends here
+"
+                    port)))
+       (emacs-header-parse section mock-elisp-file)))))
+
+(test-equal "emacs-header-parse: fetch version"
+    "1.0.0"
+  (test-emacs-header-parse "version"))
+
+(test-equal "emacs-header-parse: fetch keywords"
+    "lisp test"
+  (test-emacs-header-parse "keywords"))
+
+(test-equal "emacs-header-parse: fetch nonexistent author"
+    "nil"
+  (test-emacs-header-parse "author"))
+
 (test-end "build-emacs-utils")
-- 
2.36.1





  reply	other threads:[~2022-06-05  0:20 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   ` Fredrik Salomonsson [this message]
2022-06-05  9:52   ` Maxime Devos
2022-06-05 20:02     ` Fredrik Salomonsson
2022-06-05 19:51 ` [bug#55420] [PATCH v3 " Fredrik Salomonsson
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=20220605001924.184934-2-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).