Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions elixir-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@
(beginning-of-line)
(looking-at "^\s+->.+$")))

(defun elixir-smie-current-line-start-with-pipe-operator-p ()
(save-excursion
(beginning-of-line)
(looking-at "^\s*|>.+$")))

(defun elixir-smie-last-line-is-assignment-p ()
(save-excursion
(forward-line -1)
(beginning-of-line)
(looking-at "^.+=.+$")))

(defun elixir-smie-last-line-start-with-pipe-operator-p ()
(save-excursion
(forward-line -1)
(beginning-of-line)
(looking-at "^\s*|>.+$")))

(defun elixir-smie-line-starts-with-do-colon-p ()
(save-excursion
(beginning-of-line)
Expand Down Expand Up @@ -305,11 +322,20 @@
(`(:elem . args)
-4)
(`(:before . "OP")
(cond ((and (not (smie-rule-hanging-p))
(smie-rule-prev-p "OP"))
-2)
((smie-rule-parent-p "def" "defp" "defmacro" "defmacrop")
(smie-rule-parent))))
(cond
((and (not (smie-rule-hanging-p))
(elixir-smie-current-line-start-with-pipe-operator-p)
(elixir-smie-last-line-is-assignment-p))
(smie-rule-parent))
((and (not (smie-rule-hanging-p))
(elixir-smie-current-line-start-with-pipe-operator-p))
(goto-char (elixir-smie--previous-line-indentation)))
((and (not (smie-rule-hanging-p))
(smie-rule-prev-p "OP"))
-2)
((smie-rule-parent-p "def" "defp" "defmacro" "defmacrop")
(smie-rule-parent))
(t (smie-rule-parent))))
(`(:before . "def")
(cond
(t
Expand Down Expand Up @@ -648,7 +674,10 @@
((and (smie-rule-parent-p ";")
(smie-rule-hanging-p)
(elixir-smie-line-starts-with-do-colon-p))
(smie-rule-parent (- elixir-smie-indent-basic)))))
(smie-rule-parent (- elixir-smie-indent-basic)))

((elixir-smie-current-line-start-with-pipe-operator-p)
(smie-rule-parent))))
(`(:after . ";")
(cond
((smie-rule-parent-p "def")
Expand Down
26 changes: 25 additions & 1 deletion test/elixir-mode-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,31 @@ defmodule Foo do
end
")

(elixir-def-indentation-test indent-pipes
(elixir-def-indentation-test indent-multiline-pipes-after-call
(:tags '(indentation))
"
some_string
|> String.downcase
|> String.strip"
"
some_string
|> String.downcase
|> String.strip")

(elixir-def-indentation-test indent-multiline-on-the-right-of-pattern-match
(:tags '(indentation))
"
sanitized_string =
some_string
|> String.downcase
|> String.strip"
"
sanitized_string =
some_string
|> String.downcase
|> String.strip")

(elixir-def-indentation-test indent-pipes-after-assignment
(:tags '(indentation))
"
def foo(x) do
Expand Down