Pretty printing has traditionally been a black box process, displaying program code using a set of ﬁxed layout rules. Its utility can be greatly enhanced by opening it up to user control. The facilities described in this chapter provide general and powerful means for specifying pretty-printing behavior.
By providing direct access to the mechanisms within the pretty printer that make dynamic decisions about layout, the macros and functions pprint-logical-block, pprint-newline, and pprint-indent make it possible to specify pretty printing layout rules as a part of any function that produces output. They also make it very easy for the function to support detection of circularity and sharing and abbreviation based on length and nesting depth. Using the function set-pprint-dispatch, one can associate a user-deﬁned pretty printing function with any type of object. A small set of new format directives allows concise implementation of user-deﬁned pretty-printing functions. Together, these facilities enable users to redeﬁne the way code is displayed and allow the full power of pretty printing to be applied to complex combinations of data structures. ________________________________________________________________
Заметка для реализации: This chapter describes the interface of the XP pretty printer. XP is described fully in , which also explains how to obtain a portable implementation. XP uses a highly eﬃcient linear-time algorithm. When properly integrated into a Common Lisp, this algorithm supports pretty printing that is only fractionally slower than ordinary printing.