Skip to content

Instantly share code, notes, and snippets.

@phoe
Last active August 6, 2017 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoe/b3c8424820317b9291036d3d2edf65e0 to your computer and use it in GitHub Desktop.
Save phoe/b3c8424820317b9291036d3d2edf65e0 to your computer and use it in GitHub Desktop.
Pretty-printing function for config-like plists
(defun pprint-plist (*standard-output* list)
"Pretty-prints a plist with newlines after each key-value pair.
This will break if not called at toplevel, but works well enough for my use case."
(pprint-logical-block (*standard-output* list :prefix "(" :suffix ")")
(loop for cell on list by #'cddr
do (write (first cell))
(write-char #\Space)
(write (second cell))
(when (cddr cell)
(terpri *standard-output*)
(write-char #\Space)))
(terpri *standard-output*)))
#|
Example of printed output:
(:DB-NAME "gateway"
:DB-USER "secret"
:DB-PASS "supersecret"
:DB-HOST "secret.ksi.ii.uj.edu.pl"
:DB-PORT 54321
:DB-USE-SSL :NO
:TEST-DB-NAME "gateway-test"
:TEST-DB-USER "secret"
:TEST-DB-PASS "supersecret"
:TEST-DB-HOST "secret.ksi.ii.uj.edu.pl"
:TEST-DB-PORT 54321
:TEST-DB-USE-SSL :NO
)
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment