From 555dd0d1e23505aba546984e1c153f757779244a Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Thu, 13 Feb 2020 12:37:41 +0100 Subject: emacs: Improve indentation Parser lost its wherabouts if there was a type that contained a list with a fun inside it. Also fix alignment of '|' inside lists, ',',';' and other delimiters are aligned '|' should be too. --- lib/tools/emacs/erlang.el | 12 +++++++----- lib/tools/test/emacs_SUITE.erl | 3 ++- lib/tools/test/emacs_SUITE_data/type_specs | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index 838c41a090..16329aeb6f 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -4,7 +4,7 @@ ;; Author: Anders Lindgren ;; Keywords: erlang, languages, processes ;; Date: 2011-12-11 -;; Version: 2.8.3 +;; Version: 2.8.4 ;; Package-Requires: ((emacs "24.3")) ;; %CopyrightBegin% @@ -87,7 +87,7 @@ "The Erlang programming language." :group 'languages) -(defconst erlang-version "2.8.3" +(defconst erlang-version "2.8.4" "The version number of Erlang mode.") (defcustom erlang-root-dir nil @@ -2890,7 +2890,7 @@ Value is list (stack token-start token-type in-what)." ((looking-at "-type\\s \\|-opaque\\s ") (if stack (forward-char 1) - (erlang-push (list 'icr token (current-column)) stack) + (erlang-push (list 'type token (current-column)) stack) (forward-char 6))) ((looking-at "-spec\\s ") (if stack @@ -2933,7 +2933,7 @@ Value is list (stack token-start token-type in-what)." (erlang-pop stack) (if (and (eq (car (car stack)) 'fun) (or (eq (car (car (last stack))) 'spec) - (eq (car (car (cdr stack))) '::))) ;; -type() + (eq (car (car (last stack))) 'type))) ;; -type() ;; Inside fun type def ') closes fun definition (erlang-pop stack))) ((eq (car (car stack)) 'icr) @@ -2995,7 +2995,9 @@ Return nil if inside string, t if in a comment." (- (+ previous erlang-argument-indent) 1)))) (t (nth 2 stack-top)))) - ((= (following-char) ?,) + ((looking-at "||") + (erlang-indent-element stack-top indent-point token)) + ((memq (following-char) '(?, ?|)) ;; a comma at the start of the line: line up with opening parenthesis. (min (nth 2 stack-top) (erlang-indent-element stack-top indent-point token))) diff --git a/lib/tools/test/emacs_SUITE.erl b/lib/tools/test/emacs_SUITE.erl index 42a1f395ec..9a0caa0867 100644 --- a/lib/tools/test/emacs_SUITE.erl +++ b/lib/tools/test/emacs_SUITE.erl @@ -214,11 +214,12 @@ emacs(EmacsCmds) when is_list(EmacsCmds) -> "--directory ", dquote(emacs_dir()), " ", "--eval \"(require 'erlang-start)\" " | EmacsCmds], + io:format("Cmd: ~ts~n", [Cmd]), Res0 = os:cmd(Cmd ++ " ; echo $?"), Rows = string:lexemes(Res0, ["\r\n", $\n]), Res = lists:last(Rows), Output = string:join(lists:droplast(Rows), "\n"), - io:format("Cmd ~ts:~n => ~s ~ts~n", [Cmd, Res, Output]), + io:format(" => ~s ~ts~n", [Res, Output]), "0" = Res, Output. diff --git a/lib/tools/test/emacs_SUITE_data/type_specs b/lib/tools/test/emacs_SUITE_data/type_specs index f9b15d7914..a72e90cf57 100644 --- a/lib/tools/test/emacs_SUITE_data/type_specs +++ b/lib/tools/test/emacs_SUITE_data/type_specs @@ -66,6 +66,30 @@ , b :: any() }. + +-type combined() :: { atom(), + atom() + , integer() + } + | [ atom() | + atom() + | integer() + ]. + +-type a_list1() :: [ atom() | + t() + | tuple() + ]. + + +-type a_list_with_fun() :: + %% ERL-1140 + [ atom() | + fun() + | tuple() + ]. + + %% Spec -spec t1(FooBar :: t99()) -> t99(); -- cgit v1.2.1 From 6e802c8d08442a96ea3b12786bb5c9a6d3451e20 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Thu, 13 Feb 2020 13:21:42 +0100 Subject: emacs: Fix try indentation try Expr of Pattern -> ok ... 'Pattern' indented wrong when non default erlang-indent-level was set. --- lib/tools/emacs/erlang.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index 16329aeb6f..dafb9d56ac 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -3035,9 +3035,9 @@ Return nil if inside string, t if in a comment." (save-excursion (goto-char (nth 1 stack-top)) (if (and erlang-icr-indent - (looking-at "\\(if\\|case\\|receive\\)[^_a-zA-Z0-9]")) + (looking-at "\\(if\\|case\\|receive\\|try\\)[^_a-zA-Z0-9]")) (+ (nth 2 stack-top) erlang-icr-indent) - (if (looking-at "\\(case\\|receive\\)[^_a-zA-Z0-9]") + (if (looking-at "\\(case\\|receive\\|try\\)[^_a-zA-Z0-9]") (+ (nth 2 stack-top) erlang-indent-level) (skip-chars-forward "a-z") (skip-chars-forward " \t") -- cgit v1.2.1