Closed dbp closed 11 months ago
Thanks for the report.
You can create a REPL buffer two ways:
From a racket-run
command. This is the main, intended use case for the REPL.
From a racket-repl
command. As its doc string says, you can do this but there are caveats.
Show a Racket REPL buffer in some window.
IMPORTANT
The main, intended use of Racket Mode's REPL is that you find-file some specific .rkt file, then run it using racket-run or racket-run-module-at-point. The resulting REPL will correspond to those definitions and match your expectations.
If you really want to start a REPL for no file in particular, then you could use this racket-repl command. But the resulting REPL will have a minimal "#lang racket/base" namespace. You could enter "(require racket)" if you want the equivalent of "#lang racket". You could also "(require racket/enter)" if you want things like "enter!". But in some sense you'd be "using it wrong". If you actually don't want to use Racket Mode's REPL as intended, then consider using a plain Emacs shell buffer to run command-line Racket.
Although the doc string doesn't include this among the caveats, a bunch of settings get conveyed from Emacs variables to the Racket Mode back end process as part of a run command. These include:
racket-pretty-print
:point_left: racket-memory-limit
racket-error-context
racket-submodules-to-run
racket-user-command-line-arguments
This doesn't happen with the racket-repl
command.
So that's the explanation, and you have an idea for a work-around.
Instead?
I could document these extra caveat for the racket-repl
command. But not everyone reads the doc string. And anyway this isn't really an improvement, it's just documenting a lack of improvement. :smile:
A real improvement might be for the racket-repl
command to do a run command, just to convey these values.
racket-repl.rkt
file if it exists, i.e. a kind of init file for the REPL. (You could do this today with racket-run
, manually, of course.)I guess another option is to print a message in the REPL buffer, ~= "This racket-repl command buffer has limits; see the doc string" and maybe even linkify that to the doc string.
Ahh -- that helps clarify a lot. I think if there were a message along the lines of "Running racket-repl on its own has limited settings; you may want to use racket-run
on a buffer instead" or something like that when you ran the standalone, that might be helpful.
(Also, most of the time you want contents of the file... it just so happens that I was testing out some stuff that I hadn't written into a file, so didn't need that, or I probably wouldn't have gotten myself into this trouble.)
I just pushed a commit 5a69b3f to a topic branch, which does one option I mentioned above: Change racket-repl
into a command that just runs a certain "init" file. (The name and contents of which a user can customize, of course).
This seems so obviously the right thing to do instead, that I'm a little suspicious and want to sleep on it before merging. :smile: But it worked well in my initial testing, and I think this is at least in the right ballpark.
I went through a few rounds of dog-fooding this and fine-tuning, but ended up merging what I described above.
This addresses the specific issue you reported.
It also allows customizing a .rkt
(or for that matter .rhm
or whatever extension file with a #lang
line) which is the file run when you M-x racket-repl
. So it acts as a kind of little init file. I think in the past a few people have asked for something like this.
Thank you! This is great.
I am using doom-emacs, which I don't think messes with the mode much (though I just switched to it, so might be wrong!). I noticed that in the REPL, structs are not pretty printed; I've seen this in emacs before, and the little poking made it seem like the
racket-pretty-print
variable should maybe control that? either way, reproduction is here:I would have expected those to have been identical?
(Or if I shouldn't have, is there some setting so that I can get that behavior?)