Skip to content

Metadata-based indentation #309

Closed
Closed

Description

@TuiTh7Ji

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

  1. bbatsov commented on Aug 3, 2015

    @bbatsov
    Member

    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 for body elements, etc). SLIME has similar functionality, so I guess we can borrow from it

    This is definitely something I'm not planning to work on myself, so someone else should get the ball rolling there.

  2. Malabarba commented on Oct 1, 2015

    @Malabarba
    Member

    This is now possible in the CIDER snapshot by setting the :indent metadata 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.

  3. bbatsov commented on Oct 2, 2015

    @bbatsov
    Member

    I'll close this issue, as there are now other tickets tracking the progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions