@@ -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))
@@ -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")