bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25904: Formatting bug with js-mode


From: Felipe Ochoa
Subject: bug#25904: Formatting bug with js-mode
Date: Tue, 07 Nov 2017 18:55:11 -0500

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]