unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
To: 25904@debbugs.gnu.org
Subject: bug#25904: Patches
Date: Sun, 10 Feb 2019 14:03:44 -0800 (PST)	[thread overview]
Message-ID: <1195338258.64458.1549836224184@privateemail.com> (raw)
In-Reply-To: <CAEtRwfCeH8yeiaCc+wF3mRtvVh3F0PTi7G5HvjSrzBuH_EQrMw@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 756 bytes --]

Hello Dmitry and Felipe,

I’ve taken a stab at formatting Felipe’s fix for arrow function indentation according to the coding standards.  Compared to his patch, I made some trivial name/doc changes, and changed

(progn (forward-char) (js--looking-at-broken-arrow-function-p))

to

(save-excursion (forward-char) (js--looking-at-broken-arrow-function-p))

since we probably want to undo the forward-char in case the form returns nil.

In order to get all the JS indentation tests to pass with make, I also had to make a variable safe file-locally.

Both changes are attached.  They could be applied to the emacs-26 branch.  (Or master, but emacs-26 would be preferable so we can deliver it sooner.  I tested on both branches.)

Jackson

[-- Attachment #1.2: Type: text/html, Size: 954 bytes --]

[-- Attachment #2: 0001-Indent-arrows-expression-bodies-like-function-bodies.patch --]
[-- Type: text/x-patch, Size: 3802 bytes --]

From 383a6aa13f90346b489bc4b8f900fe767a725b90 Mon Sep 17 00:00:00 2001
From: Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Date: Sat, 9 Feb 2019 12:26:21 -0800
Subject: [PATCH] =?UTF-8?q?Indent=20arrows=E2=80=99=20expression=20bodies?=
 =?UTF-8?q?=20like=20function=20bodies=20(Bug#25904)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/progmodes/js.el (js--continued-expression-p): Don’t confuse
‘=>’ for a ‘>’ operator.
(js--line-terminating-arrow-re): New variable.
(js--looking-at-broken-arrow-function-p): New function.
(js--proper-indentation): Don’t align arrow functions’ expression
bodies starting on new lines like list continuations, instead align
them like function bodies (js-indent-align-list-continuation need not
be nil).

* test/manual/indent/js.js: Add test for Bug#25904.

Co-authored-by: Felipe Ochoa <felipe@fov.space>
---
 lisp/progmodes/js.el     | 23 +++++++++++++++++++++--
 test/manual/indent/js.js |  9 +++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 65ffb0e02f..787afb4e10 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1849,7 +1849,7 @@ js--continued-expression-p
              (skip-chars-backward " \t")
              (or (bobp) (backward-char))
              (and (> (point) (point-min))
-                  (save-excursion (backward-char) (not (looking-at "[/*]/")))
+                  (save-excursion (backward-char) (not (looking-at "[/*]/\\|=>")))
                   (js--looking-at-operator-p)
                   (and (progn (backward-char)
                               (not (looking-at "+\\+\\|--\\|/[/*]"))))))))))
@@ -2078,6 +2078,24 @@ js--maybe-goto-declaration-keyword-end
         (when comma-p
           (goto-char (1+ declaration-keyword-end))))))))
 
+(defconst js--line-terminating-arrow-re "\\s-*=>\\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 ()
+  "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)))))
+
 (defun js--proper-indentation (parse-status)
   "Return the proper indentation for the current line."
   (save-excursion
@@ -2108,7 +2126,8 @@ js--proper-indentation
                  (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-*\\(/[/*]\\|$\\)")
+                     (save-excursion (forward-char) (js--looking-at-broken-arrow-function-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 b0d8bcabd2..fc39c12244 100644
--- a/test/manual/indent/js.js
+++ b/test/manual/indent/js.js
@@ -144,6 +144,15 @@ bar(
   /abc/
 )
 
+// bug#25904
+foo.bar.baz(very => // A comment
+  very
+).biz(([baz={a: [123]}, boz]) =>
+  baz
+).snarf((snorf) => /* Another comment */
+  snorf
+);
+
 // Local Variables:
 // indent-tabs-mode: nil
 // js-indent-level: 2
-- 
2.11.0


[-- Attachment #3: 0001-js-indent-align-list-continuation-Make-variable-safe.patch --]
[-- Type: text/x-patch, Size: 900 bytes --]

From 918f873d1d702d4e23353747b97b77004dd738de Mon Sep 17 00:00:00 2001
From: Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Date: Sat, 9 Feb 2019 11:50:05 -0800
Subject: [PATCH] js-indent-align-list-continuation: Make variable safe

* lisp/progmodes/js.el (js-indent-align-list-continuation): Indicate
variable is safe as a file-local variable.  This fixes the
js-indent-align-list-continuation-nil test when run with make.
---
 lisp/progmodes/js.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index a94a2fe134..6e18e30517 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -477,6 +477,7 @@ js-indent-align-list-continuation
   "Align continuation of non-empty ([{ lines in `js-mode'."
   :version "26.1"
   :type 'boolean
+  :safe 'booleanp
   :group 'js)
 
 (defcustom js-comment-lineup-func #'c-lineup-C-comments
-- 
2.11.0


  parent reply	other threads:[~2019-02-10 22:03 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
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     ` Jackson Ray Hamilton [this message]
2019-02-13  0:27       ` bug#25904: Patches 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=1195338258.64458.1549836224184@privateemail.com \
    --to=jackson@jacksonrayhamilton.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).