[plt-scheme] The filename of the file in the definition window
Robby Findler wrote:
>> 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).
Fine.
> Handing out that object to the user's program like that is insecure
> (they can get it out of the syntax objects).
Ah, but I am not doing that. The plan is to let
front-end/complete-program call the external tool via
system from "process.ss", then capture the output and
convert the output to a syntax-object like this:
#`(display #,captured-output)
The net effect is that the contents of the definition
window is "piped" through the shell command, and the
result is shown in the interaction window.
> 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))
That's clever! Best hack I have seen in ages.
And of course given a filename, the same risk will be there...
... but I am willing to run the risk!
>> 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.
Well, I as described above I actually want to call the external
tool via "system" from (lib "process.ss"), so I can't pass
the port along.
--
Jens Axel Søgaard