Clojure InstallEditorEditor PluginCreating a projectEnable parinferHello worldUsing the REPLEnhanced Static AnalysisInstalling Leiningen

Clojure Install

The easiest way to install Clojure is to visit: https://clojure.org/guides/getting_started

 

Follow the instructions for your operation system

Editor

Download Intellji from: https://www.jetbrains.com/idea/download/

The Community version is free and suitable for Clojure development

 

 

Editor Plugin

When your editor loads you should see a welcome screen something like below

 

In order to do Clojure development we need a editor plugin called Cursive https://cursive-ide.com/

To install it press the ⚙️ Configure drop down and click Plugins

Select Marketplace and type "cursive" into the search field, then press the install button

Restart Intellji

Creating a project

Press "Create New Project" on the welcome screen we saw earlier then select Clojure from the left hand side and then "Deps" then press ok

Choose a project name

Welcome to your new project

 

Enable parinfer

Open the preferences for Intellji

Navigate through Editor > General > Smart Keys > Clojure

and change the "Structural editing style" to Parinfer Indent mode

 

Clojure parentheses will now balance according to their indentation level in the code

Hello world

Right click your project and hover over the new menu and select "Clojure Namespace"

In the box that appears type src/core that means create a folder called src and create a file called core inside the default extension for Clojure files are .clj

 

Open the newly created file

and change the code to:

 

Using the REPL

To create a REPL right click your project within the file explorer

Then click "Create 'REPL for ...'"

Right click the project again and press "Run 'REPL for ...'"

A new window will appear with the REPL inside

 

The REPL is an alive instance of Clojure that can be used to get quick feedback on your program

In order to do so we need to learn how to load code into it:

Load file into the REPL

Right click anywhere inside a open Clojure file and hover over REPL and select "Load file in REPL"

You should see something like

 

Change REPL namespace to our current namespace

Right click inside the Clojure file hover over REPL and press "Switch REPL NS to Current file"

That should provide output like

 

There's two ways we can send some code to the REPL, it can either be written directly in, then press enter with your cursor at the end of the line

or sent from the source code

 

The end result should be something like

 

Enhanced Static Analysis

Download https://github.com/borkdude/clj-kondo/releases

clj-kondo-lsp-server-2019.11.23-standalone.jar

Download https://github.com/gtache/intellij-lsp/releases

at version of at least 1.6.0

Press shift twice and type "plugins"

Press the cog under plugins and click "Install Plugin from Disk..."

Select the LSP.zip in the file browser

Restart Intellji


Under preferences

Navigate to Languages & Frameworks > Language Server Protocol > Server Definitions

Change the select box to Raw command add the following under Extension cli;cljs;cljc;edn and command you will need to add java -jar <path to lsp jar file>

 

Type the following expression into a Clojure file

You should see a red squiggly line underneath if everything has been successful

Installing Leiningen

Navigate to https://leiningen.org/

Install it for your operating system

Leiningen will allow you to use many templates for Clojure