guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/06: guix: emacs-utils: Add emacs-header-parse.


From: guix-commits
Subject: 02/06: guix: emacs-utils: Add emacs-header-parse.
Date: Fri, 17 Jun 2022 17:40:55 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit c3afbd05bf541b31b122e6093ff10eabf6a47926
Author: Fredrik Salomonsson <plattfot@posteo.net>
AuthorDate: Sun Jun 5 19:51:43 2022 +0000

    guix: emacs-utils: Add emacs-header-parse.
    
    * 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.
    
    Signed-off-by: Ludovic Court├Ęs <ludo@gnu.org>
---
 guix/build/emacs-utils.scm  |  9 +++++++++
 tests/build-emacs-utils.scm | 27 ++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

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 @@
 
             emacs-generate-autoloads
             emacs-byte-compile-directory
+            emacs-header-parse
 
             as-display
             emacs-substitute-sexps
@@ -114,6 +115,14 @@ true, evaluate using dynamic scoping."
                 (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 27cff46c38..081032285a 100644
--- a/tests/build-emacs-utils.scm
+++ b/tests/build-emacs-utils.scm
@@ -28,7 +28,7 @@
 
 (test-begin "build-emacs-utils")
 ;; Only run the following tests if emacs is present.
-(test-skip (if (which "emacs") 0 2))
+(test-skip (if (which "emacs") 0 5))
 
 (test-equal "emacs-batch-script: print foo from emacs"
   "foo"
@@ -40,4 +40,29 @@
                               "Lisp error: (wrong-type-argument numberp 
\"three\")")))
     (emacs-batch-script '(mapcar 'number-to-string (list 1 2 "three")))))
 
+(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)))
+     (test-equal "emacs-header-parse: fetch version"
+       "1.0.0"
+       (emacs-header-parse "version" mock-elisp-file))
+     (test-equal "emacs-header-parse: fetch keywords"
+       "lisp test"
+       (emacs-header-parse "keywords" mock-elisp-file))
+     (test-equal "emacs-header-parse: fetch nonexistent author"
+       "nil"
+       (emacs-header-parse "author" mock-elisp-file)))))
+
 (test-end "build-emacs-utils")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]