Skip to content
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

Indent receive/after matches correct #259

Merged
merged 1 commit into from
Sep 16, 2015
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
38 changes: 31 additions & 7 deletions elixir-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@
(if (elixir-smie-last-line-end-with-block-operator-p)
(smie-rule-parent)
0))
((and (smie-rule-parent-p "after")
(smie-rule-hanging-p))
(smie-rule-parent elixir-smie-indent-basic))
(t
(smie-rule-parent))))
(`(:before . "fn")
Expand Down Expand Up @@ -473,8 +476,19 @@
(smie-rule-parent))))
(`(:before . "->")
(cond
((smie-rule-hanging-p)
(smie-rule-parent elixir-smie-indent-basic))
;; Example
;;
;; receive do
;; after
;; 2000 ->
;; IO.puts 'hello'
;; IO.puts 'status 2000 ends' <- Indent second line
;; { :ok } ->
;; ....
((and (smie-rule-parent-p "after")
(not (smie-rule-sibling-p)))
(smie-rule-parent (+ elixir-smie-indent-basic
elixir-smie-indent-basic)))
;; Example
;;
;; case parse do
Expand All @@ -486,9 +500,8 @@
elixir-smie-indent-basic)
((and (not (smie-rule-hanging-p))
(smie-rule-parent-p "MATCH-STATEMENT-DELIMITER"))
(smie-rule-parent)
)
))
(smie-rule-parent))
(t (smie-rule-parent elixir-smie-indent-basic))))
(`(:after . "->")
(cond
;; This first condition is kind of complicated so I'll try to make this
Expand Down Expand Up @@ -517,8 +530,19 @@
((smie-rule-parent-p "catch" "rescue")
(smie-rule-parent (+ elixir-smie-indent-basic
elixir-smie-indent-basic)))
((smie-rule-parent-p "after" "do" "try")
(smie-rule-parent elixir-smie-indent-basic))
((smie-rule-parent-p "do" "try")
(smie-rule-parent elixir-smie-indent-basic))
;; Example
;;
;; receive do
;; after
;; 2000 ->
;; IO.puts 'hello' <- Indent two spaces
((and (smie-rule-parent-p "after")
(smie-rule-hanging-p)
(not (smie-rule-sibling-p)))
(smie-rule-parent (+ elixir-smie-indent-basic
elixir-smie-indent-basic)))
(t (smie-rule-parent elixir-smie-indent-basic))))))
(`(:before . ";")
(cond
Expand Down
31 changes: 31 additions & 0 deletions test/elixir-mode-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,37 @@ config = %{
trace: opts[:trace]
}")

(elixir-def-indentation-test receive-after-block
(:tags '(indentation))
"
receive do
{:hello} -> :ok
other ->
other
after
2000 ->
IO.puts 'hello'
IO.puts 'status 2000 ends'
{ :ok } ->
IO.puts 'ok'
_ -> whatever
end
"
"
receive do
{:hello} -> :ok
other ->
other
after
2000 ->
IO.puts 'hello'
IO.puts 'status 2000 ends'
{ :ok } ->
IO.puts 'ok'
_ -> whatever
end
")

;; We don't want automatic whitespace cleanup here because of the significant
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my
Expand Down