[racket] Reading drracket files into text%

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Aug 31 15:14:34 EDT 2010

Would this help: 

;; String (instance Text%) -> Void 
;; load the content of file f into text editor t, 
;; strip meta-data in first three lines 
(define (load f t)
  (send t load-file f)
  (define txt (send t get-text))
  (define inp (open-input-string txt))
  (define fst (read-line inp))
  (define res
    (if (string<=? ";;" fst) 
         (lambda (op)
           (read-line inp)
           (read-line inp)
           (copy-port inp op)))
  (send t select-all)
  (send t delete)
  (send t insert res))

No test, just a use case: 

  (define f (new frame% [label "hello world"][width 500][height 100]))
  (define t (new text%))
  (define e (new editor-canvas% [parent f][editor t]))
  (load "intermediate.rkt" t)
  (send f show #t))

On Aug 31, 2010, at 2:49 PM, Ryan Golbeck wrote:

> What's the proper way to read a file produced by DrRacket into a text% object?
> Using load-file produces problems when DrRacket has created a file
> where the first three lines contain meta data information about the
> language to use.
> Thanks,
> -ryan
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.