hylang / hy-mode

Hy mode for Emacs
GNU General Public License v3.0
189 stars 48 forks source link

Make indentation rules match the Hy style guide. #39

Closed gilch closed 6 years ago

gilch commented 8 years ago

The Hy Style Guide states that

Indentation shall be 2 spaces (no hard tabs), except when matching the indentation of the previous line.

The MELPA version of Hy-mode only gives me one space when I hit return or when I reformat a form. I shouldn't have to fight the editor to maintain the standard style.

;; current behavior
(do
 (print "Hello, World!"))
;; expected behavior
(do
  (print "Hello, World!"))
m8uz commented 7 years ago

Another problem along the same lines:

Hy-mode is intelligent enough to only indent one level (i.e. 2 spaces) after (if ..., but treats (if-not x ... as a function call and aligns the second row to the first:

;; current behavior
(if (x)
  (y))
(if-not (x)
        (y))

;; expected behavior
(if (x)
  (y))
(if-not (x)
  (y))
ekaschalk commented 6 years ago

Do you have any thoughts on which forms should be indented special?

Right now, any form matching: \\(?:\\S +/\\)?\\(def\\|with-\\|with_\\|fn\\|lambda\\) or exactly match one of:

(("for" . 1)
    ("for*" . 1)
    ("while" . 1)
    ("except" . 1)
    ("catch" . 1)
    ("let" . 1)
    ("if" . 1)
    ("when" . 1)
    ("unless" . 1))

will have the 'if-like' indentation.

Eg.

(lambda x
  y)
(with-my-own-context x
  y)

So adding if-not and such variations are simple, what else though?

For example, I think as-> is a good candidate for special indentation, possibly also ap-pipe.

I'm addressing the 2-space indentation as well.