Skip to content

Instantly share code, notes, and snippets.

@shrdlu68
Created June 18, 2018 09:31
Show Gist options
  • Save shrdlu68/beeed6385d9a323eebfdee5437c41dd8 to your computer and use it in GitHub Desktop.
Save shrdlu68/beeed6385d9a323eebfdee5437c41dd8 to your computer and use it in GitHub Desktop.
(defun add-text-padding (str &key padding newline)
"Add padding to text STR. Every line except for the first one, will be
prefixed with PADDING spaces. If NEWLINE is non-NIL, newline character will
be prepended to the text making it start on the next line with padding
applied to every single line."
(with-output-to-string (out-stream)
(with-input-from-string (in-stream str)
(loop initially (format out-stream "~A~:[~;~%~]" (read-line in-stream nil nil) newline)
for line = (read-line in-stream nil nil)
while line
do (format out-stream "~v@{ ~}~A~:[~;~%~]" padding line newline)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment