From: Andy Wingo <wingo@pobox.com>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Truncated print
Date: Tue, 05 Jan 2010 10:01:00 +0100 [thread overview]
Message-ID: <m3k4vxx6wj.fsf@pobox.com> (raw)
In-Reply-To: <878wcd9yyo.fsf@gnu.org> ("Ludovic Courtès"'s message of "Tue, 05 Jan 2010 01:28:47 +0100")
Hi :)
On Tue 05 Jan 2010 01:28, ludo@gnu.org (Ludovic Courtès) writes:
>> On Sun 03 Jan 2010 00:52, ludo@gnu.org (Ludovic Courtès) writes:
>
> [...]
>
>>>> +(truncated-print "The quick brown fox" #:width 10) (newline)
>>>> +@print{} "The quick brown..."
>>>
>>> I think it’d be nice to default to ‘HORIZONTAL ELLIPSIS’ (U+2026).
>>> Perhaps the ellipsis string could be a keyword parameter?
>
> What do you think?
I think that it sounds like you are interested in this :-) I would be
happy with doing nothing, but happier still if someone fixed this for
me. :)
I'm attaching the patch I had, when I found out the issues I wrote in my
mail.
Happy hacking,
Andy
Modified module/ice-9/pretty-print.scm
diff --git a/module/ice-9/pretty-print.scm b/module/ice-9/pretty-print.scm
index 9a0edbd..1507b4d 100644
--- a/module/ice-9/pretty-print.scm
+++ b/module/ice-9/pretty-print.scm
@@ -1,6 +1,6 @@
-;;;; -*-scheme-*-
+;;;; -*- mode: scheme; coding: utf-8 -*-
;;;;
-;;;; Copyright (C) 2001, 2004, 2006, 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2001, 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -285,7 +285,7 @@ into @var{width} characters. By default, @var{x} will be printed using
@var{display?} keyword argument.
The default behaviour is to print depth-first, meaning that the entire
-remaining width will be available to each sub-expressoin of @var{x} --
+remaining width will be available to each sub-expression of @var{x} --
e.g., if @var{x} is a vector, each member of @var{x}. One can attempt to
\"ration\" the available width, trying to allocate it equally to each
sub-expression, via the @var{breadth-first?} keyword argument."
@@ -300,8 +300,8 @@ sub-expression, via the @var{breadth-first?} keyword argument."
((= i len)) ; catches 0-length case
((= i (1- len))
(print (ref x i) (if (zero? i) width (1- width))))
- ((<= width 4)
- (display "..."))
+ ((<= width 2)
+ (display "…"))
(else
(let ((str (with-output-to-string
(lambda ()
@@ -309,7 +309,7 @@ sub-expression, via the @var{breadth-first?} keyword argument."
(if breadth-first?
(max 1
(1- (floor (/ width (- len i)))))
- (- width 4)))))))
+ (- width 2)))))))
(display str)
(lp (next x) (- width 1 (string-length str)) (1+ i)))))))
@@ -348,8 +348,8 @@ sub-expression, via the @var{breadth-first?} keyword argument."
width
(+ (string-length (caar fixes))
(string-length (cdar fixes))
- 3)))
- (format #f "~a~a...~a"
+ 1)))
+ (format #f "~a~a…~a"
(caar fixes)
(substring str (string-length (caar fixes))
(- width (string-length (cdar fixes)) 3))
@@ -363,7 +363,7 @@ sub-expression, via the @var{breadth-first?} keyword argument."
(error "expected a positive width" width))
((list? x)
(cond
- ((>= width 5)
+ ((>= width 3)
(display "(")
(print-sequence x (- width 2) (length x) (lambda (x i) (car x)) cdr)
(display ")"))
@@ -371,7 +371,7 @@ sub-expression, via the @var{breadth-first?} keyword argument."
(display "#"))))
((vector? x)
(cond
- ((>= width 6)
+ ((>= width 4)
(display "#(")
(print-sequence x (- width 3) (vector-length x) vector-ref identity)
(display ")"))
@@ -379,7 +379,7 @@ sub-expression, via the @var{breadth-first?} keyword argument."
(display "#"))))
((uniform-vector? x)
(cond
- ((>= width 9)
+ ((>= width 7)
(format #t "#~a(" (uniform-vector-element-type x))
(print-sequence x (- width 6) (uniform-vector-length x)
uniform-vector-ref identity)
--
http://wingolog.org/
next prev parent reply other threads:[~2010-01-05 9:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1NPbB4-00045m-3S@cvs.savannah.gnu.org>
2010-01-02 23:52 ` Truncated print Ludovic Courtès
2010-01-03 12:22 ` Andy Wingo
2010-01-05 0:28 ` Ludovic Courtès
2010-01-05 9:01 ` Andy Wingo [this message]
2010-01-08 20:55 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3k4vxx6wj.fsf@pobox.com \
--to=wingo@pobox.com \
--cc=guile-devel@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).