Skip to content

Commit fb61175

Browse files
committed
Correct anonymous fun indent inside block
1 parent af713e6 commit fb61175

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

elixir-smie.el

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@
246246
;; And if we're NOT on a blank line, move to the end of the line, and see
247247
;; if we're looking back at a block operator.
248248
(t (move-end-of-line 1)
249-
(looking-back elixir-smie--block-operator-regexp)))))))
249+
(and (looking-back elixir-smie--block-operator-regexp)
250+
(not (looking-back ".+fn.+")))))))))
250251

251252
(defun elixir-smie--same-line-as-parent (parent-pos child-pos)
252253
"Return non-nil if `child-pos' is on same line as `parent-pos'."
@@ -377,6 +378,8 @@
377378
((and (smie-rule-parent-p "do")
378379
(smie-rule-hanging-p))
379380
(smie-rule-parent))
381+
((and (smie-rule-parent-p "fn"))
382+
(smie-rule-parent elixir-smie-indent-basic))
380383
;; There is a case when between two line inside a def block
381384
;; when jumping to the next line and indent, where the cursor
382385
;; jumps too much in front.
@@ -471,8 +474,7 @@
471474
((and (smie-rule-parent-p "def")
472475
(smie-rule-hanging-p))
473476
(smie-rule-parent elixir-smie-indent-basic))
474-
(t
475-
elixir-smie-indent-basic)))
477+
(t elixir-smie-indent-basic)))
476478
(`(:before . "end")
477479
(smie-rule-parent))
478480
;; Closing paren on the other line
@@ -685,7 +687,9 @@
685687
(smie-rule-parent (- elixir-smie-indent-basic)))
686688

687689
((elixir-smie-current-line-start-with-pipe-operator-p)
688-
(smie-rule-parent))))
690+
(smie-rule-parent))
691+
((smie-rule-parent-p "(")
692+
(smie-rule-parent elixir-smie-indent-basic))))
689693
(`(:after . ";")
690694
(cond
691695
((smie-rule-parent-p "def")

test/elixir-mode-indentation-test.el

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ x = do_something(:foo,
823823
:bar)"
824824
"
825825
x = do_something(:foo,
826-
:bar)")
826+
:bar)")
827827

828828
(elixir-def-indentation-test indent-inside-parens/3
829829
(:tags '(indentation))
@@ -955,14 +955,15 @@ end"
955955

956956
(elixir-def-indentation-test indent-mixed-match
957957
(:tags '(indentation))
958-
"
958+
"
959959
case x do
960960
a -> b
961961
c ->
962962
d
963963
e -> f
964964
end
965-
" "
965+
"
966+
"
966967
case x do
967968
a -> b
968969
c ->
@@ -1814,6 +1815,25 @@ Enum.map(addresses, fn({mac_address, dbms}) ->
18141815
end)
18151816
")
18161817

1818+
(elixir-def-indentation-test indent-statement-with-anonymous-fn
1819+
(:tags '(indentation))
1820+
"
1821+
cond do
1822+
is_nil(val) ->
1823+
IO.puts \"OK\"
1824+
Enum.any?(1..6, fn -> end)
1825+
true ->
1826+
end
1827+
"
1828+
"
1829+
cond do
1830+
is_nil(val) ->
1831+
IO.puts \"OK\"
1832+
Enum.any?(1..6, fn -> end)
1833+
true ->
1834+
end
1835+
")
1836+
18171837
;; We don't want automatic whitespace cleanup here because of the significant
18181838
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
18191839
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my

0 commit comments

Comments
 (0)