Hi Andy!

Andy Wingo <wi...@pobox.com> writes:

> On Sun 03 Jan 2010 00:52, l...@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’.



Reply via email to