aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-10-16 15:26:58 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-10-16 15:30:47 +0200
commit6dc4d7abdd8aed6853c4513d7b3c42cdb0f1eccc (patch)
tree8dac763d4e16605bb077a2a656f4a049f59c417a
parentFixen in vcomponent formats. (diff)
downloadcalp-6dc4d7abdd8aed6853c4513d7b3c42cdb0f1eccc.tar.gz
calp-6dc4d7abdd8aed6853c4513d7b3c42cdb0f1eccc.tar.xz
Change printer for vcomponent.
This new printer attempts to output something actually matching a structure which the object can be recreated from. It's still not read-compatible (since that can only be done through reader macros), but a read + eval would work. It's fed through the pretty printer, both so the output might actually be readable, but also so that line diffs work (and so that acidental output of the entire database doesn't crash emacs). This still needs to be extended to the vlines to be really useful.
-rw-r--r--module/vcomponent/base.scm22
1 files changed, 20 insertions, 2 deletions
diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm
index 10f77606..df47a5f5 100644
--- a/module/vcomponent/base.scm
+++ b/module/vcomponent/base.scm
@@ -51,6 +51,9 @@
;;; </vcomponent>
;;;
+;;; TODO at least when called from serialize-vcomponent, this should
+;;; emit something which allows the serialized vcomponent to be
+;;; fed back into the parser to get the object back.
(define (print-vline v p)
(format p "#<<vline> key: ~s value: ~s parameters: ~s>"
(key v)
@@ -60,14 +63,29 @@
))
(define-type (vline printer: print-vline)
+ ;; TODO why does vline contain its own key?
(key type: symbol?)
(vline-value)
(vline-parameters default: (table) type: table?)
(vline-source default: "" type: string?))
+(define (serialize-vcomponent c)
+ (let ((children (table->list (vcomponent-children c))))
+ `(vcomponent ',(type c)
+ ,@(concatenate
+ (for (key . value) in (table->list (component-properties c))
+ (list (-> key symbol->string
+ string-downcase
+ string->keyword)
+ value)))
+ ,@(unless (null? children)
+ `((list ,@(map (lambda (child) (serialize-vcomponent child))
+ (map cdr children))))))))
+
(define (print-vcomponent c p)
- (format p "#<<vcomponent> ~a>"
- (type c)))
+ ((@ (ice-9 pretty-print) pretty-print)
+ (serialize-vcomponent c)
+ p))
(define false? not)