From 4df233adc5a1d5ab54d3c7419a463ae1ef417c12 Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Wed, 11 Sep 2013 06:44:27 -0400 Subject: Support EEP37 named funs in emacs erlang-mode Change emacs erlang-mode to recognize EEP37 named funs so they're indented properly. Specifically, modify erlang-partial-parse to allow for an optional Erlang variable name to appear between the "fun" keyword and the opening parenthesis of its argument list. --- lib/tools/emacs/erlang.el | 6 ++++++ lib/tools/emacs/test.erl.indented | 13 +++++++++++++ lib/tools/emacs/test.erl.orig | 13 +++++++++++++ 3 files changed, 32 insertions(+) (limited to 'lib/tools/emacs') diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index c395d22356..c1e9bec6ae 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -2600,6 +2600,12 @@ Value is list (stack token-start token-type in-what)." (if (save-excursion (goto-char (match-end 1)) (erlang-skip-blank to) + ;; Use erlang-variable-regexp here to look for an + ;; optional variable name to match EEP37 named funs. + (if (looking-at erlang-variable-regexp) + (progn + (goto-char (match-end 0)) + (erlang-skip-blank to))) (eq (following-char) ?\()) (erlang-push (list 'fun token (current-column)) stack))) ((looking-at "\\(begin\\|query\\)[^_a-zA-Z0-9]") diff --git a/lib/tools/emacs/test.erl.indented b/lib/tools/emacs/test.erl.indented index 7e61bcc45b..0de626125c 100644 --- a/lib/tools/emacs/test.erl.indented +++ b/lib/tools/emacs/test.erl.indented @@ -483,6 +483,19 @@ indent_fun() -> Y = true andalso kalle end), + %% check EEP37 named funs + Fn1 = fun Fact(N) when N > 0 -> + F = Fact(N-1), + N * F; + Fact(0) -> + 1 + end, + %% check anonymous funs too + Fn2 = fun(0) -> + 1; + (N) -> + N + end, ok. indent_try_catch() -> diff --git a/lib/tools/emacs/test.erl.orig b/lib/tools/emacs/test.erl.orig index 932758997d..57263d573b 100644 --- a/lib/tools/emacs/test.erl.orig +++ b/lib/tools/emacs/test.erl.orig @@ -483,6 +483,19 @@ Var = spawn(fun(X) Y = true andalso kalle end), +%% check EEP37 named funs +Fn1 = fun Fact(N) when N > 0 -> + F = Fact(N-1), + N * F; +Fact(0) -> + 1 + end, +%% check anonymous funs too + Fn2 = fun(0) -> +1; + (N) -> + N + end, ok. indent_try_catch() -> -- cgit v1.2.3