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

Custom indentation for some functions #80

Closed
felipethome opened this issue Oct 9, 2018 · 16 comments
Closed

Custom indentation for some functions #80

felipethome opened this issue Oct 9, 2018 · 16 comments

Comments

@felipethome
Copy link

With Cursive it is possible to configure the indentation for each function individually. Is it possible to do the same with Calva?

@PEZ
Copy link
Collaborator

PEZ commented Oct 10, 2018

Unfortunately not. Can you share how it is done in Cursive?

The way I would like to support this is to have clj-fmt support the metadata hints for indentation, like this issue is asking about: weavejester/cljfmt#49 (Calva uses clj-fmt as its formatting engine).

@felipethome
Copy link
Author

felipethome commented Oct 10, 2018

That is a pity. This is a must have feature for me since I need to respect the indentation of the code in the company I work for.

Maybe Cursive has it own implementation to format code:
cursive

@PEZ
Copy link
Collaborator

PEZ commented Oct 10, 2018 via email

@felipethome
Copy link
Author

felipethome commented Oct 10, 2018

I think I can add the support with a reasonable amount of effort. I'll look
into it, I think it sounds important.

It would be awesome, thanks for looking at it. I know it is hard to find the time.

Cursive offers numbers that you can choose to configure the indentation. They start from 0 which would indent the next line from the symbol you are defining, 1 for the parameters, and so on. It also has the indent option that would just add the amount of spaces you defined. For example:

screen shot 2018-10-10 at 14 24 20

@PEZ
Copy link
Collaborator

PEZ commented Oct 12, 2018

Is that project you have a Leiningen project, @felipethome ?

I want to know so that I can prioritize the path to fixing this.

@felipethome
Copy link
Author

Yes! I think right now Cursive only supports Leiningen, though they are starting to have support for deps.edn in the EAP version

@mseddon
Copy link
Contributor

mseddon commented Dec 21, 2018

Would configuring cljfmt in your lein project work for you? I am currently working on a rework of the ontype formatting for calva (and various other calva-fmt issues), and once the core is in place (hopefully in a week or so due to christmas) I will be adding support for customisation from the project.clj.

@felipethome
Copy link
Author

I believe it would. The nice thing about adding to project.clj is that other people would automatically use the same indentation configuration.

@ericdallo
Copy link
Contributor

+1 for this feature, the possibility to configure custom macros with it owns identation configurations.
c/c @PEZ

@PEZ
Copy link
Collaborator

PEZ commented Jun 9, 2019

Yes, this has been allowed to wait for quite long. A reason that is so is that I had hoped we should have consolidated Calva on the new formatter, but we still have them both.

If anyone feel the urge to fix this, I will be happy to provide some context and pointers into the code. It shouldn't be too hard. Both formatters actually base their indentation on a clj-fmt compatible config map. It is mostly a matter of finding a good way for the user to provide the custom config.

@guillaume
Copy link

yes this is usually spelled in our projects in a cljfmt section like so:

...
:cljfmt {:indents {timed [[:inner 0]]
                     mocking [[:inner 0]]
                     stubbing [[:inner 0]]
                     report [[:inner 0]]}}
...

@alidcast
Copy link

alidcast commented Oct 27, 2019

@PEZ could there at least be two modes for indentation, one that follows regular lisp indentation others might be used to, and one with less aggressive nesting? lots of devs using vscode come from JS land, and so that sort of formatting might be more familiar/appealing

I particularly like the formatting @tonsky described here: https://www.youtube.com/watch?v=l1b7Da2DnPo (relevant part starts at 42:18)

@PEZ
Copy link
Collaborator

PEZ commented Oct 27, 2019

I am a big fan of that proposal actually. I tried to implement it immediately when he published the blog post, even. However, I ran across a bug in cljfmt. The bug is fixed since a long while though, so it can be tried again.

Without making any new promises about this... it really should be fixed. I will have a new look.

@glenjamin
Copy link

I've just caught up on the thread, and I was a little unclear on the latest position.

Is there a way to pass custom function names or rules to cljfmt as used by Calva?

@PEZ
Copy link
Collaborator

PEZ commented Feb 4, 2020

There soon will be. Please help test #546

@PEZ
Copy link
Collaborator

PEZ commented Mar 11, 2020

This is now finally released. Please see: https://calva.readthedocs.io/en/latest/formatting.html

Sorry for the insane delay. And thanks to @nbardiuk for making such a well-thought-through implementation!

@PEZ PEZ closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants