aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tools/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tools/emacs')
-rw-r--r--lib/tools/emacs/erlang-skels.el24
-rw-r--r--lib/tools/emacs/erlang.el43
-rw-r--r--lib/tools/emacs/test.erl.indented29
-rw-r--r--lib/tools/emacs/test.erl.orig29
4 files changed, 99 insertions, 26 deletions
diff --git a/lib/tools/emacs/erlang-skels.el b/lib/tools/emacs/erlang-skels.el
index 527e812444..7379215d68 100644
--- a/lib/tools/emacs/erlang-skels.el
+++ b/lib/tools/emacs/erlang-skels.el
@@ -109,32 +109,32 @@ include separators of the form %%--...")
;; Expression templates:
(defvar erlang-skel-case
'((erlang-skel-skip-blank) o >
- "case " p " of" n> p "_ ->" n> p "ok" n> "end" p)
+ "case " p " of" n> p "_ ->" n> p "ok" n "end" > p)
"*The skeleton of a `case' expression.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-if
'((erlang-skel-skip-blank) o >
- "if" n> p " ->" n> p "ok" n> "end" p)
+ "if" n> p " ->" n> p "ok" n "end" > p)
"The skeleton of an `if' expression.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-receive
'((erlang-skel-skip-blank) o >
- "receive" n> p "_ ->" n> p "ok" n> "end" p)
+ "receive" n> p "_ ->" n> p "ok" n "end" > p)
"*The skeleton of a `receive' expression.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-receive-after
'((erlang-skel-skip-blank) o >
- "receive" n> p "_ ->" n> p "ok" n> "after " p "T ->" n>
- p "ok" n> "end" p)
+ "receive" n> p "_ ->" n> p "ok" n "after " > p "T ->" n>
+ p "ok" n "end" > p)
"*The skeleton of a `receive' expression with an `after' clause.
Please see the function `tempo-define-template'.")
(defvar erlang-skel-receive-loop
'(& o "loop(" p ") ->" n> "receive" n> p "_ ->" n>
- "loop(" p ")" n> "end.")
+ "loop(" p ")" n "end." >)
"*The skeleton of a simple `receive' loop.
Please see the function `tempo-define-template'.")
@@ -256,8 +256,8 @@ Please see the function `tempo-define-template'.")
"loop(From) ->" n>
"receive" n>
p "_ ->" n>
- "loop(From)" n>
- "end." n
+ "loop(From)" n
+ "end." > n
)
"*Template of a small server.
Please see the function `tempo-define-template'.")
@@ -291,8 +291,8 @@ Please see the function `tempo-define-template'.")
"{ok, Pid} ->" n>
"{ok, Pid};" n>
"Error ->" n>
- "Error" n>
- "end." n
+ "Error" n
+ "end." > n
n
(erlang-skel-separator-start 2)
"%% @private" n
@@ -421,8 +421,8 @@ Please see the function `tempo-define-template'.")
"{ok, Pid} ->" n>
"{ok, Pid, #state{}};" n>
"Error ->" n>
- "Error" n>
- "end." n
+ "Error" n
+ "end." > n
n
(erlang-skel-separator-start 2)
"%% @private" n
diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el
index 9bccfaab95..ec5a1f4bc5 100644
--- a/lib/tools/emacs/erlang.el
+++ b/lib/tools/emacs/erlang.el
@@ -73,6 +73,8 @@
;; M-x set-variable RET debug-on-error RET t RET
;;; Code:
+(eval-when-compile (require 'cl))
+
;; Variables:
(defconst erlang-version "2.7"
@@ -620,7 +622,6 @@ resulting regexp is surrounded by \\_< and \\_>."
"if"
"let"
"of"
- "query"
"receive"
"try"
"when")
@@ -663,6 +664,7 @@ resulting regexp is surrounded by \\_< and \\_>."
"is_function"
"is_integer"
"is_list"
+ "is_map"
"is_number"
"is_pid"
"is_port"
@@ -714,7 +716,8 @@ resulting regexp is surrounded by \\_< and \\_>."
"pos_integer"
"string"
"term"
- "timeout")
+ "timeout"
+ "map")
"Erlang type specs types"))
(eval-and-compile
@@ -771,6 +774,7 @@ resulting regexp is surrounded by \\_< and \\_>."
"is_function"
"is_integer"
"is_list"
+ "is_map"
"is_number"
"is_pid"
"is_port"
@@ -790,6 +794,7 @@ resulting regexp is surrounded by \\_< and \\_>."
"list_to_tuple"
"load_module"
"make_ref"
+ "map_size"
"max"
"min"
"module_loaded"
@@ -2569,9 +2574,9 @@ Value is list (stack token-start token-type in-what)."
(erlang-pop stack))
(if (and stack (memq (car (car stack)) '(icr begin fun try)))
(erlang-pop stack))))
- ((looking-at "catch.*of")
+ ((looking-at "catch\\b.*of")
t)
- ((looking-at "catch\\s *\\($\\|%\\|.*->\\)")
+ ((looking-at "catch\\b\\s *\\($\\|%\\|.*->\\)")
;; Must pop top icr layer, `catch' in try/catch
;;will push a new layer next.
(progn
@@ -2604,18 +2609,24 @@ 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]")
+ ((looking-at "\\(begin\\)[^_a-zA-Z0-9]")
(erlang-push (list 'begin token (current-column)) stack))
;; Normal when case
;;((looking-at "when\\s ")
;;((looking-at "when\\s *\\($\\|%\\)")
((looking-at "when[^_a-zA-Z0-9]")
(erlang-push (list 'when token (current-column)) stack))
- ((looking-at "catch.*of")
+ ((looking-at "catch\\b.*of")
t)
- ((looking-at "catch\\s *\\($\\|%\\|.*->\\)")
+ ((looking-at "catch\\b\\s *\\($\\|%\\|.*->\\)")
(erlang-push (list 'icr token (current-column)) stack))
;;(erlang-push (list '-> token (current-column)) stack))
;;((looking-at "^of$")
@@ -2906,7 +2917,7 @@ Return nil if inside string, t if in a comment."
(if stack
(erlang-caddr (car stack))
0))
- ((looking-at "catch\\($\\|[^_a-zA-Z0-9]\\)")
+ ((looking-at "catch\\b\\($\\|[^_a-zA-Z0-9]\\)")
;; Are we in a try
(let ((start (if (eq (car stack-top) '->)
(car (cdr stack))
@@ -3042,7 +3053,7 @@ This assumes that the preceding expression is either simple
\(i.e. an atom) or parenthesized."
(save-excursion
(or arg (setq arg 1))
- (forward-sexp (- arg))
+ (ignore-errors (forward-sexp (- arg)))
(let ((col (current-column)))
(skip-chars-backward " \t")
;; Special hack to handle: (note line break)
@@ -3116,13 +3127,13 @@ This assumes that the preceding expression is either simple
(defun erlang-at-keyword ()
"Are we looking at an Erlang keyword which will increase indentation?"
- (looking-at (concat "\\(when\\|if\\|fun\\|case\\|begin\\|query\\|"
- "of\\|receive\\|after\\|catch\\|try\\)[^_a-zA-Z0-9]")))
+ (looking-at (concat "\\(when\\|if\\|fun\\|case\\|begin\\|"
+ "of\\|receive\\|after\\|catch\\|try\\)\\b")))
(defun erlang-at-operator ()
"Are we looking at an Erlang operator?"
(looking-at
- "\\(bnot\\|div\\|mod\\|band\\|bor\\|bxor\\|bsl\\|bsr\\)[^_a-zA-Z0-9]"))
+ "\\(bnot\\|div\\|mod\\|band\\|bor\\|bxor\\|bsl\\|bsr\\)\\b"))
(defun erlang-comment-indent ()
"Compute Erlang comment indentation.
@@ -3649,6 +3660,10 @@ Normally used in conjunction with `erlang-beginning-of-clause', e.g.:
(setq cont nil))
((looking-at "\\s *\\($\\|%\\)")
(forward-line 1))
+ ((looking-at "\\s *<<[^>]*?>>")
+ (when (zerop res)
+ (setq res (+ 1 res)))
+ (goto-char (match-end 0)))
((looking-at "\\s *,")
(setq res (+ 1 res))
(goto-char (match-end 0)))
@@ -3930,7 +3945,7 @@ non-whitespace characters following the point on the current line."
(self-insert-command arg)
;; Was this the second char in bit-syntax open (`<<')?
- (unless (< (point) 2)
+ (unless (<= (point) 2)
(save-excursion
(backward-char 2)
(when (and (eq (char-after (point)) ?<)
@@ -3951,7 +3966,7 @@ non-whitespace characters following the point on the current line."
(defun erlang-after-bitsyntax-close ()
"Return t if point is immediately after a bit-syntax close parenthesis (`>>')."
- (and (>= (point) 2)
+ (and (>= (point) 3)
(save-excursion
(backward-char 2)
(and (eq (char-after (point)) ?>)
diff --git a/lib/tools/emacs/test.erl.indented b/lib/tools/emacs/test.erl.indented
index 7e61bcc45b..1c1086ca58 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() ->
@@ -731,3 +744,19 @@ commas_first() ->
] }
]
}.
+
+
+%% this used to result in a scan-sexp error
+[{
+ }].
+
+%% this used to result in 2x the correct indentation within the function
+%% body, due to the function name being mistaken for a keyword
+catcher(N) ->
+ try generate_exception(N) of
+ Val -> {N, normal, Val}
+ catch
+ throw:X -> {N, caught, thrown, X};
+ exit:X -> {N, caught, exited, X};
+ error:X -> {N, caught, error, X}
+ end.
diff --git a/lib/tools/emacs/test.erl.orig b/lib/tools/emacs/test.erl.orig
index 932758997d..a9d09000d2 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() ->
@@ -731,3 +744,19 @@ commas_first() ->
] }
]
}.
+
+
+%% this used to result in a scan-sexp error
+[{
+}].
+
+%% this used to result in 2x the correct indentation within the function
+%% body, due to the function name being mistaken for a keyword
+catcher(N) ->
+try generate_exception(N) of
+Val -> {N, normal, Val}
+catch
+throw:X -> {N, caught, thrown, X};
+exit:X -> {N, caught, exited, X};
+error:X -> {N, caught, error, X}
+end.