Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation inference for defmacros #777

Closed
vemv opened this issue Jul 15, 2023 · 3 comments
Closed

Indentation inference for defmacros #777

vemv opened this issue Jul 15, 2023 · 3 comments

Comments

@vemv
Copy link
Member

vemv commented Jul 15, 2023

(IDK if this had been talked about before)

Given an arbitrary macro that lacks :style/indent metadata, e.g. (defmacro fact [& forms], I'd find it most practical that CIDER inferred a sensible indent value for it.

A sensible rule of thumb is:

indent = <number of macro args before &>

For instance, [a b & c] has two arguments before &, so the inferred indent should be 2.

There occasionally exist macros without &, e.g.:

(defmacro foo [opts body]

For those, we can devise a similar rule of thumb:

indent = <number of macro args before an argument named body>

(or forms, tail, similar words)

So that foo would have an indent of 1.

I understand that this is not quite 'pure' in approach. But my experience over the years is that very few people, even among CIDER users, will remember to add the metadata manually.

Ultimately, users can of course always add metadata, which would override any inference.

WDYT?

Cheers - V

@vemv vemv changed the title Intentation inference for defmacros Indentation inference for defmacros Jul 15, 2023
@vemv
Copy link
Member Author

vemv commented Jul 17, 2023

Another rule of thumb, is that if something is called approximately defrecord, then format it like defrecord. Same for defprotocol, etc.

(For these ones, it's safer to do this only if the custom macro's arglists are equal or a subset to those of their clojure.core counterpart)

@bbatsov
Copy link
Member

bbatsov commented Jul 17, 2023

Yeah, that'd be fine. That's similar to how SLIME used to work out indentation when it wasn't specified - by relying on the the names of some params (I think body and forms). In general I'm all for adding some sensible inference to simplify the lives of users.

@bbatsov
Copy link
Member

bbatsov commented Jul 17, 2023

You can check this out for some inspiration https://github.com/slime/slime/blob/master/contrib/slime-cl-indent.el

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants