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"
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
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:
rlwrap
or some other readline program.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With