Question

I am not looking for an IDE or integrated REPL. I just wanted to ask if someone knows if it is possible to have a buffer editor in the REPL as know from 'psql' or some *nix shells.

In psql for example you just enter "\e" and you'll get the last command in your EDITOR and uppon exit it gets executed.

This would be awesome for clojure repl.

$ java -cp jline.jar:clojure-1.3.0.jar jline.ConsoleRunner clojure.main

So, is there such a feature? Where would it have to be implemented, in jline?

Solution:

rlwrap does the trick.

I had to compile readline ftp://ftp.gnu.org/gnu/readline/ and then rlwrap http://utopia.knoware.nl/~hlub/rlwrap/#rlwrap.

After that I could use the following shortcut to start the editor.

Ctrl + ^

rlwrap -m -- java -cp clojure-1.3.0.jar clojure.main

For the use with leiningen on Mac OSX I had to change the following:

lein 1.6.2
*** 226,233 ****
              rlwrap -m -q '"' echo "hi" > /dev/null 2>&1
              if [ $? -eq 0 ]; then
                  RLWRAP="$RLWRAP -r -m -q '\"'"
-             else
-                 RLWRAP="$RLWRAP -m --"
              fi
          fi
      fi
--- 226,231 ----

and export RLWRAP_EDITOR

export RLWRAP_EDITOR="vim +%L"

Was it helpful?

Solution

rlwrap

There are a number of ways to achieve what you want, but the rlwrap binary does what you need. I've also had some versioning issues with jline in the past on Mac OS X, so stopped using it.

When I type 'clj' in my terminal, it really executes the REPL wrapped with rlwrap via the following bash script in /usr/local/bin/clj:

#!/bin/sh
# Runs clojure.
# With no arguments, runs Clojure's REPL.

CLOJURE=$CLASSPATH:/usr/local/clojure/1.3.0/clojure-1.3.0.jar

rlwrap java -cp $CLOJURE clojure.main "$@"

Put the script anywhere in your path, to use.

Finally, you don't need the script, I just have it as a convenience. If rlwrap is on your system and clj is in your path, then you can simply type:

rlwrap clj

Further reading from the Clojure wiki book: Enhancing Clojure REPL with rlwrap

OTHER TIPS

See my answers to the questions One REPL to bind them all? and How to install Clojure on Ubuntu 10.04 from Github repo with no clojure.jar. Main points:

  • Don't "install" clojure at all. Install Leiningen, and let it manage the versions of clojure you have, as well as getting the classpaths right for repl or other usage.
  • If you must launch clojure by hand, use rlwrap or some other readline program.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top