diff options
author | Arun Isaac | 2023-07-25 20:47:24 +0100 |
---|---|---|
committer | Arun Isaac | 2023-07-25 23:39:14 +0100 |
commit | ad88e8319b9ebb82a12eed20cdcaf96850ec4e91 (patch) | |
tree | fa53679f2e8c83f5593f12a3b90932d4e61efd7b | |
parent | 61731755a3b0d3086597483bb7f6ac0229a5433e (diff) | |
download | guix-forge-ad88e8319b9ebb82a12eed20cdcaf96850ec4e91.tar.gz guix-forge-ad88e8319b9ebb82a12eed20cdcaf96850ec4e91.tar.lz guix-forge-ad88e8319b9ebb82a12eed20cdcaf96850ec4e91.zip |
doc: Add quoted-write.
* doc/skribilo.scm (quoted-write): New function.
(expression->string): Rewrite in terms of quoted-write.
-rw-r--r-- | doc/skribilo.scm | 25 |
1 files changed, 20 insertions, 5 deletions
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 <arunisaac@systemreboot.net> +;;; Copyright © 2022–2023 Arun Isaac <arunisaac@systemreboot.net> ;;; ;;; 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 |