unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: Truncated print
Date: Tue, 05 Jan 2010 01:28:47 +0100	[thread overview]
Message-ID: <878wcd9yyo.fsf@gnu.org> (raw)
In-Reply-To: m3vdfjz8ct.fsf@pobox.com

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





  reply	other threads:[~2010-01-05  0:28 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 [this message]
2010-01-05  9:01       ` Andy Wingo
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=878wcd9yyo.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@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).