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

feat: make indentation of special arguments customisable #582

Conversation

hugoduncan
Copy link
Member

Allow control of the indentation of special arguments through a defcustom.

  • introduces clojure-special-arg-indent-factor, which is used as a factor of
    lisp-body-ident to indent special arguments. Defaults to 2, the currently hard
    coded value for this.

  • The commits are consistent with our [contribution guidelines][1].

  • You've added tests (if possible) to cover your change(s). Bugfix, indentation, and font-lock tests are extremely important!

  • You've run M-x checkdoc and fixed any warnings in the code you've written.

  • You've updated the changelog (if adding/changing user-visible functionality).

  • You've updated the readme (if adding/changing user-visible functionality).

Allow control of the indentation of special arguments through a defcustom.

- introduces clojure-special-arg-indent-factor, which is used as a factor of
lisp-body-ident to indent special arguments.  Defaults to 2, the currently hard
coded value for this.
@bbatsov
Copy link
Member

bbatsov commented Feb 20, 2021

What problem is this aiming to solve? I don't recall ever seeing someone use a different indent level for macro forms.

@hugoduncan
Copy link
Member Author

At work we recently started using zprint to format code. zprint doesn't use a different indent for special arguments. This PR would allow achieving identical formatting with clojure-mode.

@bbatsov
Copy link
Member

bbatsov commented Feb 21, 2021

Looking at the examples it seems to the that such forms use 2-space indent there as well https://github.com/kkinnear/zprint/blob/master/doc/options/community.md Can you share some examples so that I can understand better the difference?

I guess you should add some examples to the README as well, if we want others to learn about this option and its potential usefulness.

@hugoduncan
Copy link
Member Author

I don't see a relevant example in the zprint link above. The formatting in question is the handling of special arguments when they are on separate lines. I've added an example with defrecord to the README.

@bbatsov
Copy link
Member

bbatsov commented Feb 26, 2021

Ah, now I see what you mean. I always place the special args on the first line, so it took me a while to process why something like this needed to be customized. I'll ruminate a bit more on this and I'll likely merge it over the weekend.

@hugoduncan
Copy link
Member Author

Let me know if there is anything that I can do to facilitate this.

@@ -216,6 +216,24 @@ For instructions on how to write these specifications, see
[this document](https://docs.cider.mx/cider/indent_spec.html).
The only difference is that you're allowed to use lists instead of vectors.

The indentation of special arguments is controlled by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this explanation to be a bit confusing, because I don't think we mention the meaning of special arguments anywhere in the readme and at least for me - the special argument is this case (and most of the time) is the body. I understand the examples, but I'm wondering if others won't be confused by them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forget about this - https://docs.cider.mx/cider/indent_spec.html#special-arguments I no longer remember some of the things I wrote myself. :D

@bbatsov bbatsov merged commit 3d8296e into clojure-emacs:master Mar 1, 2021
bbatsov added a commit that referenced this pull request Mar 1, 2021
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

Successfully merging this pull request may close these issues.

2 participants