bbatsov / clojure-style-guide

A community coding style guide for the Clojure programming language
https://guide.clojure.style
3.99k stars 279 forks source link

Indenting cond #75

Closed jeremyheiler closed 9 years ago

jeremyheiler commented 10 years ago

The indentation for cond in the guide uses two spaces, but clojure-mode enforces one space. Given that clojure-mode is actively used, should we update the guide?

bbatsov commented 10 years ago

That's likely a bug in clojure-mode I haven't noticed. I'll look into it.

aviflax commented 10 years ago

OTOH Clojure itself uses 1 space so perhaps we should standardize on 1 space.

michaelklishin commented 10 years ago

@aviflax Clojure itself is known to have the most nonsensical indentation and code style in the industry, so I'd not be so keen to see the entire community do the same.

michaelklishin commented 10 years ago

Also, clojure/core repeatedly tells people to not treat clojure.core as a golden standard for anything, e.g. code readability. It takes some gnarly parts to bootstrap a homoiconic language.

bbatsov commented 10 years ago

@aviflax I think that @michaelklishin is right - having something in Clojure's own source code doesn't make it automatically good style. Personally I can't think of a single idea to indent cond differently (and AFAIK no other Lisp does so).

j0ni commented 10 years ago

I see this happening for many functions. At first I thought something else in my emacs config might be causing problems, but now I've found this bug I'm thinking perhaps not.

For example, using Stuart Sierra's component library:

(component/using
 (app/app-component app-options)
 [:some-stuff :some-other-stuff])

also I'm seeing the same thing for clojure.core functions:

(repeatedly
 #(Math/random))

I thought that maybe clojure-defun-style-default-indent might be good enough, but that also impacts clojure.core functions, causing functions like map (or I guess any function I pass an arg on the same line, then a second arg on the next line) to be indented wrongly (IMO - correct me if it is intended behaviour).

It's been a while since the last comment on this - is it still regarded as a bug? If so is there an issue open on clojure-emacs/clojure-mode?

Gonzih commented 10 years ago

Feels like bug in clojure-mode to me.

bbatsov commented 10 years ago

Yeah, I'd say it's a bug. I'm planning to work on improving font-locking and indentation in clojure-mode. Hopefully I'll get to fixing this as well.

bbatsov commented 9 years ago

In light of the discussion in https://github.com/clojure-emacs/clojure-mode/issues/235 should we update clojure-mode or the guide? I'm on the fence about this given all the CL baggage, but using 2-space indent seems more sensible.

eigenhombre commented 9 years ago

+1 for two-space indent and updating clojure-mode.

ghost commented 9 years ago

Another vote for 2-space indent and updating clojure-mode.

emallson commented 9 years ago

Here's another vote for 2-space indentation. IMHO the goal of increasing indentation levels is to visually demarcate the segment. I don't believe that 1-space indentation does so effectively.

bbatsov commented 9 years ago

OK, I've updated clojure-mode.

nashbridges commented 8 years ago

Now https://github.com/bbatsov/clojure-style-guide#one-space-indent rule is quite confusing for me as a clojure novice.

What is the difference between or/and and cond? clojure-emacs discussion ended up in

Lists get a single space indent unless it's a known macro form, in which case it gets two?

Isn't or well known?

bitti commented 3 years ago

@nashbridges it's not about whether or not a macro is well known, but about if the macros is taking a body form (which is indented by 2 spaces, and not aligned with preceding arguments, e.g. bindings). Many of these macros are well known, but don't have to be. E.g. you can write your own macros which take body forms which should be indented accordingly. The macros or and and don't take body forms and are therefore formatted like normal functions.

cond is controversial since it objectively doesn't take a body form but a list of clauses. But since this list can get quite long it kind of feels like a body form.