[plt-scheme] user-extensible graphical "print" format

From: Gregory Cooper (greg at cs.brown.edu)
Date: Sun May 16 09:26:15 EDT 2004

You can define a custom language%, overriding the render-value and
render-value/format methods.  This is how FrTime displays values that
change over time (look at frtime-tool.ss in the frtime collection).

One thing that makes the task a little tricky: The tool module (with the
language% subclass) can't define or even statically import the conversion
function (since the structure definitions come from a dynamically
instantiated language module).  Instead, you need to override on-execute
and extract the appropriate function(s) with namespace-variable-value
(using run-in-user-thread).

Since DrScheme creates a fresh instance of the language's module each time
the user opens a new window or clicks Execute, you really want to
accumulate a collection of (weakly held) converters, all of which get
applied.  This is what the code in frtime-tool.ss does.

Otherwise, defining the converter itself is trivial.  It's typically just
a function like

(define (cvt val)
  (if (my-struct? val)
      (make-snip val)

where make-snip constructs an appropriate snip instance, possibly an
instance of image-snip% or string-snip% (or a custom subclass).

Hope this helps,

On Sun, 16 May 2004, Neil W. Van Dyke wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> Can I define special graphical display "snip%" classes that are used
> when DrScheme needs to display objects of certain types in the
> Interactions window?
> Like what "syntax-snip%" does, but without having to modify the DrScheme
> source to hook it in.

Posted on the users mailing list.