From 9274c3dd4058b3f63ba97570fc2f1598debbc03d Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 29 Dec 2009 21:15:08 +0100 Subject: [PATCH] ~:@y allows for truncation to an absolute maximum width * 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 | 5 +++++ module/ice-9/format.scm | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/ref/misc-modules.texi b/doc/ref/misc-modules.texi index 1449292cd..a6bb6c3cb 100644 --- a/doc/ref/misc-modules.texi +++ b/doc/ref/misc-modules.texi @@ -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. diff --git a/module/ice-9/format.scm b/module/ice-9/format.scm index 2d12dbf04..133f8e4ef 100644 --- a/module/ice-9/format.scm +++ b/module/ice-9/format.scm @@ -487,13 +487,23 @@ (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) -- 2.20.1