-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
Wrong indentation in multi-arity forms #239
Comments
As a reference, here's how it usually looks. (defn a-function
[x y]
(+ x y)) |
Yep, that's definitely a bug. |
What is the desired behaviour here? Both vim's Clojure indentation and LightTable's indent thus: (defn foo
([x] (bar x))
([x y]
(if (predicate? x)
(bar x)
(baz x)))) (which looks weird to me, but I think I'm used to the way clojure-mode has been indenting these for a while now). I can't find any advice in any clojure style guides (including the referenced Scheme guide) about multiple-arity clojure indentation. |
What you just posted is the desired behavior. clojure-mode now indents the first form, of multi-arity function bodies with two spaces more than it should. |
I see this has the "help-needed" label. What would be useful? |
It means that I don't have the time to deal with this soon. Basically, the problem is caused by us copying (inheriting) too much things from |
Should probably rename that label, @bbatsov might want some help, but he never needs it :p |
@expez LOL |
Hi all, Is it still a bug? already, some codes has used 3 space indent. (e.g. core.async/src/main/clojure/core/async.clj:78) ;; clojure-mode.el:718:clojure-indent-function:
(if (and (eq (char-after (point)) ?\[)
(eq (char-after (elt state 1)) ?\())
(+ (current-column) 2) ;; this is probably inside a defn
(current-column)) and commits: |
@vmfhrmfoaj yes, this is still a bug. That code, in core.async, is probably written using emacs, and thus it's our fault it looks like that. |
Well that wound up being much simpler than expected. Thanks so much for the quick response! |
Phew, I was just writing a bug report that the indentation of multi-arity functions isn't as nice anymore as it used to be... |
@tsdh Can't please everyone I guess. I have no idea why the indentation was implemented as it was originally. We can make this configurable, but this is not something I'm going to pursue myself. |
@bbatsov Please don't make it customizable. It's good for a language and collaboration if there's one canonical style of formatting and not everybody has his own style. I'll just adapt to the new style. |
👍 |
I'd also say I like the previous one better. Also, most of the Clojure codebase is indented the old way. Can we bring this up again and discuss a little more? Arguments pro: in the old way the implementations of different arities are easier distinguished: (defn foo
([x]
(bar x))
([x y]
(if (predicate? x)
(bar x)
(baz x)))) vs (defn foo
([x]
(bar x))
([x y]
(if (predicate? x)
(bar x)
(baz x)))) |
Perhaps. But the argument that nobody else does the indentation like clojure-mode did is a very strong cons of the old style. I might write a blog post about this to get some more feedback. |
@alexander-yakushev While I also liked the old way better, I don't buy your argument. I just checked clojure/core.clj, and there you'll find about half of the time the new indentation style, and the other half the old one. Aside from that, Clojure itself is a poor resource when it comes to deciding what's a good formatting style. It's full of trailing whitespace and far from consistent. I guess that's caused by people working with different tools on it: Emacs, CCW, LightTable, whatnot. To me the most important aspect should be how the other editors format multi-arity fns. I just tested LightTable, and that indents like clojure-mode does now, too. Someone should check CCW and others with reasonable market share. @wjlroe already told us that Vim also indents that way. So to summarize, all Clojure editor devs should try to use the same indentation/formatting by default. It's just frustrating if you get dozen-line patches just because you edited one line in a function that someone with some other editor wrote and some auto-formatting jumped in. (Yes, I know the relevant diff options but I prefer "just works"). |
I totally agree that it is better to have a single formatting style. I just don't consider Vim and LightTable enough authority to state that |
@bbatsov I'm 99% sure those decisions in other editors were accidental, not considered. Say, in clojure-mode and in Vim people arrived at two different styles. Then, LightTable developers randomly followed Vim style rather than in clojure-mode (but it could be vice versa). I think this doesn't qualify as an argument until there is a proof that this behaviour was intended and not just mimicked. I say we can bring those other editor implementors into the discussion and decide upon the correct way once and for all. |
Pretty sure our indentation was the accidental one. We were inheriting behavior from lisp-mode with no special handling of multi-arity forms. Am I right, @bbatsov? |
There was a commit that introduced it way back in 2008 (7c3a604), but I have no idea what was the reasoning behind this. I think this was just a preference of the original Anyways, I'm fine with starting a broader discussion on the topic. |
I submit that we move any discussion of the platonic ideal of Clojure code relating to multiple arities to the style guide. I've opened a pull request accordingly. If and when that issue gets resolved then all our tools can refer to that. |
Things are currently auto-indented like this:
and
The text was updated successfully, but these errors were encountered: