Description
Here is a well-known problem: often we create a function or a macro which is
meant to be some kind of container for other elements, or some kind of control
structure, so we want the nested calls to be indented defun-style. One obvious
example is functions in Om's dom namespace:
;; how it is indented by default
(dom/div #js {:id "foo"}
(nested-stuff))
;; how it should be indented
(dom/div #js {:id "foo"}
(nested-stuff))
Currently, this issue is dealt with in a number of ways, one of which is to use
heuristics to determine the correct indentation (if first symbol starts with
def, indent defun-style), and the other is to force users to maintain a giant
nasty list of define-clojure-indent calls. It is quite obvious that these
solutions are nothing but hacks that do not really work.
Luckily, we already have a place where various source-related data (like
e.g. line number of a definition) are put: vars' metadata. So my proposal is to
make indentation of a form dependent on (explicitly specified by its author)
metadata of the var to which first symbol of the form resolves.
I understand that this issue is much broader in scope than clojure-mode itself
(other IDEs have to support this too in order for this to be useful), and even
within context of Emacs it maybe belongs to CIDER rather than clojure-mode
(since we need an nrepl connection to read metadata), so please feel free to
redirect me to the appropriate place to start the discussion.
Activity
bbatsov commentedon Aug 3, 2015
I agree with pretty much everything you said. This is definitely outside the scope of
clojure-mode, though, as it requires a running process to obtain this information. I'm not sure how many library authors would add such metadata, so other heuristics would be useful as well (e.g. inspecting macro signatures forbodyelements, etc). SLIME has similar functionality, so I guess we can borrow from itThis is definitely something I'm not planning to work on myself, so someone else should get the ball rolling there.
Malabarba commentedon Oct 1, 2015
This is now possible in the CIDER snapshot by setting the
:indentmetadata of a var. The feature is not finalized yet (it needs a couple of tweaks and needs to be documented), but I'll open separate issues for that.bbatsov commentedon Oct 2, 2015
I'll close this issue, as there are now other tickets tracking the progress.