1.0.33.6: prettier PRINT-OBJECT default method
authorGabor Melis <mega@hotpop.com>
Fri, 4 Dec 2009 17:59:48 +0000 (17:59 +0000)
committerGabor Melis <mega@hotpop.com>
Fri, 4 Dec 2009 17:59:48 +0000 (17:59 +0000)
If *PRINT-PRETTY*, the default method of PRINT-OBJECT now establishes
a logical block around PRINT-UNREADABLE-OBJECT that, in turn, adds a
few PPRINT-NEWLINES to allow for the stuff between #< and > be broken
into multiple lines as the pretty printer sees fit. This allows #<...>
to be wrapped properly.

https://bugs.launchpad.net/sbcl/+bug/488979

NEWS
src/code/print.lisp
src/pcl/print-object.lisp
tests/print.impure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index 364bfc2..3d11b7d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ changes relative to sbcl-1.0.33:
     Willem Broekema; launchpad bug lp#489698).
   * bug fix: some minor code rearrangements to reenable warning-free building
     from CMUCL (reported by xme@gmx.net; launchpad bug lp#491104)
+  * bug fix: PRINT-OBJECT for clos instances respects the right margin when
+    pretty printing
 
 changes in sbcl-1.0.33 relative to sbcl-1.0.32:
   * new port: support added for x86-64 NetBSD.  (thanks to Aymeric Vincent)
index 31b48ab..8e6e0c8 100644 (file)
                     :level nil :length nil)
              (write-char #\space stream))
            (when body
+             (pprint-newline :fill stream)
              (funcall body))
            (when identity
              (when (or body (not type))
                (write-char #\space stream))
+             (pprint-newline :fill stream)
              (write-char #\{ stream)
              (write (get-lisp-obj-address object) :stream stream
                     :radix nil :base 16)
            (pprint-logical-block (stream nil :prefix "#<" :suffix ">")
              (print-description)))
           (t
-            (write-string "#<" stream)
-            (print-description)
-            (write-char #\> stream))))
+           (write-string "#<" stream)
+           (print-description)
+           (write-char #\> stream))))
   nil)
 \f
 ;;;; OUTPUT-OBJECT -- the main entry point
index b5c2500..7711dab 100644 (file)
   (fmakunbound 'print-object)
   (defgeneric print-object (object stream))
   (defmethod print-object ((x t) stream)
-    (print-unreadable-object (x stream :type t :identity t))))
+    (if *print-pretty*
+        (pprint-logical-block (stream nil)
+          (print-unreadable-object (x stream :type t :identity t)))
+        (print-unreadable-object (x stream :type t :identity t)))))
 (/show0 "done replacing placeholder PRINT-OBJECT with DEFGENERIC")
 \f
 ;;;; a hook called by the printer to take care of dispatching to PRINT-OBJECT
index 7766b39..382483a 100644 (file)
       (let ((*print-pretty* t))
         (assert (string= (princ-to-string 'bar) "BAR"))))))
 
+;;; bug-lp#488979
+
+(defclass a-class-name () ())
+
+(assert (find #\Newline
+              (let ((*print-pretty* t)
+                    (*print-right-margin* 10))
+                (format nil "~A" (make-instance 'a-class-name)))
+              :test #'char=))
+
+(assert (not (find #\Newline
+                   (let ((*print-pretty* nil)
+                         (*print-right-margin* 10))
+                     (format nil "~A" (make-instance 'a-class-name)))
+                   :test #'char=)))
+
 ;;; success
index 8a41bfe..436b013 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.33.5"
+"1.0.33.6"