From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: nalaginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: bug#13077: guile: add repl-option for customized print Date: Tue, 04 Dec 2012 13:19:18 +0800 Organization: HFG Message-ID: <1354598358.25329.4.camel@Renee-desktop.suse> References: <87hao21nte.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1354598381 25660 80.91.229.3 (4 Dec 2012 05:19:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Dec 2012 05:19:41 +0000 (UTC) Cc: 13077@debbugs.gnu.org To: Daniel Hartwig , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Dec 04 06:19:52 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tfkv9-0006pk-Cv for guile-devel@m.gmane.org; Tue, 04 Dec 2012 06:19:51 +0100 Original-Received: from localhost ([::1]:39388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tfkux-00008S-IJ for guile-devel@m.gmane.org; Tue, 04 Dec 2012 00:19:39 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:34671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tfkuq-000085-0E for guile-devel@gnu.org; Tue, 04 Dec 2012 00:19:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tfkuj-0000ib-4I for guile-devel@gnu.org; Tue, 04 Dec 2012 00:19:31 -0500 Original-Received: from mail-ie0-f169.google.com ([209.85.223.169]:35214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tfkui-0000iE-UL for guile-devel@gnu.org; Tue, 04 Dec 2012 00:19:25 -0500 Original-Received: by mail-ie0-f169.google.com with SMTP id c14so6370559ieb.0 for ; Mon, 03 Dec 2012 21:19:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:x-mailer:mime-version :content-transfer-encoding; bh=wmEFGCKBaHuUPE1yWb+vMkpNJZLf7I+ZdTZ98chmH+k=; b=ChnNgo/0b9og1uisybYbWjP0/Bzwi2Wo+McvdmGrvooSB5lB1Zgz37fiLrPGI61PwJ Fl0ffrCYmITS60mS+cpLnNPh9Ry5z+YP4S1lvbghTYUxQ0mzTDAxzRhQYKx/3lQg7kGL N7oEbCdVZ9O72HyD7TGhm8JpuDbvK2xBv911vaDcEubwtXXIN6fvG0wCMIGO4n5hn/x6 uQI7TCe7fr7Ptv821zWMUUFrCXiESmC9fMpaHlIvWOZMMju2wjy+L/tcLvlPcRxDUB5o 84ag2vM9EFC5wgbqnyzXgCD6bRR050aoTwCyTPfGkVXaEVfmp5d4bHWy0WEnSzz7UaJs TCmQ== Original-Received: by 10.50.208.41 with SMTP id mb9mr1487216igc.42.1354598363805; Mon, 03 Dec 2012 21:19:23 -0800 (PST) Original-Received: from [147.2.147.112] ([61.14.130.226]) by mx.google.com with ESMTPS id ff4sm9032215igc.13.2012.12.03.21.19.20 (version=SSLv3 cipher=OTHER); Mon, 03 Dec 2012 21:19:22 -0800 (PST) In-Reply-To: <87hao21nte.fsf@gmail.com> X-Mailer: Evolution 3.4.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.223.169 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15293 Archived-At: Hi Daniel! I believe this patch simplified my work, and 'colorized' module has been finished, I'm testing and debugging. I'll post it when it's all done. Thanks! On Tue, 2012-12-04 at 11:46 +0800, Daniel Hartwig wrote: > Package: guile > Severity: wishlist > Tags: patch > X-Debbugs-CC: nalaginrut > > Dear maintainer > > The attached patch adds a new repl-option to set a custom print > procedure. > > -- > scheme@(guile-user)> (use-modules (srfi srfi-1)) > scheme@(guile-user)> (iota 20) > $1 = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19) > scheme@(guile-user)> (define (repl-print* repl val) > (if (not (eq? val *unspecified*)) > (begin > (run-hook before-print-hook val) > (format #t "~20@y" val) > (newline)))) > scheme@(guile-user)> (use-modules (system repl common)) > scheme@(guile-user)> (repl-option-set! (car (fluid-ref *repl-stack*)) 'print repl-print*) > scheme@(guile-user)> (iota 20) > $2 = (0 1 2 3 4 5 6 7 …) > differences between files attachment > (0001-repl-add-repl-option-for-customized-print.patch) > From b0cadcb69a12a4ed2a205f4854af41bf926da20b Mon Sep 17 00:00:00 2001 > From: Daniel Hartwig > Date: Tue, 4 Dec 2012 11:41:35 +0800 > Subject: [PATCH] repl: add repl-option for customized print > > * module/system/repl/common.scm (repl-default-options) > (repl-print): Add option to use customized print procedure. > * doc/ref/scheme-using.texi (REPL Commands): Update. > --- > doc/ref/scheme-using.texi | 4 ++++ > module/system/repl/common.scm | 26 +++++++++++++++++--------- > 2 files changed, 21 insertions(+), 9 deletions(-) > > diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi > index 7eb84de..4f9e6db 100644 > --- a/doc/ref/scheme-using.texi > +++ b/doc/ref/scheme-using.texi > @@ -445,6 +445,10 @@ choice is available. Off by default (indicating compilation). > @item prompt > A customized REPL prompt. @code{#f} by default, indicating the default > prompt. > +@item print > +A procedure of two arguments used to print the result of evaluating each > +expression. The arguments are the current REPL and the value to print. > +By default, @code{#f}, to use the default procedure. > @item value-history > Whether value history is on or not. @xref{Value History}. > @item on-error > diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm > index 346ba99..fd41b09 100644 > --- a/module/system/repl/common.scm > +++ b/module/system/repl/common.scm > @@ -119,6 +119,11 @@ See , for more details.") > ((thunk? prompt) (lambda (repl) (prompt))) > ((procedure? prompt) prompt) > (else (error "Invalid prompt" prompt))))) > + (print #f ,(lambda (print) > + (cond > + ((not print) #f) > + ((procedure? print) print) > + (else (error "Invalid print procedure" print))))) > (value-history > ,(value-history-enabled?) > ,(lambda (x) > @@ -206,15 +211,18 @@ See , for more details.") > (% (thunk)))) > > (define (repl-print repl val) > - (if (not (eq? val *unspecified*)) > - (begin > - (run-hook before-print-hook val) > - ;; The result of an evaluation is representable in scheme, and > - ;; should be printed with the generic printer, `write'. The > - ;; language-printer is something else: it prints expressions of > - ;; a given language, not the result of evaluation. > - (write val) > - (newline)))) > + (cond > + ((repl-option-ref repl 'print) > + => (lambda (print) (print repl val))) > + ((not (eq? val *unspecified*)) > + (begin > + (run-hook before-print-hook val) > + ;; The result of an evaluation is representable in scheme, and > + ;; should be printed with the generic printer, `write'. The > + ;; language-printer is something else: it prints expressions of > + ;; a given language, not the result of evaluation. > + (write val) > + (newline))))) > > (define (repl-option-ref repl key) > (cadr (or (assq key (repl-options repl))