3

In bash or Ruby's IRB, I can run a command or evaluate an expression, then use the up arrow on my keyboard to edit and rerun the same code. (This may be something I have configured, but I don't think so.)

This doesn't work for me in the Clojure REPL; I just see ^[[A typed when I press the up arrow.

Is there a way to "retype" the last line?

Nathan Long
  • 122,748
  • 97
  • 336
  • 451
  • Hmmm, hitting the left arrow to edit the line I'm working on produces similar output. Maybe this is a problem with my machine? – Nathan Long Sep 03 '13 at 13:47
  • how do you start your repl? – Jonas Sep 03 '13 at 13:48
  • @Jonas - using `java -cp clojure-1.5.1.jar clojure.main` or the shorter version after setting the CLASSPATH variable. (I'm just trying some Getting Started tutorials.) – Nathan Long Sep 03 '13 at 13:50
  • 4
    try `rlwrap java -cp clojure-1.5.1.jar clojure.main` Also, take a look at lein (http://leiningen.org) which most clojure programmers use. – Jonas Sep 03 '13 at 13:52

1 Answers1

14

As mentioned in comments rlwrap is picking up where a native Clojure REPL is not "doing it", including arrow navigation, history and more.

However most (if not all) of the time Clojure is used together with lein, which has a built in REPL. Every time a Clojure REPL is needed, you can do:

lein repl

You don't necessarily need to have a project to start it, it can be started from anywhere (given that you have lein in your PATH) and has many other very nice properties, which rlwrap won't give you.

To name a few:

  • If you run it form under the root of your project, it will load project's classpath, so you can interact with all the libs and code of your project.

  • It will also start an nREPL which you can connect to from anywhere (local/remote) including your favorite IDE/editors that are "nREPL capable". This would allow (for example) vim or emacs to use that REPL you started with lein repl to evaluate, compile, navigate (source) right from the editor.

  • Before it starts it reads and "obeys" ~/.lein/profiles.clj, where you can configure your sessions with pretty much anything you want: gpg keys, repl-options, dependencies, plugins, etc.. which will be loaded/configured on the lein repl

tolitius
  • 22,149
  • 6
  • 70
  • 81