laurent.orseau
2020-5-2 12:52:15

Script of the day: Have a Menu that displays all open tabs in DrRacket. (Currently, DrRacket displays only the first 10).

How to install: Click on Scripts | Manage scripts | New script… Enter “All tabs” (a new script opens filled with a template.

Replace the template with the code below. Save the file.

Click on Scripts | All tabs. A new menu “All tabs” appears in DrRacket!


spdegabrielle
2020-5-2 13:06:37

Pls post to reddit


laurent.orseau
2020-5-2 13:09:50

I don’t use reddit, but if you want to do it, be my guest :slightly_smiling_face:


spdegabrielle
2020-5-2 13:31:16

Can you post to Racket users and I’ll link back


spdegabrielle
2020-5-2 13:32:51

I’m actually digging a hole in the garden atm. I just worry because lots of good stuff shows up on slack and gets lost forever. RacketUsers>Reddit anyway



laurent.orseau
2020-5-2 14:06:27

@robby I must be doing something wrong. I’m still trying to make a quickscript that does send the-drracket-frame open-in-new-tab some-file, and it keeps failing with “something’s missing in the namespace.” The problem is that it only gives me one missing module at a time, and each time I have to restart DrRacket.

Up to now, I’ve added these modules: drracket/tool-lib racket/match/stxtime syntax/parse/experimental/template syntax/parse/lib/function-header racket/contract/private/arr-util syntax/name racket/contract/base racket/contract/private/opt-guts racket/contract/private/arr-i-parse racket/contract/private/top-sort racket/contract/private/ds-helpers syntax/free-vars (submod racket/match/define-forms lazy-require-aux-1-0) and it keeps asking for more. I can easily imagine it’s going to ask for a hundred or more, which would take me hours…

What am I missing?


robby
2020-5-2 14:07:27

Is that method being called on the main thread of the DrRacket event space?


laurent.orseau
2020-5-2 14:08:23

I have a namespace anchor in the tool.rkt file that defines the DrRacket plugin


robby
2020-5-2 14:08:48

In general I think DrRackets api stuff depends on being in a fairly reasonable context (parameter settings etc) and I guess that the way you set up namespaces could be breaking those assumptions.


laurent.orseau
2020-5-2 14:09:29

Then I create a namespace with: (define (make-script-namespace) (define ns (make-base-empty-namespace)) (for ([mod '(racket/class racket/gui/base <many other requires> (namespace-attach-module (namespace-anchor->empty-namespace a) mod ns)) ns) then I call the script in this namespace, sending it this (the DrRacket frame%).


robby
2020-5-2 14:09:45

Maybe the right thing is for any DrRacket functions that get injected into the scripts namespace to wrap things and go back to the reasonable context.


robby
2020-5-2 14:10:36

The tab creation sets up a new DrRacket environment (to run user programs) and maybe that’s what’s failing here.


robby
2020-5-2 14:11:03

Are you creating separate threads to run scripts on?


laurent.orseau
2020-5-2 14:13:00

No, I just do: (parameterize ([current-namespace ns]) (let ([f (dynamic-require file fun)] [<some-args> ...] (apply f <some-args>))) where f is the function received from the script


robby
2020-5-2 14:13:52

Probably the startup of a user program (which the new tab does) requires the current namespace to be the original drr namespace.


robby
2020-5-2 14:14:14

I am not really sure what the hidden invariants of these methods are, tho.


laurent.orseau
2020-5-2 14:14:16

The namespace anchor is not enough then?


robby
2020-5-2 14:14:33

The namespace anchor creates a new namespace.


laurent.orseau
2020-5-2 14:14:38

right


robby
2020-5-2 14:14:50

So that would be a different namespace.


laurent.orseau
2020-5-2 14:14:59

ok


robby
2020-5-2 14:15:07

Maybe just worth trying to see?


robby
2020-5-2 14:15:33

If that’s the issue then we can discuss how best to arrange things so that script authors don’t suffer too much


laurent.orseau
2020-5-2 14:15:35

you mean remove the namespace altogether and run directly? I’ll try


laurent.orseau
2020-5-2 14:16:05

Yes, it works


robby
2020-5-2 14:16:10

Or paramètreriez to put it back before the call


laurent.orseau
2020-5-2 14:16:38

(did you just include a french word in the middle of your sentence? :smile: )


laurent.orseau
2020-5-2 14:16:58

Not sure what you mean though, put what back?


robby
2020-5-2 14:17:05

parameterize


robby
2020-5-2 14:17:20

My phone autocompletes in French sometimes.


laurent.orseau
2020-5-2 14:17:27

I see :slightly_smiling_face:


laurent.orseau
2020-5-2 14:18:35

I guess I could send the namespace to the script, so that the script could parameterize correctly, just for a function call?


laurent.orseau
2020-5-2 14:18:47

Looks dirty though


robby
2020-5-2 14:19:40

The more I think about this the more I think it would be better to insist that scripts are in modules and then you just don’t need to make any new namespaces


robby
2020-5-2 14:19:44

Is that feasible?


laurent.orseau
2020-5-2 14:20:41

(sending the namespace works)


laurent.orseau
2020-5-2 14:20:52

scripts are in modules


laurent.orseau
2020-5-2 14:21:41

Hm…. wait, did I really over-engineer it then?


laurent.orseau
2020-5-2 14:21:56

Why do I need a new namespace…?


robby
2020-5-2 14:22:19

Oh! I figured it was because scripts used the top level.


robby
2020-5-2 14:22:30

But I didn’t actually look to see! Sorry!


robby
2020-5-2 14:22:40

Maybe just not creating a namespace is the best way.


robby
2020-5-2 14:22:53

But there are security issues with scripts.


robby
2020-5-2 14:23:13

If they were to be isolated then that would probably defeat a lot of useful things.


robby
2020-5-2 14:23:34

Yeah so I guess just not making a new namespace is best?


laurent.orseau
2020-5-2 14:25:15

ah, one problem is that if you don’t create a new namespace, you can’t edit a script and reload it, because it will have been loaded already. Which means you need to restart drracket


robby
2020-5-2 14:25:25

Ah


robby
2020-5-2 14:26:21

Do you want new copies of files the script requires or just the one script?


robby
2020-5-2 14:26:33

The main file, I mean.


laurent.orseau
2020-5-2 14:27:22

Each time the script is invoked, i want to revisit it from scratch (unless marked ‘persistent’)


laurent.orseau
2020-5-2 14:27:31

(not sure if that answers your question)


robby
2020-5-2 14:27:59

Let’s say that a script has a require in it


robby
2020-5-2 14:28:46

When I reload that script, do I get the new version of the required file, or the first version of the required file? (I mean, what behavior do you want?)


laurent.orseau
2020-5-2 14:30:47

Currently, I guess (non-persistent—the default) scripts get a new version, while scripts marked persistent require only once


laurent.orseau
2020-5-2 14:31:32

But I’m a little uncertain if that’s desirable though.


robby
2020-5-2 14:31:32

The reason I ask is that there may be a different approach that would reload only the one file (and not thjngs it requires)


laurent.orseau
2020-5-2 14:31:44

ah, that’s interesting


robby
2020-5-2 14:32:03

Or maybe things in a specific directory possibly.


laurent.orseau
2020-5-2 14:32:25

(that might be backward incompatible though)


robby
2020-5-2 14:32:53

I think you can interpose on the “what name does this module have” part of racket and then give the scripts a fresh name every time.


robby
2020-5-2 14:33:17

That will cause them to appear as new modules and thus get reloaded


robby
2020-5-2 14:33:39

I am not sure this would work but maybe worth exploring


laurent.orseau
2020-5-2 14:34:16

oh, so you require all of them in the global namespace, and give them a new name everytime. I see.


laurent.orseau
2020-5-2 14:34:26

But memory consumption will increase linearly?


robby
2020-5-2 14:34:48

Dinno


robby
2020-5-2 14:34:53

Dunno


robby
2020-5-2 14:35:03

There probably is a way to get rid of them.


robby
2020-5-2 14:35:15

But let’s see if this can work at all first.


robby
2020-5-2 14:35:29

Look for module declare in the docs



robby
2020-5-2 14:35:59

I am not completely sure how this gets invoked but maybe it can make it work


robby
2020-5-2 14:36:20

It may be best to move this discussion to the users or dev mailing list


robby
2020-5-2 14:36:36

Want me to start the conversation?


robby
2020-5-2 14:36:53

Of maybe I will just ask Matthew.


robby
2020-5-2 14:36:54

:)


laurent.orseau
2020-5-2 14:38:01

brb


robby
2020-5-2 14:43:41

I sent email @laurent.orseau


laurent.orseau
2020-5-2 15:04:25

Thanks for the email with Matthew.


laurent.orseau
2020-5-2 15:05:37

Another simple but inelegant solution is to pass a function do-in-drracket that takes a thunk, parameterizes with the global namespace and calls the thunk.


laurent.orseau
2020-5-2 15:39:14

Inelegant as in “not transparent for the user”, when the purpose of quickscript is to make things easier… So I’m willing to give your idea some more thought.


laurent.orseau
2020-5-2 15:49:34

(after reading your email more carefully i realize that’s what you said :) )


wanpeebaw
2020-5-3 01:58:08

@wanpeebaw has joined the channel