`rlwrap racket`

I've been setting up my .inputrc so that I can get vi-keybinding-goodness in various shells/repls. For racket, rlwrap ends up overwriting the ">" prompt (I can see it momentarily, then it disappears). I ended up faking the prompt with:

rlwrap --always-readline --substitute-prompt "> " racket

aka rlwrap -a -S "> " racket.

I just thought I'd post/archive this solution, in case others run into the same thing. This is on MacOS 14.5, running from tcsh.

(And in other, different random quirkiness of rlwrap: the python repl shows its prompt fine, but requires a special passing-through of ^D and even then doesn't see it unless preceded by a space(!?); racket & other shells have no problem with recognizing ^D.)

At the risk outing myself as someone familiar with neither Vi nor rlwrap, some things that might (or might not) be relevant:

  • Since Racket 8.4, the default command-line REPL has been based on the Chez Scheme "expression editor", expeditor. It provides history and completion features similar to a line-editing library, but it is aware of S-expressions (even mult-line S-expressions), and Racket's version adds the syntax coloring and indentation tools also used by DrRacket. In addition to many default keybindings, it has a customization API that can do a lot.
  • If you don't want to use expeditor, you can use the ,input meta-command for xrepl to specify what to do instead (taking effect on next start). In particular, ,input readline selects the Racket readline library, which by default uses libedit.
  • If you want to use GNU Readline specifically with Racket's readline, either set the environment variable PLT_READLINE_LIB to the path to the library, or install the Racket package readline-gpl to find it automatically.
2 Likes

I started writing a Vi mode for expeditor once, and then decided the primitives didn't quite let me do what I wanted without diving further into internals than I cared to. Despite using Vi modes in most shells (and with Vim as my editor), I've stuck with the default expeditor stuff for now—it's pushed me to do less in the REPL and more in easy-to-run modules and functions :slight_smile:

1 Like