Skip to content

Clojure configurationλ︎

Enable the Clojure module with LSP support in the ~/.config/doom/init.el configuration file

(clojure +lsp)
lsp

Use the doom command to load the modules

doom sync

Cider configurationλ︎

Define variables to configure CIDER

~/.config/doom/config.el
(use-package! cider
  :after clojure-mode
  :config
  (setq cider-show-error-buffer t               ;'only-in-repl
        cider-font-lock-dynamically nil         ; use lsp semantic tokens
        cider-eldoc-display-for-symbol-at-point nil ; use lsp
        cider-prompt-for-symbol nil
        cider-use-xref nil                      ; use lsp

        cider-repl-pop-to-buffer-on-connect nil ; REPL buffer shown at starup
        clojure-enable-kaocha-runner t          ; enable Kaocha test runner
        cider-repl-display-help-banner nil      ; disable help banner
        cider-print-fn 'puget                   ; pretty printing with sorted keys / set values
        cider-result-overlay-position 'at-point ; results shown right after expression
        cider-overlays-use-font-lock t
        cider-repl-buffer-size-limit 100        ; limit lines shown in REPL buffer
        cider-repl-history-size 42
        )
  (set-lookup-handlers! '(cider-mode cider-repl-mode) nil) ; use lsp
  (set-popup-rule! "*cider-test-report*" :side 'right :width 0.4)
  (set-popup-rule! "^\\*cider-repl" :side 'bottom :quit nil)
  ;; use lsp completion
  (add-hook 'cider-mode-hook (lambda () (remove-hook 'completion-at-point-functions #'cider-complete-at-point))))

(use-package! clojure-mode
  :config
  (setq clojure-indent-style 'align-arguments
        clojure-align-forms-automatically t
        clojure-toplevel-inside-comment-form t  ;; evaluate expressions in comment as top level
))

Restart Doom Emacs after larger changes

Space q r to restart Doom Emacs when significant changes are made or something is not working correctly

Clojure CLIλ︎

Practicalli Clojure install guide

Clojure CLI provides a way to run Clojure code, packaged Clojure (jar) and of course run a Clojure REPL.

Practicalli Clojure install guide details prerequisites, Clojure install options and supporting tools for an enhanced developer workflow. Or visit the Clojure Getting Started guide for just the Clojure CLI.

practicalli/clojure-deps-edn provides a wide range of community tools that can easily be added to the development environment and used across all projects.

Aliases are required for many command examples

Without installing practicalli/clojure-deps-edn many commands provided in this book will not work, unless the same alias configuration is added to a either a project or user level deps.edn configuration.

Clojure LSPλ︎

Clojure LSP installation guide Practicalli Clojure LSP configuration

Clojure Language Server Protocol LSP

Clojure LSP provides a standard set of features for editing and manipulating source code, e.g. autocompletion, code navigation, refactor code, inline syntax errors and idiom warnings.

LSP and the REPL

The REPL is used to design Clojure effectively by providing instant feedback on code expressions as they are written and evaluated. A REPL based workflow supports the most effective approach to development of Clojure apps and services. Clojure LSP supports the editing activities to write Clojure code effectively, providing a static analysis of the code base that drives advance editing, navigation and refactor tasks.

Install the Clojure LSP command line tool and configure ~./config/clojure-lsp/config.edn or use Practicalli Clojure LSP configuration which provides a complete configuration for clojure-lsp (config.edn), including a wide range of snippets and less restrictive formatting rules (cljfmt.edn).

Clone via SSH

git clone -o practicalli git@github.com:practicalli/clojure-lsp-config.git $XDG_CONFIG_HOME/clojure-lsp

Clone via HTTPS

git clone -o practicalli https://github.com/practicalli/clojure-lsp-config.git $XDG_CONFIG_HOME/clojure-lsp

Clone via SSH

git clone -o practicalli git@github.com:practicalli/clojure-lsp-config.git $HOME/.clojure-lsp

Clone via HTTPS

git clone -o practicalli https://github.com/practicalli/clojure-lsp-config.git $HOME/.clojure-lsp

Run the clojure-lsp command in a terminal to ensure the install was successful.

clojure-lsp -v
Clojure LSP and clj-kondo

Clojure LSP includes clj-kondo to provide an implementation of the Language Server Protocol for the Clojure Language. clj-kondo provides static analysis of source code files, providing subtle warnings as Clojure code is written to help the developer follow idioms and avoid syntatic errors.

Referencesλ︎