Skip to content

Commit c5d1cba

Browse files
committed
Merge pull request #317 from elixir-lang/correct-pipeline-indenation
Correct pipeline indentation
2 parents e909185 + eebce30 commit c5d1cba

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

elixir-smie.el

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@
195195
(beginning-of-line)
196196
(looking-at "^\s+->.+$")))
197197

198+
(defun elixir-smie-current-line-start-with-pipe-operator-p ()
199+
(save-excursion
200+
(beginning-of-line)
201+
(looking-at "^\s*|>.+$")))
202+
203+
(defun elixir-smie-last-line-is-assignment-p ()
204+
(save-excursion
205+
(forward-line -1)
206+
(beginning-of-line)
207+
(looking-at "^.+=.+$")))
208+
209+
(defun elixir-smie-last-line-start-with-pipe-operator-p ()
210+
(save-excursion
211+
(forward-line -1)
212+
(beginning-of-line)
213+
(looking-at "^\s*|>.+$")))
214+
198215
(defun elixir-smie-line-starts-with-do-colon-p ()
199216
(save-excursion
200217
(beginning-of-line)
@@ -305,11 +322,20 @@
305322
(`(:elem . args)
306323
-4)
307324
(`(:before . "OP")
308-
(cond ((and (not (smie-rule-hanging-p))
309-
(smie-rule-prev-p "OP"))
310-
-2)
311-
((smie-rule-parent-p "def" "defp" "defmacro" "defmacrop")
312-
(smie-rule-parent))))
325+
(cond
326+
((and (not (smie-rule-hanging-p))
327+
(elixir-smie-current-line-start-with-pipe-operator-p)
328+
(elixir-smie-last-line-is-assignment-p))
329+
(smie-rule-parent))
330+
((and (not (smie-rule-hanging-p))
331+
(elixir-smie-current-line-start-with-pipe-operator-p))
332+
(goto-char (elixir-smie--previous-line-indentation)))
333+
((and (not (smie-rule-hanging-p))
334+
(smie-rule-prev-p "OP"))
335+
-2)
336+
((smie-rule-parent-p "def" "defp" "defmacro" "defmacrop")
337+
(smie-rule-parent))
338+
(t (smie-rule-parent))))
313339
(`(:before . "def")
314340
(cond
315341
(t
@@ -648,7 +674,10 @@
648674
((and (smie-rule-parent-p ";")
649675
(smie-rule-hanging-p)
650676
(elixir-smie-line-starts-with-do-colon-p))
651-
(smie-rule-parent (- elixir-smie-indent-basic)))))
677+
(smie-rule-parent (- elixir-smie-indent-basic)))
678+
679+
((elixir-smie-current-line-start-with-pipe-operator-p)
680+
(smie-rule-parent))))
652681
(`(:after . ";")
653682
(cond
654683
((smie-rule-parent-p "def")

test/elixir-mode-indentation-test.el

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,31 @@ defmodule Foo do
696696
end
697697
")
698698

699-
(elixir-def-indentation-test indent-pipes
699+
(elixir-def-indentation-test indent-multiline-pipes-after-call
700+
(:tags '(indentation))
701+
"
702+
some_string
703+
|> String.downcase
704+
|> String.strip"
705+
"
706+
some_string
707+
|> String.downcase
708+
|> String.strip")
709+
710+
(elixir-def-indentation-test indent-multiline-on-the-right-of-pattern-match
711+
(:tags '(indentation))
712+
"
713+
sanitized_string =
714+
some_string
715+
|> String.downcase
716+
|> String.strip"
717+
"
718+
sanitized_string =
719+
some_string
720+
|> String.downcase
721+
|> String.strip")
722+
723+
(elixir-def-indentation-test indent-pipes-after-assignment
700724
(:tags '(indentation))
701725
"
702726
def foo(x) do

0 commit comments

Comments
 (0)