Skip to content

correct indentation after one line definition with if keyword #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2015
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
20 changes: 19 additions & 1 deletion elixir-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@
((smie-rule-hanging-p)
(smie-rule-parent elixir-smie-indent-basic))
(t elixir-smie-indent-basic)))
(`(:before . "if")
(cond
((smie-rule-parent-p ";")
(smie-rule-parent))))
(`(:before . "->")
(cond
((smie-rule-hanging-p)
Expand Down Expand Up @@ -364,9 +368,23 @@
(t (smie-rule-parent elixir-smie-indent-basic))))))
(`(:before . ";")
(cond
;; There is a case after an one line definition of functions/macros
;; when an `if' keyword token is involved, where the next block `end'
;; token will have a `if' as parent and it's hanging.
;;
;; Example:
;;
;; defmacro my_if(expr, do: if_block), do: if(expr, do: if_block, else: nil)
;; defmacro my_if(expr, do: if_block, else: else_block) do
;; ...
;; end <- parent is `if`
((and (smie-rule-parent-p "if")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rules are getting quite extensive. We need to start adding comments explaining what these are for.

(smie-rule-hanging-p))
(smie-rule-parent))
((smie-rule-parent-p "after" "catch" "def" "defmodule" "defp" "do" "else"
"fn" "if" "rescue" "try" "unless")
(smie-rule-parent elixir-smie-indent-basic))))
(smie-rule-parent elixir-smie-indent-basic))
))
(`(:after . ";")
(cond
((smie-rule-parent-p "def")
Expand Down
28 changes: 28 additions & 0 deletions test/elixir-mode-indentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,34 @@ defmodule Greeter do
end
end")

(elixir-def-indentation-test indent-after-def-do-online/2
(:tags '(indentation))

"defmodule ControlFlow do
defmacro my_if(expr, do: if_block), do: if(expr, do: if_block, else: nil)
defmacro my_if(expr, do: if_block, else: else_block) do
quote do
case unquote(expr) do
result when result in [false, nil] -> unquote(else_block)
_ -> unquote(if_block)
end
end
end
end"

"defmodule ControlFlow do
defmacro my_if(expr, do: if_block), do: if(expr, do: if_block, else: nil)
defmacro my_if(expr, do: if_block, else: else_block) do
quote do
case unquote(expr) do
result when result in [false, nil] -> unquote(else_block)
_ -> unquote(if_block)
end
end
end
end")


(elixir-def-indentation-test indent-binary-sequence
(:tags '(indentation))
"
Expand Down