inf clojure REPL - boot-clj/boot GitHub Wiki
Introduction
Using inf-clojure
with boot
should be a simple task, because there are no external dependencies whatsoever. The simplicity of setup and use may appeal to some, but those who seek a REPL with more advanced functionality should take a look at CIDER instead.
Company-mode code-completions
For code-completions to work with company-mode, the REPL needs to be started with the '--no-colors' flag so ANSI color codes won't be injected into your *inf-clojure*
process output.
Setup
There are two predominant ways of connecting to your boot REPL:
- Start the server and connect a client both from within Emacs
- Start the server in your boot
deftask
or from command line, and connect a client from Emacs
Server + Client in Emacs
Setting inf-clojure-program
to boot -C repl
should just work.
(setq inf-clojure-program "boot -C repl")
Running M-x inf-clojure
will start a REPL server and connect to it.
Client-only Emacs setup
Boot setup
In your build.boot
, compose (repl :server true)
into your task. Alternatively, you could run boot -C repl -s
in your command line.
Emacs setup
Set inf-clojure-program
to start just the client:
(setq inf-clojure-program "boot -C repl -c")
The client will detect the existence of .nrepl-port
in your project root directory, and connect to the correct repl.
Bonus: Connecting to a specific port
To connect to a specific port, once the nRepl server has started, take note of the port number and connect to it in emacs by running M-x inf-clojure-connect
(or C-c M-c
)
Tip: You can start inf-clojure and switch to the REPL by running C-c C-z
from your Clojure source files.
Some additional helper functions:
(defun reload-current-clj-ns (next-p)
(interactive "P")
(let ((ns (clojure-find-ns)))
(message (format "Loading %s ..." ns))
(inf-clojure-eval-string (format "(require '%s :reload)" ns))
(when (not next-p) (inf-clojure-eval-string (format "(in-ns '%s)" ns)))))
This (re)loads the current namespace of the buffer. I bind this to C-c C-k
.