jank-lang / jank

The native Clojure dialect hosted on LLVM
https://jank-lang.org
Mozilla Public License 2.0
1.68k stars 50 forks source link

Better vim indentation #4

Closed jeaye closed 6 years ago

jeaye commented 8 years ago

Most lisp-like languages have one indentation scheme (no puns), which is not up for debate. jank is the same way, and it follows clojure's indentation almost to the letter.

Vim's clojure files are here https://github.com/guns/vim-clojure-static but the indentation logic is ridiculous, so I haven't bothered yet.

In short, every first new line of a form indents 2 spaces and subsequent new lines match the previous. An exception is if one argument is passed, then the next new lines match that argument. Certain "special forms" (function, lambda, if, etc) always indent 2 spaces.

So, examples:

(print!
  1
  2)

(; Subsequent lines match the first argument. ;)
(print!
  1 2
  3 4)

(; If one is supplied on the first line, the rest match up. ;)
(print! 1
        2)

(; Lambdas have the signature on the first line, but the body doesn't indent to match it. ;)
(lambda () ()
  (print! "meow"))

(; If expressions take a condition, but the then/else bodies don't match up to it. ;)
(if (empty? foo)
  (print! "empty")
  (print! "not empty"))
jeaye commented 6 years ago

The new Clojure syntax rules this out.