unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Hartwig <mandyke@gmail.com>
To: nalaginrut <nalaginrut@gmail.com>
Cc: 13077@debbugs.gnu.org, guile-devel@gnu.org
Subject: Re: bug#13077: guile: add repl-option for customized print
Date: Tue, 4 Dec 2012 13:34:52 +0800	[thread overview]
Message-ID: <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg@mail.gmail.com> (raw)
In-Reply-To: <1354598358.25329.4.camel@Renee-desktop.suse>

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

On 4 December 2012 13:19, nalaginrut <nalaginrut@gmail.com> wrote:
> 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.

Glad to hear it.

Attached is an alternate patch that handles before-print-hook and
*unspecified* outside of the custom print procedure, to avoid the need
for boilerplate there.

--
scheme@(guile-user)> (define (repl-print* repl 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)> (use-modules (srfi srfi-1))
scheme@(guile-user)> (iota 20)
$1 = (0 1 2 3 4 5 6 7 …)

[-- Attachment #2: 0001-repl-add-repl-option-for-customized-print.alt.patch --]
[-- Type: application/octet-stream, Size: 2948 bytes --]

From 2251a259058524fbe631fd287c95b43882227f79 Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <mandyke@gmail.com>
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 |   21 +++++++++++++++------
 2 files changed, 19 insertions(+), 6 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..3f3e785 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -119,6 +119,11 @@ See <http://www.gnu.org/licenses/lgpl.html>, 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)
@@ -209,12 +214,16 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
   (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)))
+         (else
+          ;; 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))
-- 
1.7.10.4


  reply	other threads:[~2012-12-04  5:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87hao21nte.fsf@gmail.com>
2012-12-04  5:19 ` bug#13077: guile: add repl-option for customized print nalaginrut
2012-12-04  5:34   ` Daniel Hartwig [this message]
2012-12-04  6:30     ` nalaginrut
2012-12-04  6:34       ` Daniel Hartwig
2012-12-12  4:03     ` Nala Ginrut
2012-12-12  5:00       ` Daniel Hartwig
2012-12-12  5:49         ` Nala Ginrut
     [not found]           ` <CAN3veRdDA-LwBhu7_Uthfj1h7HGzvFOPLoOtkoyd-MQOA+1Xug@mail.gmail.com>
2012-12-12  6:03             ` Daniel Hartwig
     [not found]   ` <CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg__21131.9749746055$1354599399$gmane$org@mail.gmail.com>
2012-12-04  6:39     ` Thien-Thi Nguyen
2012-12-04  7:36       ` Daniel Hartwig

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='CAN3veReRKhsGip-jev8YyYf_xbTLFFK-bEN=9bR8BddatGWLKg@mail.gmail.com' \
    --to=mandyke@gmail.com \
    --cc=13077@debbugs.gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=nalaginrut@gmail.com \
    /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).