News for hackers. Stuff that matters.
Re:Not Lisp again (2009) by lispm on Wednesday May 03, 2017 @02:14PM (#14258507)
Hmm, my editor does it for me.

Wait, even Lisp does that for me, because it has a built-in source code pretty printer:

Call the pretty printer to format this mess:

    CL-USER 41 > (let ((*print-case* :downcase))
    (pprint '(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."
    (let ((str (if newline (concatenate 'string (string #\Newline) str) str)))
    (with-output-to-string (s) (map 'string (lambda (x) (princ x s) (when (char= x #\Newline)
    (dotimes (i padding) (princ #\Space s)))) str))))
    ))

It prints wonderfully formatted and indented code:

    (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."
      (let ((str
             (if newline
                 (concatenate 'string (string #\Newline) str)
               str)))
        (with-output-to-string (s)
          (map 'string
               (lambda (x)
                 (princ x s)
                 (when (char= x #\Newline)
                   (dotimes (i padding) (princ #\Space s))))
               str))))
Now one would only need to fix this beginner level code.

There are no comments on this comment yet.