~:@y allows for truncation to an absolute maximum width
authorAndy Wingo <wingo@pobox.com>
Tue, 29 Dec 2009 20:15:08 +0000 (21:15 +0100)
committerAndy Wingo <wingo@pobox.com>
Tue, 29 Dec 2009 20:15:08 +0000 (21:15 +0100)
* module/ice-9/format.scm (format): Allow ~:@y to interpret the width as
  the maximum width, inclusive of whatever else has already been output.
* doc/ref/misc-modules.texi (Formatted Output): Document this.

doc/ref/misc-modules.texi
module/ice-9/format.scm

index 1449292..a6bb6c3 100644 (file)
@@ -648,6 +648,11 @@ necessary.
 within @var{width} columns (79 by default), on a single line. The
 output will be truncated if necessary.
 
+@nicode{~:@@y} is like @nicode{~@@y}, except the @var{width} parameter
+is interpreted to be the maximum column to which to output. That is to
+say, if you are at column 10, and @nicode{~60:@@y} is seen, the datum
+will be truncated to 50 columns.
+
 @item @nicode{~?}
 @itemx @nicode{~k}
 Sub-format.  No parameters.
index 2d12dbf..133f8e4 100644 (file)
                                         (car params)
                                         79)))
                          (case modifier
-                           ((colon colon-at)
-                            (format:error "illegal modifier in ~~?"))
                            ((at)
                             (format:out-str
                              (with-output-to-string 
                                (lambda ()
-                                 (truncated-print (next-arg) #:width width)))))
+                                 (truncated-print (next-arg)
+                                                  #:width width)))))
+                           ((colon-at)
+                            (format:out-str
+                             (with-output-to-string 
+                               (lambda ()
+                                 (truncated-print (next-arg)
+                                                  #:width
+                                                  (max (- width
+                                                          format:output-col)
+                                                       1))))))
+                           ((colon)
+                            (format:error "illegal modifier in ~~?"))
                            (else
                             (pretty-print (next-arg) format:port
                                           #:width width)