From ad88e8319b9ebb82a12eed20cdcaf96850ec4e91 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 25 Jul 2023 20:47:24 +0100 Subject: doc: Add quoted-write. * doc/skribilo.scm (quoted-write): New function. (expression->string): Rewrite in terms of quoted-write. --- doc/skribilo.scm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/skribilo.scm b/doc/skribilo.scm index 1025db4..a666eed 100644 --- a/doc/skribilo.scm +++ b/doc/skribilo.scm @@ -1,5 +1,5 @@ ;;; guix-forge --- Guix software forge meta-service -;;; Copyright © 2022 Arun Isaac +;;; Copyright © 2022–2023 Arun Isaac ;;; ;;; This file is part of guix-forge. ;;; @@ -207,13 +207,28 @@ the default value. DEFAULT, when specified, will override the default value extracted from the source." (make-record-field identifier #f default documentation)) +(define (quoted-write object port) + "Write @var{object} to @var{port} printing quoted expressions using +the quote character." + (match object + (('quote child) + (display "'" port) + (quoted-write child port)) + ((parent children ...) + (display "(" port) + (quoted-write parent port) + (unless (null? children) + (display " " port)) + (for-each (cut quoted-write <> port) + children) + (display ")" port)) + (_ (write object port)))) + (define (expression->string exp) "Return EXP as a human-readable string. In particular, quote forms are printed using the quote symbol." - (match exp - (('quote exp) - (string-append "'" (expression->string exp))) - (_ (format "~s" exp)))) + (call-with-output-string + (cut quoted-write exp <>))) (define (record-documentation file identifier . fields) "Document record identified by IDENTIFIER, a symbol, in FILE. FIELDS -- cgit v1.2.3