From b73657309e74235c0fbf15c6e7df2d9500c65dd4 Mon Sep 17 00:00:00 2001 From: Samuel Tonini Date: Wed, 26 Aug 2015 16:50:15 +0200 Subject: [PATCH] Correct indent in case expr when returning a tuple --- elixir-smie.el | 13 ++++++++++++- test/elixir-mode-indentation-test.el | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/elixir-smie.el b/elixir-smie.el index 9975a298..61045d39 100644 --- a/elixir-smie.el +++ b/elixir-smie.el @@ -410,7 +410,18 @@ ;; { _, [ user, project, count ], _ } ((and (not (smie-rule-hanging-p)) (smie-rule-parent-p "do")) - (smie-rule-parent)) + ;; If the last line ends with a block operator `->' + ;; indent two spaces more + ;; + ;; Example + ;; + ;; case File.read("/usr/share/dict/words") do + ;; {:ok, contents} -> + ;; {:something, contents} <- Indent here two spaces + ;; ... + (if (elixir-smie-last-line-end-with-block-operator-p) + (smie-rule-parent elixir-smie-indent-basic) + (smie-rule-parent))) ((and (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") (not (smie-rule-hanging-p))) (if (elixir-smie-last-line-end-with-block-operator-p) diff --git a/test/elixir-mode-indentation-test.el b/test/elixir-mode-indentation-test.el index 12725eae..72ef98c9 100644 --- a/test/elixir-mode-indentation-test.el +++ b/test/elixir-mode-indentation-test.el @@ -1286,6 +1286,29 @@ case parse do _ -> :help end") +(elixir-def-indentation-test complex-case-with-matches/3 + (:tags '(indentation)) +" +defmodule MyModule do +case File.read(\"/usr/share/dict/words\") do +{:ok, contents} -> + {:something, contents} + {:error, reason} -> +{:error, reason} + end +end +" +" +defmodule MyModule do + case File.read(\"/usr/share/dict/words\") do + {:ok, contents} -> + {:something, contents} + {:error, reason} -> + {:error, reason} + end +end +") + (elixir-def-indentation-test close-map-curly-brackt (:tags '(indentation)) "