tags:

views:

295

answers:

3

I'm using rlwrap, but I don't have tab-completion, and characters with accents get mangled. This is on OSX 10.6 in Terminal.app.

+1  A: 

ClojureX attempts to be just what you want to OS X users. I've got no experience with it myself (I'm a Linux user), but I'm under the impression that the ClojureX folks will be willing to help you if you run into weird problems (character mangling? I don't get that, with or without rlwrap...).

Update: Here's a link to an announcement on the Clojure group re: some recent changes in ClojureX...

There's a second option for readline-like functionality in JVM-based console apps -- jline. Use something like

java -cp $CLASSPATH jline.ConsoleRunner clojure.main

(with jline.jar included in $CLASSPATH, of course) if you'd like to give it a try.

Also, I don't think I've ever heard of tab completion in stand-alone Clojure REPLs. Most people use Emacs / Aquamacs + SLIME, Vimclojure or some Java IDE with a Clojure plugin for stuff like that. Well, some other people have heard about it alright (see Brian's answer). And I've since found this description of how to set up tab completion with jline. And I've since checked the sources for ClojureX -- it does set up tab completion for you. That makes this part of my original answer a bit of a blunder, I guess... But the fact remains that ClojureX is a very safe bet which may save you the trouble of configuring things yourself.

Michał Marczyk
+2  A: 

Use the -f flag to rlwrap to enable tab completion. It's going to be static completion though, based on a static list of symbols in some file you specify. If you want dynamic completion (based on any symbol that's currently defined in your running REPL), you should try Emacs + SLIME or equivalent.

In any case, here's one way to generate a list of symbols to tab-complete. You will have to regenerate this file from time to time because new symbols are added to Clojure's core in every version. (This code works with bleeding edge clojure-contrib; clojure.contrib.io was called duck-streams in earlier versions.)

user> (use 'clojure.contrib.io)
nil
user> (with-out-writer "/home/user/.clj-tabcompletion"
        (doseq [[sym _] (ns-publics 'clojure.core)]
          (println sym)))
nil

Then:

$ rlwrap -f ~/.clj-tabcompletion java -jar clojure.jar
Clojure 1.2.0-master-SNAPSHOT
user=> def<TAB>
definline    defmacro     defmethod    defmulti     defn         defonce      defprotocol  defstruct    deftype
user=> def

If your terminal is mangling characters with accents, you likely have an encoding or locale problem. It works fine for me. I don't use OS X and don't know what terminal you use, so I can't help. In Konsole in Linux, inside rlwrap:

user=> (println "àèìòùáéíóúäëïöüâêîôûãõñ")
àèìòùáéíóúäëïöüâêîôûãõñ
nil
user=> (println "牛が牧場で草を食べている。")
牛が牧場で草を食べている。
nil
Brian Carper
A: 

Thanks Michał, as the guy behind ClojureX I'm obviously happy if if somebody recommends the project :-) BTW: ClojureX is long past the stage of only working on Macs. I use and test it on OSX and OpenSolaris, but it also works on Linux and - surprise - Windows with Cygwin.

@Michiel: Since you are on a Mac I'd be happy if you tried out ClojureX and gave me some feedback if stuff works for you. Completions with rlwrap can be done in two ways: either you use the one we provide or you create your own in /.clojure-completions.

Michael Kohl