When I wrote about formatting Clojure buffers1 I also mentioned that Clojure LSP2 can take care of this among other things. Since my working days are pretty much Clojure days, it’s time to check out how LSP can help me in this regard and whether the experience is worth an extra tool.

Installing Clojure LSP is trivial so I will leave you on your own with that. After the installation the first thing I tried is the obvious M-x eglot in a Clojure buffer, but all I got was a connection timeout error as a reply. Weird, I thought, this has never happened with LaTeX. However, the solution was simple: I just needed to increase the default value of eglot-connect-timeout to 60.

Emacs can leverage many goodies from Clojure LSP thanks to Eglot, but some of them out of the box interfere with CIDER. For instance, the integration with ElDoc is better left in the capable hands of Eglot in order to avoid duplicates when displaying documentation.

(setq-default cider-eldoc-display-for-symbol-at-point nil)

(defun mu-cider-disable-eldoc ()
  "Let LSP handle ElDoc instead of CIDER."
  (remove-hook 'eldoc-documentation-functions #'cider-eldoc t))

(add-hook 'cider-mode-hook #'mu-cider-disable-eldoc)

In a similar fashion I put Clojure LSP in charge of completions. This approach is useful when in a Clojure buffer all I need is some poking around to understand the code in front of me. There is no need to jack-in with CIDER to do just that.

(defun mu-cider-disable-completion ()
  "Let LSP handle completion instead of CIDER."
  (remove-hook 'completion-at-point-functions #'cider-complete-at-point t))

(add-hook 'cider-mode-hook #'mu-cider-disable-completion)

I am sure CIDER can, and probably will, embrace Clojure LSP some day, but one cannot blame its developers for these nuisances. On the contrary, we should be grateful for the ease of customization at our disposal, which is one more reason to appreciate CIDER, if you ask me.

Anyway, now I can get rid of mu-cljfmt-format-buffer and rely on M- eglot-format-buffer for my Clojure formatting needs. A happy ending indeed, because removing code from my init.el is always a pleasure.