[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/jsx e196207 15/19: Indent broken arrow function bo
From: |
Marcin Borkowski |
Subject: |
[Emacs-diffs] feature/jsx e196207 15/19: Indent broken arrow function bodies as an N+1th arg |
Date: |
Wed, 27 Mar 2019 05:35:02 -0400 (EDT) |
branch: feature/jsx
commit e1962071a5b8c77bed1af8f9b6b1c636400de130
Author: Jackson Ray Hamilton <address@hidden>
Commit: Marcin Borkowski <address@hidden>
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.
---
lisp/progmodes/js.el | 22 ++++++++--------------
test/manual/indent/js.js | 5 +++++
2 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 5d87489..f8dd72c 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -2550,23 +2550,17 @@ indentation is aligned to that column."
(when comma-p
(goto-char (1+ declaration-keyword-end))))))))
-(defconst js--line-terminating-arrow-re "\\s-*=>\\s-*\\(/[/*]\\|$\\)"
+(defconst js--line-terminating-arrow-re "=>\\s-*\\(/[/*]\\|$\\)"
"Regexp matching the last \"=>\" (arrow) token on a line.
Whitespace and comments around the arrow are ignored.")
-(defun js--looking-at-broken-arrow-function-p ()
+(defun js--broken-arrow-terminates-line-p ()
"Helper function for `js--proper-indentation'.
-Return t if point is at the start of a (possibly async) arrow
-function and the last non-comment, non-whitespace token of the
-current line is the \"=>\" token."
- (when (looking-at "\\s-*async\\s-*")
- (goto-char (match-end 0)))
- (cond
- ((eq (char-after) ?\()
- (forward-list)
- (looking-at-p js--line-terminating-arrow-re))
- (t (looking-at-p
- (concat js--name-re js--line-terminating-arrow-re)))))
+Return t if the last non-comment, non-whitespace token of the
+current line is the \"=>\" token (of an arrow function)."
+ (let ((from (point)))
+ (end-of-line)
+ (re-search-backward js--line-terminating-arrow-re from t)))
(defun js-jsx--context ()
"Determine JSX context and move to enclosing JSX."
@@ -2713,7 +2707,7 @@ return nil."
(goto-char (nth 1 parse-status)) ; go to the opening char
(if (or (not js-indent-align-list-continuation)
(looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
- (save-excursion (forward-char)
(js--looking-at-broken-arrow-function-p)))
+ (save-excursion (forward-char)
(js--broken-arrow-terminates-line-p)))
(progn ; nothing following the opening paren/bracket
(skip-syntax-backward " ")
(when (eq (char-before) ?\)) (backward-list))
diff --git a/test/manual/indent/js.js b/test/manual/indent/js.js
index 647d743..9658c95 100644
--- a/test/manual/indent/js.js
+++ b/test/manual/indent/js.js
@@ -160,6 +160,11 @@ foo.bar.baz(very => // A comment
snorf
);
+// Continuation of bug#25904; support broken arrow as N+1th arg
+map(arr, (val) =>
+ val
+)
+
// Local Variables:
// indent-tabs-mode: nil
// js-indent-level: 2
- [Emacs-diffs] branch feature/jsx created (now acab35c), Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 24fcdad 03/19: Add new (failing) unclosed JSX test and separate such tests, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 754f826 01/19: Add failing tests for JSX indentation bugs, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 91c29fb 09/19: Update expectations for JSX indentation in JSXAttribute space, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 539191c 07/19: Font-lock JSX while editing it by extending regions, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 79954c6 05/19: Use js-jsx- prefix for functions and variables, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx acab35c 19/19: Add tests for miscellaneous JSX parsing feats, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx e196207 15/19: Indent broken arrow function bodies as an N+1th arg,
Marcin Borkowski <=
- [Emacs-diffs] feature/jsx 071c134 06/19: Add basic JSX font-locking, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx ec144e9 12/19: Automatically detect JSX in JavaScript files, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx c66bfa6 10/19: Indent JSX as parsed in a JS context, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx f7ac5e4 11/19: Finish replacing SGML-based JSX detection with js-mode’s parsing, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 79118f8 16/19: Fix counting of nested self-closing JSXOpeningElements, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 4337acd 14/19: Rename tests to use the “.jsx” file extension, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 66433fd 13/19: Improve JSX syntax propertization, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx ae0ee9b 18/19: Split JSX indentation calculation into several functions, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 2b4cc70 17/19: Indent expressions in JSXAttributes relative to the attribute’s name, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx d5dae48 02/19: Refactor JSX indentation code to improve enclosing JSX discovery, Marcin Borkowski, 2019/03/27