Search code examples
clojure

Why my clojure repl formatting is broken?


I am new to Clojure, and I am usually using it from (Spac)emacs, where the repl formats fine. However, when I try to use the repl within a gnome-terminal, then the formatting is broken, i.e. after 'sending' some code, the line of code gets 'reformatted' as shown in the screencast below: enter image description here

Anybody has some idea what is going on here? The terminal is just a basic 'gnome-terminal' on Fedora.

B.t.w. the same screencast is used for reporting an issue with criterium about the bench example hanging.


Solution

  • Disclaimer: this is not a solution to the problem, but it shows, where the problem lies and what are workarounds.

    TL;DR: call clojure (which does not use rlwrap¹; use Rebel-Readline instead, for more features

    clj calls clojure, but checks, if rlwrap is installed and uses that to call clojure with some settings, that are suitable for a Lisp.

    rlwrap is a great tool, to get readline capabilities with interactive CLI tools, that don't have it (e.g. emacs/vi-mode, history, "hippy" completion). But in this case it is the culprit to smash up the REPL. What's underlying problem is not clear, but in cases like this the options usually are: buggy software (the terminal, rlwrap, or the way Clojure interacts with the terminal), wrong/buggy TERM settings or term-capabilities.

    That said, rlwrap might be the "just good enough" option here anyway. First of all Clojure developers tend to use the REPL via the editor anyway. Second there is a far superior option to get what rlwrap brings to the table: Rebel-Readline

    Beside emacs/vi-modes and history it brings (and probably more):

    • syntax highlighting for both input and output (with pretty-printing)
    • multi-line edit in the REPL
    • proper auto-completion
    • showing the doc-string of the function under the cursor

    ¹) From: https://github.com/hanslub42/rlwrap

    rlwrap is a 'readline wrapper', a small utility that uses the GNU Readline library to allow the editing of keyboard input for any command.