unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Llorens <daniel.llorens@bluewin.ch>
To: guile-devel <guile-devel@gnu.org>
Subject: Enable truncation of exception output
Date: Fri, 3 Feb 2017 14:40:33 +0100	[thread overview]
Message-ID: <38205FE3-791F-4EE8-BD7F-07BC6C0511DE@bluewin.ch> (raw)


(I've messed up with git send-email, the patch with this email is
at http://lists.gnu.org/archive/html/guile-devel/2017-02/msg00008.html).

Some objects have large printed representations and trying to print
them can kill the terminal. This is a serious problem when handling
e.g. big arrays.

For repl values there's (repl-default-option-set! 'print (lambda (val)
...)) which lets you override the default printing routine. But for
exceptions there's no equivalent. The default exception printers are
in (ice-9 boot-9) and are difficult to override. Besides, the format
of the exception output is often chosen by arguments to scm-error and
not by those printers.

The patch to master (ice-9 boot-9) lets you override the (format) used
internally by the exception printers. Then I rewrite the format string
in user code, see below. It's a bit hacky, maybe someone has a better
solution.

See also the other patch I've posted to the list to support arrays in
(truncated-print). The patches are independent, but they make each
other useful so to speak.

Regards

        Daniel

(In the code below for .guile, replace [AT] by the at symbol).

; Truncate output on exceptions. Requires exception-format in ice-9/boot.scm.
; FIXME doesn't handle e.g. "x~~~s" -> "x~~~[AT]y"
(define (rewrite-fmt fmt)
  (let loop ((f "") (b 0))
    (let ((next (string-contains-ci fmt "~s" b)))
      (if next
        (loop
         (if (or (zero? next) (not (char=? #\~ (string-ref fmt (- next 1)))))
           (string-append f (substring fmt 0 next) "~[AT]y")
           fmt)
         (+ b next 2))
        (string-append f (substring fmt b))))))

(when (defined? 'exception-format)
  (set! exception-format
        (lambda (port fmt . args)
          (apply format port (rewrite-fmt fmt) args))))




             reply	other threads:[~2017-02-03 13:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 13:40 Daniel Llorens [this message]
2017-03-10  8:47 ` Enable truncation of exception output Andy Wingo
2017-03-10  9:07   ` Ludovic Courtès
2017-03-10  9:17     ` Andy Wingo
2017-03-10  9:12   ` Daniel Llorens

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=38205FE3-791F-4EE8-BD7F-07BC6C0511DE@bluewin.ch \
    --to=daniel.llorens@bluewin.ch \
    --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).