'cond' isn't indented properly

Create issue
Issue #75 wontfix
Raynes created an issue

https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L578 Apparently, cond is supposed to be indented with one space, as is shown here. VimClojure would indent that same code with two spaces before each clause. I didn't quite understand why this is a problem, but amalloy had this to say:

{{{ [15:21:59] <amalloy> Raynes: 1 is "correct", though i don't like it [15:22:40] <Raynes> amalloy: Why is it correct? [15:22:55] <amalloy> because cond isn't a defun [15:22:57] <Raynes> I'm asking because VimClojure doesn't indent it like that, and I'm failing to see why it should. [15:23:21] <amalloy> ie, it doesn't take &body, it takes &clauses }}}

Comments (3)

  1. Meikel Brandmeyer repo owner

    I don't know a single form which would be indented by one space (minus vectors, maps, etc.). Here some counter examples from clojure.core itself.

    Anyway, there is no “official” standard whatsoever. VimClojure's indentation follows some simple rules and I'm not persuaded up to now to add some special case for cond. Especially since the example of clojure.core actually contradicts itself. Also inspecting a non-representative sample of projects by credible authors rather supports the 2 spaces approach.

    Please re-open of this does not address your concerns sufficiently.

  2. Raynes reporter

    It looks like lazy-seq would also be in that group, but nothing in particular besides that comes to me right now. https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2423 though it isn't indented consistently either. I agree, core should really be more standardized.

    Also, http://mumble.net/~campbell/scheme/style.txt, specifically:

    If the first subform is a non-special name, then if the second subform is on the same line, align the starting column of all following subforms with that of the second subform.  If the second subform is on the following line, align its starting column with that of the first subform, and do the same for all remaining subforms.

    The only reason I care about it is that Emacs does it differently. My co-workers use Emacs and I have to manually indent these things in order to remain consistent with them. This isn't a really big problem, but will probably get tedious at some point. Not that I'm saying that Emacs should be the golden standard you should adhere to, mostly just expressing frustration.

    That said, I understand why you aren't motivated to fix this. Just keep it in mind.

  3. Meikel Brandmeyer repo owner

    I see the idea of having “plain” lists indented with only one space. However even emacs isn't consistent. For example try is also indented with only one space. But catch with two. Why? I prefer a more simple “two for all” rule since lists in Clojure are always function calls.

    I started using the lispindent from vim which uses two spaces for cond, also. YMMV.

    As for your concrete problem: You may copy over GetClojureIndent from indent/clojure.vim to after/indent/clojure.vim.

    Change the line 209 to read:

            if paren[0] < line(".")
                    return paren[1]

    Then replace indentexpr with your modified function. after/indent/clojure.vim should then look like this:

    function! MySpecialGetClojureIndent()
    setlocal indentexpr=MySpecialGetClojureIndent()

    Then you also have to “fix” other emacs related peculiarities like try in after/ftplugin/clojure.vim:

    setlocal lispwords-=try

    Hope the helps.

  4. Log in to comment