From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Colorized REPL Date: Sun, 27 Jan 2013 11:06:58 +0100 Message-ID: <87ehh79by5.fsf@pobox.com> References: <1354692089.25329.71.camel@Renee-desktop.suse> <1354697316.25329.83.camel@Renee-desktop.suse> <1354703255.25329.107.camel@Renee-desktop.suse> <87a9tmajov.fsf@gnu.org> <1355106191.22533.63.camel@Renee-desktop.suse> <87zk1l1t3x.fsf@gnu.org> <1356942598.2785.174.camel@Renee-desktop.suse> <87623dvy88.fsf@gnu.org> <1357726654.2798.103.camel@Renee-desktop.suse> <87k3rj7psf.fsf@gnu.org> <8738y6umof.fsf@gnu.org> <1359195310.3676.90.camel@Renee-desktop.suse> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1359281228 16166 80.91.229.3 (27 Jan 2013 10:07:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Jan 2013 10:07:08 +0000 (UTC) Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , guile-devel@gnu.org To: Nala Ginrut Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 27 11:07:27 2013 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 1TzP94-0001dy-Kl for guile-devel@m.gmane.org; Sun, 27 Jan 2013 11:07:26 +0100 Original-Received: from localhost ([::1]:47071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzP8m-0002mm-FV for guile-devel@m.gmane.org; Sun, 27 Jan 2013 05:07:08 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:59890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzP8i-0002mR-Nj for guile-devel@gnu.org; Sun, 27 Jan 2013 05:07:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzP8h-0007Qo-B6 for guile-devel@gnu.org; Sun, 27 Jan 2013 05:07:04 -0500 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:61044 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzP8h-0007Qf-6t; Sun, 27 Jan 2013 05:07:03 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 13370AB86; Sun, 27 Jan 2013 05:07:02 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=5NI4p3e7Zhpdrl7/UG6kJwcZ9Mw=; b=tBLCDp tcAaYcYpU20xB3dYAlW5pfVLglOuMBoYho7uJMbQNhIgLiSQyHIxarCzB7NnV0/R +sixwJuAIb9PdWHYM0z2V5JhITtgtfCZpXuuYLPj7+hZYaV+dxrTEysn3QcG7e5R HXzT087DQJRp1jKimw6WsupwZNQd2G4T/3Jrs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=NUCe1YzjVAz30w/wks1aUMAE7pRMWqL0 SmRn1mrikP60vR/H/ugqz8jgnm5kPbmEmUIlNaVAfIQBPx/KwfOEFJTnQuhFuulu V8yiOGjQABXc8mwbUEZMtJjRBCqax5udB9GeBAtHJeXSwxL2nYXuHQuEpl8+XDy5 HAdNpntw4wo= Original-Received: from a-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 0AE09AB85; Sun, 27 Jan 2013 05:07:02 -0500 (EST) Original-Received: from badger (unknown [88.160.190.192]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 73845AB84; Sun, 27 Jan 2013 05:07:01 -0500 (EST) In-Reply-To: <1359195310.3676.90.camel@Renee-desktop.suse> (Nala Ginrut's message of "Sat, 26 Jan 2013 18:15:10 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-Pobox-Relay-ID: 4B23D0B0-6869-11E2-8A0A-0A4F0E5B5709-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-Received-From: 208.72.237.25 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:15598 Archived-At: On Sat 26 Jan 2013 11:15, Nala Ginrut writes: > Please review it. ;-P A drive-by review (i.e., just style comments and random questions) > ;; Copyright (C) 2012 Free Software Foundation, Inc. 2013 > ;;;; Author: Mu Lei known as NalaGinrut > (define-module (ice-9 colorized) > #:use-module (ice-9 rdelim) > #:use-module ((srfi srfi-1) #:select (filter-map any proper-list?)) > #:use-module (srfi srfi-9) > #:use-module (system repl common) > #:export (activate-colorized custom-colorized-set! color-it colorize-it colorize > colorize-string colorized-display add-color-scheme!)) No tabs, please. In emacs this is (indent-tabs-mode nil) I think; you can M-x untabify also. > (define (activate-colorized) > (let ((rs (fluid-ref *repl-stack*))) > (if (null? rs) > (repl-default-option-set! 'print colorized-repl-printer) ; if no REPL started, set as default printer > (repl-option-set! (car rs) 'print colorized-repl-printer)))) ; or set as the top-REPL printer Nice > (define *color-list* > `((CLEAR . "0") Why are these upper-cased? Unless there is a reason, lower-case is better as it is easier to type and read. > (define (get-color color) > (assoc-ref *color-list* color)) Use assq-ref, the keys are symbols > (define (generate-color colors) > (let ((color-list > (filter-map (lambda (c) (assoc-ref *color-list* c)) colors))) Use get-color here; and is the intention to silently ignore unknown colors? > (define (colorize-the-string color str control) > (string-append (generate-color color) str (generate-color control))) The name is confusingly like "colorize-string" below. Better to have a more descriptive name, or maybe colorize-string-helper. > ;; test-helper functions > ;; when eanbled, it won't output colored result, but just normal. > ;; it used to test the array/list/vector print result. > (define *color-func* (make-fluid colorize-the-string)) > (define (disable-color-test) > (fluid-set! *color-func* colorize-the-string)) > (define (enable-color-test) > (fluid-set! *color-func* color-it-test)) Surely testing-related functions should not be here? > (define (color-it-inner color str control) > ((fluid-ref *color-func*) color str control)) Use parameters instead of fluids. > (define *pre-sign* > `((LIST . "(") > (PAIR . "(") > (VECTOR . "#(") > (ARRAY . #f))) > ;; array's sign is complecated, return #f so it will be handled by pre-print "complicated" > (define* (pre-print cs #:optional (port (current-output-port))) > (let* ((type (color-scheme-type cs)) > (control (color-scheme-control cs)) > (sign (assoc-ref *pre-sign* type)) assq-ref > (define *colorize-list* > `((,integer? INTEGER ,color-integer (BLUE BOLD)) > (,char? CHAR ,color-char (YELLOW)) > (,string? STRING ,color-string (RED)) Interesting :) Regards, Andy -- http://wingolog.org/