Skip to content

Commit b039283

Browse files
committed
correct indentation after one line definition with if keyword fixes #212
1 parent 1e63148 commit b039283

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

elixir-smie.el

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@
330330
((smie-rule-hanging-p)
331331
(smie-rule-parent elixir-smie-indent-basic))
332332
(t elixir-smie-indent-basic)))
333+
(`(:before . "if")
334+
(cond
335+
((smie-rule-parent-p ";")
336+
(smie-rule-parent))))
333337
(`(:before . "->")
334338
(cond
335339
((smie-rule-hanging-p)
@@ -364,9 +368,13 @@
364368
(t (smie-rule-parent elixir-smie-indent-basic))))))
365369
(`(:before . ";")
366370
(cond
371+
((and (smie-rule-parent-p "if")
372+
(smie-rule-hanging-p))
373+
(smie-rule-parent))
367374
((smie-rule-parent-p "after" "catch" "def" "defmodule" "defp" "do" "else"
368375
"fn" "if" "rescue" "try" "unless")
369-
(smie-rule-parent elixir-smie-indent-basic))))
376+
(smie-rule-parent elixir-smie-indent-basic))
377+
))
370378
(`(:after . ";")
371379
(cond
372380
((smie-rule-parent-p "def")

test/elixir-mode-indentation-test.el

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,34 @@ defmodule Greeter do
873873
end
874874
end")
875875

876+
(elixir-def-indentation-test indent-after-def-do-online/2
877+
(:tags '(indentation))
878+
879+
"defmodule ControlFlow do
880+
defmacro my_if(expr, do: if_block), do: if(expr, do: if_block, else: nil)
881+
defmacro my_if(expr, do: if_block, else: else_block) do
882+
quote do
883+
case unquote(expr) do
884+
result when result in [false, nil] -> unquote(else_block)
885+
_ -> unquote(if_block)
886+
end
887+
end
888+
end
889+
end"
890+
891+
"defmodule ControlFlow do
892+
defmacro my_if(expr, do: if_block), do: if(expr, do: if_block, else: nil)
893+
defmacro my_if(expr, do: if_block, else: else_block) do
894+
quote do
895+
case unquote(expr) do
896+
result when result in [false, nil] -> unquote(else_block)
897+
_ -> unquote(if_block)
898+
end
899+
end
900+
end
901+
end")
902+
903+
876904
(elixir-def-indentation-test indent-binary-sequence
877905
(:tags '(indentation))
878906
"

0 commit comments

Comments
 (0)