[plt-scheme] The filename of the file in the definition window

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Dec 19 16:25:05 EST 2007

On Dec 19, 2007 3:14 PM, Jens Axel Soegaard <jensaxel at soegaard.net> wrote:
> Robby Findler skrev:
> > The port should have it:
> >
> > Welcome to MzScheme v3.99.0.5 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
> >> (call-with-input-file "/home/robby/tmp.ss" object-name)
> > #<path:/home/robby/tmp.ss>
> >
> > but why do you need it?
>
> I get
>
>    #<struct:object:...pper/stepper-tool.ss:618:8>
>
> as the result of calling object-name with the port.
> Makes sense it doesn't work, since the contents
> of the definition window might be unsaved.

Oh, right. This is going to change in the next release (it has already
changed in SVN). It is now a path or a special symbol indicating that
there is no path (if the file has never been saved).

Handing out that object to the user's program like that is insecure
(they can get it out of the syntax objects). Here's a self-modifiying
program (note that you can do worse things, since you can go from the
editor to the drscheme frame and thus get at lots of drscheme's
internal state).

(define-syntax (m stx)
  (with-syntax ([x (syntax-source stx)])
    #'x))

(require (lib "mred.ss" "mred")
         (lib "class.ss"))

(let* ([ed (m)]
       [line1 (send ed get-text
                    (send ed paragraph-start-position 0)
                    (send ed paragraph-end-position 0))]
       [mth (regexp-match #rx"^; ([0-9]+)" line1)]
       [lckd (send ed is-locked?)])
  (send ed lock #f)
  (if mth
      (begin
        (send ed delete
              (send ed paragraph-start-position 0)
              (send ed paragraph-end-position 0))
        (send ed insert (format "; ~a" (+ 1 (string->number (cadr mth)))) 0 0))
      (send ed insert "; 0\n" 0 0))
  (send ed lock lckd))

> This leads to another question: How do I check whether the
> contents of the definition windows has been saved?
>
>
> The reason I need the name is that I want to pass the content
> along to an external executable.

I'm not positive, but wouldn't it be better to pass the port along?
The port library lets you do all kind of things, like forking the port
if it needs to go two places, etc. Also, you don't have to deal with
the "is it saved" question.

Robby


Posted on the users mailing list.