Indentation guidelines

234 views
Skip to first unread message

timowest

unread,
Nov 27, 2012, 3:38:24 AM11/27/12
to clojured...@googlegroups.com
Hi.

What indentation guidelines are followed in ccw?

Looking at https://code.google.com/p/counterclockwise/issues/detail?id=439 it seems that the formatting is not in sync with some guidelines available.

Here is a very simple to follow guideline which seems to be in sync with clojure.core sources
https://wiki.helsinki.fi/display/clojure2011/Idiomatic+Clojure

The -> macro for example is indented like this in clojure.core sources https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L3681

Br,
Timo Westkämper

Laurent PETIT

unread,
Dec 13, 2012, 3:26:17 AM12/13/12
to clojured...@googlegroups.com
2012/11/27 timowest <timo.we...@mysema.com>
Who's happier with the -> macro indenting 2 spaces (after the first arg of course)?
Whos's happier with changing the -> macro to indent as regular function?

If not a lot of people answer, or there is no clear winner -> statu quo :-)

Chas Emerick

unread,
Dec 13, 2012, 4:47:32 AM12/13/12
to clojured...@googlegroups.com
Always-2-spaces is the only rule that will always work.  The nuance around 2 spaces vs. prior-arg-alignment is unsustainable in the face local rebindings of core fn/macro names and people's special expectations around how their own macros should be treated.

Trying to do anything else results in things like this:


where indentation is modified based on var naming conventions (here, anything prefixed by 'with-' is indented as per `with-open`, instead of whatever the clojure-mode default is), and things like this:


where one ends up configuring one's personal editor to indent particular forms differently.  Of course, those changes are only local (so won't be applied when someone else touches the code, or even when you touch the code using a different editor or on a different computer), must be constantly maintained in order to stay abreast of changes in the projects that one works on, and are applied globally (so you can't have a macro `foo` in project A indented differently than a function `foo` in project B).

Always-2-spaces is the only rule that will always work. :-)

Cheers,

- Chas

Laurent PETIT

unread,
Dec 13, 2012, 4:50:29 AM12/13/12
to clojured...@googlegroups.com
Hello Chas,

2012/12/13 Chas Emerick <ch...@cemerick.com>
Sure, but you did not clearly answer the question :-)
 

Cheers,

- Chas

--
You received this message because you are subscribed to the Google Groups "counterclockwise-users" group.
To post to this group, send email to clojured...@googlegroups.com.
To unsubscribe from this group, send email to clojuredev-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojuredev-users?hl=en.

Anthony Grimes

unread,
Dec 13, 2012, 5:24:12 AM12/13/12
to clojured...@googlegroups.com
+1 for -> indenting as a regular function and adding a vote to ignore everything Chas just said.

Jozef Wagner

unread,
Dec 13, 2012, 6:15:34 AM12/13/12
to clojured...@googlegroups.com
How about indenting vector, set and map? http://pastebin.com/35WGZhaP

It breaks the always 2-space rule.

Laurent PETIT

unread,
Dec 13, 2012, 6:34:21 AM12/13/12
to clojured...@googlegroups.com
Not answering my question :)

As of your question: vectors, sets and maps are not lists, the 2-space rule applies to non quoted lists IMHO 

2012/12/13 Jozef Wagner <jozef....@gmail.com>

--
You received this message because you are subscribed to the Google Groups "counterclockwise-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/clojuredev-users/-/7fYAQMO605wJ.

timc

unread,
Dec 13, 2012, 6:59:30 AM12/13/12
to clojured...@googlegroups.com
For me the current rules are OK.
There are anomalies (cond, condp, macros), but I can live with those.

Laurent PETIT

unread,
Dec 13, 2012, 7:14:22 AM12/13/12
to clojured...@googlegroups.com
2012/12/13 timc <TimG...@gmail.com>
For me the current rules are OK.
There are anomalies (cond, condp, macros), but I can live with those.

cond fixed.

What's the problem with condp?

macros won't be fixed, too hard to get consistent behaviour.
 
To view this discussion on the web visit https://groups.google.com/d/msg/clojuredev-users/-/cpBlCF8Kpz8J.

Jozef Wagner

unread,
Dec 13, 2012, 7:18:18 AM12/13/12
to clojured...@googlegroups.com

In my emacs, -> is indented like regular fn. But I would prefer it would indent 2 spaces.

JW

timc

unread,
Dec 13, 2012, 7:27:32 AM12/13/12
to clojured...@googlegroups.com
The way it is, it treats the forms following cond and condp simply as normal function arguments (which is indeed what they are :), but it would be nice (simply as a matter of taste), if they were treated pairwise, like this:

(condp = (blah blah)
--:something
----(now the action)
--:somethingelse
----(more action)
--(final action))

where - = \space; similarly for cond.
However, this is probably very difficult, so if I really want to do that I can do it manually (and as I said it's just a matter of taste - not a problem).

[More important to me is the issue of auto-reformat when forms are inserted, deleted or hoisted - it can be really tedious to manually press TAB on every line of a big form. -- but that's not the subject here :]

Chas Emerick

unread,
Dec 13, 2012, 9:12:52 AM12/13/12
to clojured...@googlegroups.com
On Dec 13, 2012, at 7:27 AM, timc wrote:

[More important to me is the issue of auto-reformat when forms are inserted, deleted or hoisted - it can be really tedious to manually press TAB on every line of a big form. -- but that's not the subject here :]

This was the primary motivation behind my prior message.

Everyone in the world (myself included, certainly) has their own idiosyncratic tastes and preferences when it comes to things like indentation.  However, I'd much prefer to ignore tastes and preferences in exchange for a simple rule that can be systematically applied everywhere.

(And yes, my prior 2-space suggestion does not apply to things like vector and map literals.  Alignment just inside the opening bracket/brace is universal, and is already applied automatically, everywhere.)

- Chas

Laurent PETIT

unread,
Dec 13, 2012, 9:56:18 AM12/13/12
to clojured...@googlegroups.com
I just added an option for forcing 2-spaces indentation, will make it into the next beta

2012/12/13 Chas Emerick <ch...@cemerick.com>

--
You received this message because you are subscribed to the Google Groups "counterclockwise-users" group.
Reply all
Reply to author
Forward
0 new messages