utilities.print-tree

2016-12-04

Introduction

The utilities.print-tree system provides simple facilities for printing tree structures in an easy to read way using either ASCII or Unicode characters to render the parent-child relations. One focus is playing nicely with pretty printing.

The following example shows the result of printing the utilities.print-tree ASDF system without and with additional details added to nodes:

utilities.print-tree
??src
? ??package
? ??print-tree
??README.org

Note how pretty-printing of the "Depends-on" entry works seamlessly with tree printing:

utilities.print-tree
? Pathname   /home/jmoringe/code/cl/utilities.print-tree/
? Encoding   UTF-8
? Depends-on ((#<LOAD-OP > #<MODULE "utilities.print-tree" "src">
?              #<STATIC-FILE "utilities.print-tree" "README.org">)
?             (PREPARE-OP #<SYSTEM "utilities.print-tree">)
?             (COMPILE-OP #<SYSTEM "utilities.print-tree">))
??src
? ? Pathname   /home/jmoringe/code/cl/utilities.print-tree/src/
? ? Encoding   UTF-8
? ? Depends-on ((#<LOAD-OP >
? ?              #<CL-SOURCE-FILE "utilities.print-tree" "src" "package">
? ?              #<CL-SOURCE-FILE "utilities.print-tree" "src" "print-tree">)
? ?             (PREPARE-OP #<MODULE "utilities.print-tree" "src">)
? ?             (COMPILE-OP #<MODULE "utilities.print-tree" "src">))
? ??package
? ?   Pathname   /home/jmoringe/code/cl/utilities.print-tree/src/package.lisp
? ?   Encoding   UTF-8
? ?   Depends-on ((PREPARE-OP
? ?                #<CL-SOURCE-FILE "utilities.print-tree" "src" "package">)
? ?               (COMPILE-OP
? ?                #<CL-SOURCE-FILE "utilities.print-tree" "src" "package">))
? ??print-tree
?     Pathname   /home/jmoringe/code/cl/utilities.print-tree/src/print-tree.lisp
?     Encoding   UTF-8
?     Depends-on ((PREPARE-OP
?                  #<CL-SOURCE-FILE "utilities.print-tree" "src" "print-tree">)
?                 (COMPILE-OP
?                  #<CL-SOURCE-FILE "utilities.print-tree" "src" "print-tree">))
??README.org
    Pathname   /home/jmoringe/code/cl/utilities.print-tree/README.org
    Encoding   UTF-8
    Depends-on ((PREPARE-OP #<STATIC-FILE "utilities.print-tree" "README.org">)
                (COMPILE-OP #<STATIC-FILE "utilities.print-tree" "README.org">))

The following code produces this output:

  (defmethod print-component ((target stream) (depth t) (component asdf:component))
    (princ (asdf:component-name component) target))

  (defmethod print-details ((target stream) (depth t) (component asdf:component))
    (format target "Pathname   ~A~@:_~
                    Encoding   ~A~@:_~
                    Depends-on ~A"
            (asdf:component-pathname   component)
            (asdf:component-encoding   component)
            (asdf:component-depends-on 'asdf:load-op component)))

  (defmethod asdf:component-children ((component t))
    '())

  (labels ((do-it (details?)
             (fresh-line)
             (terpri)
             (print-tree *standard-output* (asdf:find-system :utilities.print-tree)
                         (make-node-printer #'print-component
                                            (when details? #'print-details)
                                            #'asdf:component-children))))
    (do-it nil)
    (do-it t))

The full code of this example is available in file:examples/asdf.lisp.

settings

Author
Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
Maintainer
Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
License
LLGPLv3