From e3d628fba1652d2005d8856512e81a1f2c0698ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 2 Mar 2019 23:11:36 +0100 Subject: Add print-vcomponent procedure. --- code.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'code.scm') diff --git a/code.scm b/code.scm index eba732bc..14581c90 100755 --- a/code.scm +++ b/code.scm @@ -1,7 +1,8 @@ (define-module (code) #:export (extract localize-date sort* drop-time! copy-date drop-time %date<=? date-today? color-if - for-each-in STR-YELLOW STR-RESET)) + for-each-in STR-YELLOW STR-RESET + print-vcomponent)) (use-modules (srfi srfi-19) (srfi srfi-19 setters) @@ -65,3 +66,20 @@ (define-syntax-rule (for-each-in lst proc) (for-each proc lst)) + +(define* (print-vcomponent comp #:optional (depth 0)) + (let ((kvs (map (lambda (key) (cons key (get-attr comp key))) + (attributes comp)))) + (format #t "~a <~a> :: ~:a~%" + (make-string depth #\:) + (type comp) comp) + (for-each-in kvs + (lambda (kv) + (let ((key (car kv)) + (value (cdr kv))) + (format #t "~a ~20@a: ~a~%" + (make-string depth #\:) + key value)))) + (for-each-in (children comp) + (cut print-vcomponent <> (1+ depth))))) + -- cgit v1.2.3