Skip to content

Commit f68b762

Browse files
committed
Merge pull request #260 from elixir-lang/correct-indent-for-oneline
Correct indentation after "for" comprehension
2 parents 7f9e218 + 6bd8ccb commit f68b762

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

elixir-smie.el

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@
121121
("try" "do" statements "catch" match-statements "end")
122122
("try" "do" statements "rescue" match-statements "end")
123123
("try" "do" statements "end")
124-
("case" non-block-expr "do" match-statements "end"))
124+
("case" non-block-expr "do" match-statements "end")
125+
("for" non-block-expr "COMMA" "do:" non-block-expr))
125126
(non-block-expr (non-block-expr "OP" non-block-expr)
126-
(non-block-expr "COMMA" non-block-expr)
127127
("(" non-block-expr ")")
128128
("{" non-block-expr "}")
129129
("[" non-block-expr "]")
@@ -365,13 +365,25 @@
365365
(smie-rule-parent))))
366366
(`(:before . "fn")
367367
(smie-rule-parent))
368+
(`(:before . "for")
369+
(smie-rule-parent))
368370
(`(:before . "do:")
369371
(cond
370372
((smie-rule-parent-p "def" "if" "defp" "defmacro" "defmacrop")
371373
(smie-rule-parent))
372374
((and (smie-rule-parent-p ";")
373375
(not (smie-rule-hanging-p)))
374-
(smie-rule-parent elixir-smie-indent-basic))))
376+
(smie-rule-parent elixir-smie-indent-basic))
377+
;; Example
378+
;;
379+
;; hi = for i <- list, do: i
380+
;; # weird spacing now <- Indent
381+
;;
382+
;; for i <- list, do: i
383+
;; IO.puts 'WORKED' <- Indent
384+
((and (smie-rule-parent-p "for")
385+
(not (smie-rule-hanging-p)))
386+
(smie-rule-parent))))
375387
(`(:before . "do")
376388
(cond
377389
((and (smie-rule-parent-p "case")

test/elixir-mode-indentation-test.el

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

1386+
13861387
(elixir-def-indentation-test receive-after-block
13871388
(:tags '(indentation))
13881389
"
@@ -1414,6 +1415,37 @@ after
14141415
end
14151416
")
14161417

1418+
(elixir-def-indentation-test indent-after-for-online-definition
1419+
(:tags '(indentation))
1420+
"
1421+
defmodule Hello do
1422+
def hi do
1423+
hi = for i <- list, do: i
1424+
# weird spacing now
1425+
1426+
for i <- list, do: i
1427+
IO.puts 'WORKED'
1428+
end
1429+
end
1430+
1431+
hi = for i <- list, do: i
1432+
# weird spacing now
1433+
"
1434+
"
1435+
defmodule Hello do
1436+
def hi do
1437+
hi = for i <- list, do: i
1438+
# weird spacing now
1439+
1440+
for i <- list, do: i
1441+
IO.puts 'WORKED'
1442+
end
1443+
end
1444+
1445+
hi = for i <- list, do: i
1446+
# weird spacing now
1447+
")
1448+
14171449
;; We don't want automatic whitespace cleanup here because of the significant
14181450
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
14191451
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my

0 commit comments

Comments
 (0)