Is there a way to get DrRacket to indent all on save?

That's about it. I would like formatting to be done automagically when a definition file is saved.

I figure it must be possible, but may be require a script or plugin. I can't find a preference or setting that would do it.

4 Likes

I think it’s fair to say that this is not something DrRacket does out of the box.

I see the value.

This might be something that can be done in a plug-in or as a change to an existing plugin.

https://pkgd.racket-lang.org/pkgn/search?q=plugin+&tags=

S.

Now I’m wondering if DrRacket can reformat on each keypress, in the same way that it automatically balances parentheses.

I have a quickscript sript that removes trailing whitespace from lines and then saves the file (There's currently no way to hook scripts to run on particular actions like saving). You might be able to use it as a starting point for using with the formatter/pretty printer of your choice.

http://pasterack.org/pastes/476

2 Likes

Thanks for the script.

Working on it :slight_smile: No idea when this will be ready though.

Are you working on a DrRacket change or is there a way to do it with a plugin?

I'm working on upgrading Quickscript to have hooks that trigger on certain events.

And yes, you can do what you want with a DrRacket plugin, by augmenting on-save-file by extending the definitions text% with drracket:get/extend:extend-definitions-text. See a plugin example in the docs.

(The purpose for the new hook system in Quickscript is to simplify the process of writing such plugins.)

1 Like

The first time I looked at that page it went right over my head. Thanks for making me look at it again. The magic of Lisp.

Adding hooks to Quickscript sounds like a great idea. If there's any way I can help let me know.

Now that Quickscript has hooks (see here), it should be fairly easy to format as you wish:

From this script, just replace the line that removes trailing spaces with

       (define new-str (program-format str))

This requires Racket ≥v8.10.3 (which is in the snapshot for now). Let me know if that works — or not!

1 Like