aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJackson Ray Hamilton2019-03-24 13:17:12 -0700
committerJackson Ray Hamilton2019-04-08 22:48:23 -0700
commit84b1cfbc2d6b9236913a18ed192798fd530911db (patch)
tree8d96fb77965f2f0e9025e38adbe597e95a2352ab
parentd9d1bb2b07750f3b2f2a9f8fa3d7aa1a5ec5038e (diff)
downloademacs-84b1cfbc2d6b9236913a18ed192798fd530911db.tar.gz
emacs-84b1cfbc2d6b9236913a18ed192798fd530911db.zip
Indent broken arrow function bodies as an N+1th arg
* lisp/progmodes/js.el (js--line-terminating-arrow-re): Revise regexp for use with re-search-backward. (js--looking-at-broken-arrow-function-p): Remove. (js--broken-arrow-terminates-line-p): Replacement for js--looking-at-broken-arrow-function-p. Don’t consider whether an arrow appears at point (in an arglist); instead, just look for an arrow that terminates the line. (js--proper-indentation): Use js--broken-arrow-terminates-line-p. * test/manual/indent/js.js: Add test for a broken arrow as an N+1th arg.
-rw-r--r--lisp/progmodes/js.el22
-rw-r--r--test/manual/indent/js.js5
2 files changed, 13 insertions, 14 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 5d87489b524..f8dd72c22bc 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -2550,23 +2550,17 @@ indentation is aligned to that column."
2550 (when comma-p 2550 (when comma-p
2551 (goto-char (1+ declaration-keyword-end)))))))) 2551 (goto-char (1+ declaration-keyword-end))))))))
2552 2552
2553(defconst js--line-terminating-arrow-re "\\s-*=>\\s-*\\(/[/*]\\|$\\)" 2553(defconst js--line-terminating-arrow-re "=>\\s-*\\(/[/*]\\|$\\)"
2554 "Regexp matching the last \"=>\" (arrow) token on a line. 2554 "Regexp matching the last \"=>\" (arrow) token on a line.
2555Whitespace and comments around the arrow are ignored.") 2555Whitespace and comments around the arrow are ignored.")
2556 2556
2557(defun js--looking-at-broken-arrow-function-p () 2557(defun js--broken-arrow-terminates-line-p ()
2558 "Helper function for `js--proper-indentation'. 2558 "Helper function for `js--proper-indentation'.
2559Return t if point is at the start of a (possibly async) arrow 2559Return t if the last non-comment, non-whitespace token of the
2560function and the last non-comment, non-whitespace token of the 2560current line is the \"=>\" token (of an arrow function)."
2561current line is the \"=>\" token." 2561 (let ((from (point)))
2562 (when (looking-at "\\s-*async\\s-*") 2562 (end-of-line)
2563 (goto-char (match-end 0))) 2563 (re-search-backward js--line-terminating-arrow-re from t)))
2564 (cond
2565 ((eq (char-after) ?\()
2566 (forward-list)
2567 (looking-at-p js--line-terminating-arrow-re))
2568 (t (looking-at-p
2569 (concat js--name-re js--line-terminating-arrow-re)))))
2570 2564
2571(defun js-jsx--context () 2565(defun js-jsx--context ()
2572 "Determine JSX context and move to enclosing JSX." 2566 "Determine JSX context and move to enclosing JSX."
@@ -2713,7 +2707,7 @@ return nil."
2713 (goto-char (nth 1 parse-status)) ; go to the opening char 2707 (goto-char (nth 1 parse-status)) ; go to the opening char
2714 (if (or (not js-indent-align-list-continuation) 2708 (if (or (not js-indent-align-list-continuation)
2715 (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)") 2709 (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
2716 (save-excursion (forward-char) (js--looking-at-broken-arrow-function-p))) 2710 (save-excursion (forward-char) (js--broken-arrow-terminates-line-p)))
2717 (progn ; nothing following the opening paren/bracket 2711 (progn ; nothing following the opening paren/bracket
2718 (skip-syntax-backward " ") 2712 (skip-syntax-backward " ")
2719 (when (eq (char-before) ?\)) (backward-list)) 2713 (when (eq (char-before) ?\)) (backward-list))
diff --git a/test/manual/indent/js.js b/test/manual/indent/js.js
index 647d7438f45..9658c95701c 100644
--- a/test/manual/indent/js.js
+++ b/test/manual/indent/js.js
@@ -160,6 +160,11 @@ foo.bar.baz(very => // A comment
160 snorf 160 snorf
161); 161);
162 162
163// Continuation of bug#25904; support broken arrow as N+1th arg
164map(arr, (val) =>
165 val
166)
167
163// Local Variables: 168// Local Variables:
164// indent-tabs-mode: nil 169// indent-tabs-mode: nil
165// js-indent-level: 2 170// js-indent-level: 2