unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Truncated print
       [not found] <E1NPbB4-00045m-3S@cvs.savannah.gnu.org>
@ 2010-01-02 23:52 ` Ludovic Courtès
  2010-01-03 12:22   ` Andy Wingo
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2010-01-02 23:52 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

Howdy!

"Andy Wingo" <wingo@pobox.com> writes:

> commit b8596c08ac2ef2201c1e8559ac5f4d62ebde3d91
> Author: Andy Wingo <wingo@pobox.com>
> Date:   Tue Dec 29 13:26:41 2009 +0100
>
>     add ~@y truncated printing directive to format
>     
>     * doc/ref/misc-modules.texi (Formatted Output): Add documentation for
>       the new ~@y format directive.
>       (Pretty Printing): Add documentation for truncated-write.
>     
>     * module/ice-9/format.scm (format): Add ~@y, for doing a truncated
>       print. Also, allow both ~y variants to take a width parameter.

Nice!  Can you please add test cases, e.g., based on the examples added
to the manual?

> +(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?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Truncated print
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2010-01-03 12:22 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

Hello :)

On Sun 03 Jan 2010 00:52, ludo@gnu.org (Ludovic Courtès) writes:

>> commit b8596c08ac2ef2201c1e8559ac5f4d62ebde3d91
>> Author: Andy Wingo <wingo@pobox.com>
>> Date:   Tue Dec 29 13:26:41 2009 +0100
>>
>>     add ~@y truncated printing directive to format
>
> Nice!  Can you please add test cases, e.g., based on the examples added
> to the manual?

Sure, will do.

>> +(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?

Having it be a keyword parameter would complicate things somewhat, as
there are some hardcoded lengths in there. It could work.

But perhaps a bigger problem is that if you're in a non-unicode
locale -- *as Guile is by default, without a call to setlocale* -- the
`…' will expand to `...', which uses up more characters, thus the
"truncated" part of things doesn't work as advertised.

So either we play games with locale conversion (OK, but complicated), or
we setlocale() at the beginning and punt on the issue. See
http://lists.gnu.org/archive/html/guile-devel/2009-12/msg00025.html.

Given Mike's mail, I think we should be calling setlocale(). What do you
think?

Andy
-- 
http://wingolog.org/




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Truncated print
  2010-01-03 12:22   ` Andy Wingo
@ 2010-01-05  0:28     ` Ludovic Courtès
  2010-01-05  9:01       ` Andy Wingo
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2010-01-05  0:28 UTC (permalink / raw)
  To: guile-devel

Hi Andy!

Andy Wingo <wingo@pobox.com> 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?
>
> Having it be a keyword parameter would complicate things somewhat, as
> there are some hardcoded lengths in there. It could work.
>
> But perhaps a bigger problem is that if you're in a non-unicode
> locale -- *as Guile is by default, without a call to setlocale* -- the
> `…' will expand to `...', which uses up more characters, thus the
> "truncated" part of things doesn't work as advertised.

Once the string port patch I posted is applied, the following function
comes in handy:

--8<---------------cut here---------------start------------->8---
(define (ellipsis encoding)
  (define e "…")

  (with-fluids ((%default-port-encoding encoding))
    (catch 'misc-error
      (lambda ()
        (with-output-to-string
          (lambda ()
            (display e))))
      (lambda (key . args)
        "..."))))
--8<---------------cut here---------------end--------------->8---

Another approach would be ‘string->encoding’ (a generalization of
‘string->utf8’), but we don’t have that yet.

I guess we have to play tricks anyway to know whether a given character
can be represented in a given encoding.

What do you think?

Thanks,
Ludo’.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Truncated print
  2010-01-05  0:28     ` Ludovic Courtès
@ 2010-01-05  9:01       ` Andy Wingo
  2010-01-08 20:55         ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2010-01-05  9:01 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

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/




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Truncated print
  2010-01-05  9:01       ` Andy Wingo
@ 2010-01-08 20:55         ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2010-01-08 20:55 UTC (permalink / raw)
  To: guile-devel

Hi!

Andy Wingo <wingo@pobox.com> 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. :)

Done:

  http://git.sv.gnu.org/cgit/guile.git/commit/?id=c5e05a1c70d7a3db2456677524872a590624285f

Thanks,
Ludo’.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-01-08 20:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
2010-01-08 20:55         ` Ludovic Courtès

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).