From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Daniel Llorens Newsgroups: gmane.lisp.guile.devel Subject: Enable truncation of exception output Date: Fri, 3 Feb 2017 14:40:33 +0100 Message-ID: <38205FE3-791F-4EE8-BD7F-07BC6C0511DE@bluewin.ch> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1486129254 27729 195.159.176.226 (3 Feb 2017 13:40:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 3 Feb 2017 13:40:54 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Feb 03 14:40:50 2017 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZe6c-00071E-2Q for guile-devel@m.gmane.org; Fri, 03 Feb 2017 14:40:50 +0100 Original-Received: from localhost ([::1]:34831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZe6g-0000QM-5t for guile-devel@m.gmane.org; Fri, 03 Feb 2017 08:40:54 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZe6X-0000QH-Jt for guile-devel@gnu.org; Fri, 03 Feb 2017 08:40:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZe6U-0007wS-HJ for guile-devel@gnu.org; Fri, 03 Feb 2017 08:40:45 -0500 Original-Received: from vimdzmsp-sfwd03.bluewin.ch ([195.186.120.132]:37982 helo=smtpauths.lb.bluewin.ch) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZe6U-0007v0-2g for guile-devel@gnu.org; Fri, 03 Feb 2017 08:40:42 -0500 Original-Received: from 4box.hq.corp.viasat.com ([213.193.80.99]) by vimdzmsp-sfwd03.bluewin.ch Swisscom AG with SMTP id Ze6Qce0VN8iZ8Ze6QcsmPd; Fri, 03 Feb 2017 14:40:39 +0100 X-Bluewin-Spam-Analysis: v=2.1 cv=MtTykzue c=1 sm=1 tr=0 a=DzaHVtLsrNCQ5PccsnG91A==:117 a=DzaHVtLsrNCQ5PccsnG91A==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=mDV3o1hIAAAA:8 a=kOhoVAW2-c3OxXW4ZLMA:9 a=CjuIK1q_8ugA:10 a=zZE6B0XuYjMA:10 a=_FVE-zBwftR9WsbkzFJk:22 X-Bluewin-Spam-Score: 0.00 X-FXIT-IP: IPv4[213.193.80.99] Epoch[1486129239] X-Bluewin-AuthAs: dll@bluewin.ch X-Mailer: Apple Mail (2.1878.6) X-CMAE-Envelope: MS4wfKoEPT2YaECCYJWWnuaT/6dIfX2oQh2YQWone1kuAzT/jXi5AGwgX2Zz7PR9BVpUWlBLzUpFblW5d9tZnpVFXVqG7PAxLM5Qu39U0PZFWaqiwfiOLkjB IZRuOxoh6QmRYXvwm+Xxz+0mQMUhMzVv/t+83LNpC4wRy2v/o6w1CfyBMhG1BZ0QHcdeYy5GBkhzOQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.186.120.132 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18887 Archived-At: (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))))