From e90d37805e43091219a34614618ac3bd9b71f515 Mon Sep 17 00:00:00 2001 From: Matt DeBoard Date: Thu, 10 Jul 2014 00:12:07 -0400 Subject: [PATCH 1/3] Add grammar rule for one-line anon fns. Refs #59 Unfortunately this fix also broke a couple other tests around multi-line anon fns. --- elixir-smie.el | 1 + test/elixir-mode-indentation-tests.el | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/elixir-smie.el b/elixir-smie.el index e1823c64..81728dfb 100644 --- a/elixir-smie.el +++ b/elixir-smie.el @@ -259,6 +259,7 @@ Return non-nil if any line breaks were skipped." ("try" "do" statements "end") ("case" non-block-expr "do" match-statements "end") ("def" non-block-expr "do" statements "end") + (non-block-expr "fn" match-statement "end") (non-block-expr "do" statements "end") (expr) ) diff --git a/test/elixir-mode-indentation-tests.el b/test/elixir-mode-indentation-tests.el index f4ddc2b1..e455dbcb 100644 --- a/test/elixir-mode-indentation-tests.el +++ b/test/elixir-mode-indentation-tests.el @@ -363,7 +363,7 @@ to_process = [27, 33, 35, 11, 36, 29, 18, 37, 21, 31, 19, 10, 14, 30, ") (elixir-def-indentation-test indent-nested-fn - (:expected-result :failed) ; #59 + () "defmodule FooModule do def foo do x = fn(a, b) -> a + b end From 78cbe16d04b7b40fe936ec211bc05a0a194c38eb Mon Sep 17 00:00:00 2001 From: Matt DeBoard Date: Thu, 10 Jul 2014 00:38:56 -0400 Subject: [PATCH 2/3] Move grammar rules around. This alleviated a precedence error I was getting: .do < else:. < .do --- elixir-smie.el | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/elixir-smie.el b/elixir-smie.el index 81728dfb..81f95aef 100644 --- a/elixir-smie.el +++ b/elixir-smie.el @@ -250,6 +250,8 @@ Return non-nil if any line breaks were skipped." (statement) (statement ";" statements)) (statement + (non-block-expr "fn" match-statement "end") + (non-block-expr "do" statements "end") ("if" non-block-expr "do" statements "else" statements "end") ("if" non-block-expr "do" statements "end") ("if" non-block-expr "COMMA" "do:" statement) @@ -258,11 +260,7 @@ Return non-nil if any line breaks were skipped." ("try" "do" statements "catch" match-statements "end") ("try" "do" statements "end") ("case" non-block-expr "do" match-statements "end") - ("def" non-block-expr "do" statements "end") - (non-block-expr "fn" match-statement "end") - (non-block-expr "do" statements "end") - (expr) - ) + ("def" non-block-expr "do" statements "end")) (non-block-expr (non-block-expr "OP" non-block-expr) (non-block-expr "COMMA" non-block-expr) From 98b370f36e603115811656446e0fea5dd19f1e03 Mon Sep 17 00:00:00 2001 From: Matt DeBoard Date: Thu, 10 Jul 2014 00:57:05 -0400 Subject: [PATCH 3/3] Add logic to handle indenting anon fns. Refs #59 --- elixir-smie.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/elixir-smie.el b/elixir-smie.el index 81f95aef..a96d641b 100644 --- a/elixir-smie.el +++ b/elixir-smie.el @@ -308,9 +308,15 @@ Return non-nil if any line breaks were skipped." ;; for some reason SMIE doesn't look this far when there's a ;; comment terminating the previous line. Ugh. nil) + ;; If the parent token of `->' is `fn', then we want to align to the + ;; parent, and offset by `elixir-smie-indent-basic'. Otherwise, indent + ;; normally. This helps us work with/indent anonymous function blocks + ;; correctly. (`(:after . "->") (when (smie-rule-hanging-p) - elixir-smie-indent-basic)) + (if (smie-rule-parent-p "fn") + (smie-rule-parent elixir-smie-indent-basic) + elixir-smie-indent-basic))) (`(,_ . ,(or `"COMMA")) (smie-rule-separator kind)) (`(:after . "=") elixir-smie-indent-basic) (`(:after . "end") 0)