Skip to content

Quick start: Clojure

Roger Erens edited this page Nov 9, 2023 · 18 revisions

Clojure is a robust, practical, and fast programming language with a set of useful features that together form a simple, coherent, and powerful tool.

Conjure has deep support for Clojure either in the original JVM setting or JavaScript via ClojureScript. We’re focusing on regular JVM Clojure here, see other guides for specifics on ClojureScript since it has its own nuances.

Prerequisites

  1. Install the latest Neovim.

  2. Install the Conjure plugin.

  3. Install the Clojure CLI tools (my preference) or Leiningen.

  4. Get a project set up with the CLI tools or Leiningen.

Start your nREPL + CIDER middleware

You can skip this section by installing vim-jack-in and executing the appropriate command such as :Clj or :Lein. It’ll start an nREPL server with all of the appropriate middleware inside your Neovim instance, you can then connect to it as described in the final section.

With Clojure CLI

Configure an alias in the project or user level deps.edn file to include the appropriate dependencies, e.g. $XDG_CONFIG_HOME/clojure/deps.edn or $HOME/.clojure/deps.edn.

{:aliases
 {:repl/conjure
    {:extra-deps {nrepl/nrepl       {:mvn/version "1.0.0"}
                  cider/cider-nrepl {:mvn/version "0.42.1"}}
     :main-opts  ["--main" "nrepl.cmdline"
                  "--middleware" "[cider.nrepl/cider-middleware]"
                  "--interactive"]}
  }}

In the root of the project, start a REPL process and an nREPL server with the added CIDER middleware.

clj -M:repl/conjure

Alternatively, you can start the same thing without creating a deps.edn file with this.

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.42.1"}}}' \
    --main nrepl.cmdline \
    --middleware '["cider.nrepl/cider-middleware"]' \
    --interactive

With Leiningen

Simply add the CIDER plugin to your project.clj.

:plugins [[cider/cider-nrepl "0.42.1"]]

And start your REPL which will automatically start nREPL + CIDER.

lein repl

Start editing!

Now open any .clj or .cljc file and start evaluating! It will automatically connect to the correct host and port as you open a source file, provided .nrepl-port was created when you started your REPL (this should be the case). If not, you can either create that file yourself or use :ConjureConnect [port] to get started. Note that .nrepl-port is in the working directory that you ran clj nrepl.cmdline from, so start nvim in that directory.

If you’re unsure how to evaluate things with Conjure, please refer to :help conjure, :help conjure-client-clojure-nrepl and :ConjureSchool (an interactive tutorial).