cider
cider copied to clipboard
Indentation according to custom spec (e.g. `:style/indent` metadata) broken in latest version?
This has started happening after upgrading to the latest version of CIDER.
Before connecting CIDER,M-q indents forms as expected according to indentation specs (put-clojure-indent) in my .dir-locals.el or elsewhere. After starting CIDER, anything with a custom indentation spec in either Emacs Lisp (e.g. withput-clojure-indent) or with :style/indent metadata stops indenting correctly. Specifically, things that should be indented two spaces now get indented four spaces.
I am able to reproduce this in a completely blank project with just a single namespace and a dummy empty ({}) deps.edn file.
Expected behavior
(defmacro my-macro {:style/indent 0} [& body]
`(do ~@body))
(defn x []
(my-macro
:wow)) ; should look like this after doing M-q here
Actual behavior
(defmacro my-macro {:style/indent 0} [& body]
`(do ~@body))
(defn x []
(my-macro
:wow)) ; looks like this after M-q here
Steps to reproduce the problem
This is extremely important! Providing us with a reliable way to reproduce a problem will expedite its solution.
Environment & Version information
CIDER version information
;; CIDER 1.3.0-snapshot (package: 20220222.1710), nREPL 0.9.0
;; Clojure 1.10.3, Java 17.0.1
Emacs version
29.0.50 (built from source via homebrew)
Operating system
macOS Monterey
put-clojure-indent is part of clojure-mode, so it's possible that's some regression there. What CIDER does is that it generates indentation rules from clojure-mode dynamically from the :style/indent metadata. I'll try to reproduce this issue later in the week.
Any progress here? I noticed if I just specify the indentation via the define-clojure-indent elisp macro and remove the indent spec it's indenting correctly. So for me it seems clojure-mode works fine, but somehow the way cider inject indent spec rules into clojure-mode is broken.
I'd suggest to run this code by hand in an elisp repl: https://github.com/clojure-emacs/cider/blob/e86f2f74f65eaa3aa2dd088ad2e0b1426a04c3e1/cider-mode.el#L580-L586
Interesting, that function is returning "Missing format argument" for me. So it seems to be related to https://github.com/clojure-emacs/cider/issues/3156, i.e. something changed with with-demoted-errors in certain emacs versions? It must have something to do in how this macro works, if I put in a literal string with one %s parameter in there instead of format it works. The suggestion with quote and unquote in https://github.com/clojure-emacs/cider/issues/3156#issuecomment-1058991862 doesn't work for me though.
Seems the this macro got fixed in newer emacs versions: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54225. So we do nothing in cider and everybody just has to update? (Or monkey patch or something.)
So we do nothing in cider and everybody just has to update?
Indeed. And anyway I've been working on :style/indent improvements:
- infer them when possible, in absence of
:style/indentmetadata - make them available in cljs
Which is to say, I'd certainly notice if we had a bug.