Skip to content

Commit 7f9e218

Browse files
committed
Merge pull request #259 from elixir-lang/correct-indent-for-receive-after
Indent receive/after matches correct
2 parents ed4fd79 + 1cf6b1a commit 7f9e218

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

elixir-smie.el

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@
358358
(if (elixir-smie-last-line-end-with-block-operator-p)
359359
(smie-rule-parent)
360360
0))
361+
((and (smie-rule-parent-p "after")
362+
(smie-rule-hanging-p))
363+
(smie-rule-parent elixir-smie-indent-basic))
361364
(t
362365
(smie-rule-parent))))
363366
(`(:before . "fn")
@@ -473,8 +476,19 @@
473476
(smie-rule-parent))))
474477
(`(:before . "->")
475478
(cond
476-
((smie-rule-hanging-p)
477-
(smie-rule-parent elixir-smie-indent-basic))
479+
;; Example
480+
;;
481+
;; receive do
482+
;; after
483+
;; 2000 ->
484+
;; IO.puts 'hello'
485+
;; IO.puts 'status 2000 ends' <- Indent second line
486+
;; { :ok } ->
487+
;; ....
488+
((and (smie-rule-parent-p "after")
489+
(not (smie-rule-sibling-p)))
490+
(smie-rule-parent (+ elixir-smie-indent-basic
491+
elixir-smie-indent-basic)))
478492
;; Example
479493
;;
480494
;; case parse do
@@ -486,9 +500,8 @@
486500
elixir-smie-indent-basic)
487501
((and (not (smie-rule-hanging-p))
488502
(smie-rule-parent-p "MATCH-STATEMENT-DELIMITER"))
489-
(smie-rule-parent)
490-
)
491-
))
503+
(smie-rule-parent))
504+
(t (smie-rule-parent elixir-smie-indent-basic))))
492505
(`(:after . "->")
493506
(cond
494507
;; This first condition is kind of complicated so I'll try to make this
@@ -517,8 +530,19 @@
517530
((smie-rule-parent-p "catch" "rescue")
518531
(smie-rule-parent (+ elixir-smie-indent-basic
519532
elixir-smie-indent-basic)))
520-
((smie-rule-parent-p "after" "do" "try")
521-
(smie-rule-parent elixir-smie-indent-basic))
533+
((smie-rule-parent-p "do" "try")
534+
(smie-rule-parent elixir-smie-indent-basic))
535+
;; Example
536+
;;
537+
;; receive do
538+
;; after
539+
;; 2000 ->
540+
;; IO.puts 'hello' <- Indent two spaces
541+
((and (smie-rule-parent-p "after")
542+
(smie-rule-hanging-p)
543+
(not (smie-rule-sibling-p)))
544+
(smie-rule-parent (+ elixir-smie-indent-basic
545+
elixir-smie-indent-basic)))
522546
(t (smie-rule-parent elixir-smie-indent-basic))))))
523547
(`(:before . ";")
524548
(cond

test/elixir-mode-indentation-test.el

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,37 @@ config = %{
13831383
trace: opts[:trace]
13841384
}")
13851385

1386+
(elixir-def-indentation-test receive-after-block
1387+
(:tags '(indentation))
1388+
"
1389+
receive do
1390+
{:hello} -> :ok
1391+
other ->
1392+
other
1393+
after
1394+
2000 ->
1395+
IO.puts 'hello'
1396+
IO.puts 'status 2000 ends'
1397+
{ :ok } ->
1398+
IO.puts 'ok'
1399+
_ -> whatever
1400+
end
1401+
"
1402+
"
1403+
receive do
1404+
{:hello} -> :ok
1405+
other ->
1406+
other
1407+
after
1408+
2000 ->
1409+
IO.puts 'hello'
1410+
IO.puts 'status 2000 ends'
1411+
{ :ok } ->
1412+
IO.puts 'ok'
1413+
_ -> whatever
1414+
end
1415+
")
1416+
13861417
;; We don't want automatic whitespace cleanup here because of the significant
13871418
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
13881419
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my

0 commit comments

Comments
 (0)