From: Felipe Ochoa <felipeochoa0918@gmail.com>
To: 25904@debbugs.gnu.org
Subject: bug#25904: Formatting bug with js-mode
Date: Tue, 07 Nov 2017 18:55:11 -0500 [thread overview]
Message-ID: <87shdp63vk.fsf@gmail.com> (raw)
In-Reply-To: <CAEtRwfCeH8yeiaCc+wF3mRtvVh3F0PTi7G5HvjSrzBuH_EQrMw@mail.gmail.com>
Here's an initial implementation of a solution for this
issue. (Also filed as js2#314 [1])
foo.bar.baz(very =>
very // current code aligns return value to paren above
).biz(baz =>
baz
);
I've been using this code successfully for a number of days now,
but since it's my first time touching indentation code, it likely
needs review for I comments and whitespace handling, etc.
(Note: disabling `js-indent-align-list-continuation' also
addresses this issue, but disabling it changes indentation in
other parts.)
[1]: https://github.com/mooz/js2-mode/issues/314
---
lisp/progmodes/js.el | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 1f86909..18f888d 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1848,7 +1848,9 @@ This performs fontification according to `js--class-styles'."
(skip-chars-backward " \t")
(or (bobp) (backward-char))
(and (> (point) (point-min))
- (save-excursion (backward-char) (not (looking-at "[/*]/")))
+ ;; Need to exclude => here since js--looking-at-operator-p thinks
+ ;; it's looking at an assignment operator
+ (save-excursion (backward-char) (not (looking-at "[/*]/\\|=>")))
(js--looking-at-operator-p)
(and (progn (backward-char)
(not (looking-at "+\\+\\|--\\|/[/*]"))))))))))
@@ -2107,7 +2109,18 @@ indentation is aligned to that column."
(continued-expr-p (js--continued-expression-p)))
(goto-char (nth 1 parse-status)) ; go to the opening char
(if (or (not js-indent-align-list-continuation)
- (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)"))
+ (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
+ ;; check for a arrow function without parens
+ (and (looking-at "(\\s-*\\(async\\s-*\\)?")
+ ;; TODO: should call (forward-comment most-positive-fixnum)?
+ (save-excursion
+ (goto-char (match-end 0))
+ (cond
+ ((eq (char-after) ?\()
+ (forward-sexp)
+ (looking-at-p "\\s-*=>\\s-*\\(/[/*]\\|$\\)"))
+ (t (looking-at-p
+ (concat js--name-re "\\s-*=>\\s-*\\(/[/*]\\|$\\)")))))))
(progn ; nothing following the opening paren/bracket
(skip-syntax-backward " ")
(when (eq (char-before) ?\)) (backward-list))
--
2.7.4
next prev parent reply other threads:[~2017-11-07 23:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAEtRwfDCdNSBPH=1Ohe3sBZJ70QBzJY3nd+Xs0uk85EuA3GRtw@mail.gmail.com>
[not found] ` <CAEtRwfA5_ibO2tmKCDtOHOs9ZCYosn21sKe5gC9LhE3y54GDyQ@mail.gmail.com>
2017-02-28 22:50 ` bug#25904: Formatting bug with js-mode Michael Snead
2017-11-07 23:55 ` Felipe Ochoa [this message]
2017-11-12 23:02 ` Dmitry Gutov
2017-11-20 22:22 ` Felipe Ochoa
2017-11-23 21:41 ` Dmitry Gutov
2018-03-16 1:06 ` Felipe Ochoa
2018-05-04 21:37 ` Dmitry Gutov
2018-04-29 1:20 ` bug#25904: bug#24896: JSX prop indentation after fat arrow Jimmy Yuen Ho Wong
2018-04-29 2:43 ` Eli Zaretskii
2019-02-10 22:03 ` bug#25904: Patches Jackson Ray Hamilton
2019-02-13 0:27 ` Dmitry Gutov
2019-02-13 4:01 ` Jackson Ray Hamilton
2019-02-13 15:15 ` Eli Zaretskii
2019-02-14 1:20 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shdp63vk.fsf@gmail.com \
--to=felipeochoa0918@gmail.com \
--cc=25904@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).