hylang / hy-mode

Hy mode for Emacs
GNU General Public License v3.0
191 stars 47 forks source link

Indentation requests and bugs. #48

Closed ekaschalk closed 6 years ago

ekaschalk commented 7 years ago

@gilch @Kodiologist

I've rewritten hy-mode indentation taking from Clojure. We now have:

  1. 2-spaces hy style guide now followed.
  2. Both dicts and lists with strings at start should be indented correctly in all cases.

Let me know if any bugs have popped up, it's passing on all my files.

Also let me know if any remaining requests for indentation, in particular adjusting the specform to indent things like as->, ap-pipe/if/... and so on.

gilch commented 7 years ago

The , special form for tuples should align args like a function call.

Current

(, 1
 2
 3)

Expected

(, 1
   2
   3)
ekaschalk commented 7 years ago

Fixed the tuple alignment. I've been refactoring the indentation, almost all clean now.

6f1ac071b71865ac0f130b0a679aa7120b7af65e

gilch commented 7 years ago

Smartparens doesn't duplicate it anymore, but, the ` is getting paired and indented like a bracket. For example,

(if b
  `x
    `y)

Expected

(if b
  `x
  `y)
ekaschalk commented 7 years ago

Fixed with d5cf1890c938a17dcef37b0d70230ab7e2dcfe03

I've finished rewriting the indentation, should be solid now.

ekaschalk commented 7 years ago

Found an issue occuring only when starting a form with exactly .-:

(.-a d
    e)

Expected:

(.-a d
     e)
gilch commented 7 years ago

Hy's if is variadic, (like in Arc Lisp). When taking more than three arguments, it needs to be indented like Clojure's cond, instead of Clojure's if.

Current

(if 1 2
  3 4
  5 6
  7 8
  9)

Expected

(if 1 2
    3 4
    5 6
    7 8
    9)

This used to work both ways, like a call if 1 2 were on the same line, and like a defn if 1 was by itself, e.g.

(if 1 2
    3)
(if 1
  2
  3)

In other Lisps, it's normal to indent if just like a function call. Emacs is unusual because it dedents the else clasue. And Clojure is unusual because it dedents both then and else clauses.

I personally think it would be fine if if were indented just like a regular call all the time. It doesn't have an implicit-do body. But in either case, the cond-like form should not get the dedent.

gilch commented 7 years ago

The , is just a symbol, but even in [] and {}, it gets indented like a tuple special form--

[, 1
   2 3]
{, 1
   2 3}

Expected

[, 1
 2 3]
{, 1
 2 3}
ekaschalk commented 7 years ago

Tuple indentation fixed with 57078d7a3adbff17dd7ed9fcfe2326d2fe02d1ee If treated as function with eb808be9b00de514a470ad96c5694cef633204e8 Tag macro indentation with c26bc900be071dbe2488c12c787d953c21232ed8

There was no bug with .- symbols.

If you have preference for the final case I know how to implement that.

ekaschalk commented 7 years ago

I believe indentation to be settled now. Going to close this.

gilch commented 7 years ago

Sets seem to throw off indentation

(foo #{}
      1
      2)

expected

(foo #{}
     1
     2)
ekaschalk commented 6 years ago

Fixed. Before tag macros would indent 1 past the hash, they now indent at the hash as seen in the set literals.

ekaschalk commented 6 years ago

Forms opening with another form throw normal indentation off.

((if pred f g) a
 b)

Expected to follow standard indentation rules, instead always indents at the opening. Believe it is because it indents parenthesis like a bracket-like.

Edit: Resolved in 620e968a9f51c91b2704729134bf3a33b30f0d97