[plt-scheme] Re: function for reading text from Scheme files

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sun Nov 19 23:41:44 EST 2006

FWIW, open-input-graphical-file does something like the below
internally (plus other stuff) and returns a port, rather than just the
editor.

Robby

At Sun, 19 Nov 2006 20:36:35 -0800 (PST), Danny Yoo wrote:
> >    * This is not robust: I really would want to somehow get the editor%
> >      that DrScheme is itself using, but haven't figured out how to pull
> >      that out of Framework yet.
> 
> ... Actually, I don't think we to do anything complicated after all! 
> After more closely reading reading:
> 
> http://download.plt-scheme.org/doc/352/html/mred/mred-Z-H-623.html#node_sec_8.2.1
> 
> it sounds like we should be able to handle all different kinds of snips 
> already, since the snips have a reliable encoding that auto-load their 
> required snip classes.
> 
> Ah, in that case, it's just a matter of doing something like this:
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (module read-text mzscheme
>    (require (lib "mred.ss" "mred")
>             (lib "class.ss"))
> 
>    (provide read-text)
> 
>    ;; read-text: path -> string
>    ;; Given a path, opens it and returns its text.  Images and other snips
>    ;; are munged.
>    (define (read-text path)
>      (let ([editor (new text%)])
>        (send editor load-file path)
>        (send editor get-text))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> Much simpler.  And if we wanted to get closer to the data, we can use 
> OPEN-INPUT-GRAPHICAL-FILE which should be able to handle files with snips 
> in them too.  My apologies about making things more complicated than they 
> needed to be; I'm still learning the API.
> 
> 
> Best of wishes!
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.