Skip to content

Correctly indent one-line anon fns AND block fns. Fixes #59 #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions elixir-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ Return non-nil if any line breaks were skipped."
(statement)
(statement ";" statements))
(statement
(non-block-expr "fn" match-statement "end")
(non-block-expr "do" statements "end")
("if" non-block-expr "do" statements "else" statements "end")
("if" non-block-expr "do" statements "end")
("if" non-block-expr "COMMA" "do:" statement)
Expand All @@ -258,10 +260,7 @@ Return non-nil if any line breaks were skipped."
("try" "do" statements "catch" match-statements "end")
("try" "do" statements "end")
("case" non-block-expr "do" match-statements "end")
("def" non-block-expr "do" statements "end")
(non-block-expr "do" statements "end")
(expr)
)
("def" non-block-expr "do" statements "end"))
(non-block-expr
(non-block-expr "OP" non-block-expr)
(non-block-expr "COMMA" non-block-expr)
Expand Down Expand Up @@ -309,9 +308,15 @@ Return non-nil if any line breaks were skipped."
;; for some reason SMIE doesn't look this far when there's a
;; comment terminating the previous line. Ugh.
nil)
;; If the parent token of `->' is `fn', then we want to align to the
;; parent, and offset by `elixir-smie-indent-basic'. Otherwise, indent
;; normally. This helps us work with/indent anonymous function blocks
;; correctly.
(`(:after . "->")
(when (smie-rule-hanging-p)
elixir-smie-indent-basic))
(if (smie-rule-parent-p "fn")
(smie-rule-parent elixir-smie-indent-basic)
elixir-smie-indent-basic)))
(`(,_ . ,(or `"COMMA")) (smie-rule-separator kind))
(`(:after . "=") elixir-smie-indent-basic)
(`(:after . "end") 0)
Expand Down
2 changes: 1 addition & 1 deletion test/elixir-mode-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ to_process = [27, 33, 35, 11, 36, 29, 18, 37, 21, 31, 19, 10, 14, 30,
")

(elixir-def-indentation-test indent-nested-fn
(:expected-result :failed) ; #59
()
"defmodule FooModule do
def foo do
x = fn(a, b) -> a + b end
Expand Down