Skip to content

Commit

Permalink
Merge pull request #317 from elixir-lang/correct-pipeline-indenation
Browse files Browse the repository at this point in the history
Correct pipeline indentation
  • Loading branch information
tonini committed Apr 3, 2016
2 parents e909185 + eebce30 commit c5d1cba
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
41 changes: 35 additions & 6 deletions elixir-smie.el
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
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

0 comments on commit c5d1cba

Please sign in to comment.