From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Felipe Ochoa Newsgroups: gmane.emacs.bugs Subject: bug#25904: Formatting bug with js-mode Date: Mon, 20 Nov 2017 17:22:14 -0500 Message-ID: <87y3n0mvzd.fsf@gmail.com> References: <87shdp63vk.fsf@gmail.com> <7f9fd974-e768-b532-ad86-33adb531d189@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: blaine.gmane.org 1511216598 1779 195.159.176.226 (20 Nov 2017 22:23:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 20 Nov 2017 22:23:18 +0000 (UTC) Cc: 25904@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 20 23:23:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGuT5-0008Cj-Bl for geb-bug-gnu-emacs@m.gmane.org; Mon, 20 Nov 2017 23:23:07 +0100 Original-Received: from localhost ([::1]:60031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGuTC-0000K0-QU for geb-bug-gnu-emacs@m.gmane.org; Mon, 20 Nov 2017 17:23:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGuT4-0000Jr-3C for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2017 17:23:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGuT0-0002MA-2H for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2017 17:23:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40921) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eGuSz-0002M0-T4 for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2017 17:23:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eGuSz-0002PG-Ms for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2017 17:23:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Felipe Ochoa Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 Nov 2017 22:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25904-submit@debbugs.gnu.org id=B25904.15112165459196 (code B ref 25904); Mon, 20 Nov 2017 22:23:01 +0000 Original-Received: (at 25904) by debbugs.gnu.org; 20 Nov 2017 22:22:25 +0000 Original-Received: from localhost ([127.0.0.1]:49602 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGuSP-0002OG-7w for submit@debbugs.gnu.org; Mon, 20 Nov 2017 17:22:25 -0500 Original-Received: from mail-ua0-f169.google.com ([209.85.217.169]:40671) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGuSN-0002O2-I3 for 25904@debbugs.gnu.org; Mon, 20 Nov 2017 17:22:23 -0500 Original-Received: by mail-ua0-f169.google.com with SMTP id z43so6978295uac.7 for <25904@debbugs.gnu.org>; Mon, 20 Nov 2017 14:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:from:to:cc:subject:in-reply-to:date:message-id :mime-version; bh=zuw+cvCzrWlLyu5Y/6QiJVGpKjUjSxN3Y5Vdj3Ei/Lk=; b=fzMgchiUudI3wqbpSP3h5H3BX1Lc6Hoqwxfi7/fUYQj03dcJvJzXQyjbCNP8Scuf9l kFD+Ugzcv/id+LfAeWct9ps9CGWwBZZ5iuTdGEeuU4uy72F2jljDQqy0b9c93d0hTuWM HoYff9z7PEes6D9d70FHcxpPFC737SyrVZDwj2XE544uYBHL862kJaDEe09TkI6WKfXs 1Bi9gdgfPA7fdLwWO9pFZkRXt+Jy1CLd5iL297U3a+cT40EYEJjlDEIaMsv0Jj4dG200 +6d36F927iu/nQzC4uLHH8wk75761TcwgSsMTxiA0Sxvl3IVEMJZ+qwqWGQAj9QIXtVn XOsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=zuw+cvCzrWlLyu5Y/6QiJVGpKjUjSxN3Y5Vdj3Ei/Lk=; b=lEsHbbL0vYnaYbpvBCt6Z1JOZXzNrYCTYa1VlaEH1shGOopXnKhr/HBQC9oWIy6yPp 2xgTm2i5M/WbHUnAeCNOJBHJCRYLV9KeqtQyejmadu2b4pJUbxmB9Lv3G8tv9nyYm0UK NmJeNULnGczlX+AheWQ1rFAgUK2ClP6yB1wvX6koEKiQazPWruzJVlosNrqyruDBIeaF /52ciRMZFy6kfmkNQBtC8jj+MLTlrAhrAJBBqrhsTct7pAhZXIqHrk72Zl45oWWLx7jS AkT0LeywkLHQf776SB+9dF0seXok+rSA1zA3S4sI2qzVIkuLbSX28L1Ak1jjOktNIaHh cuuw== X-Gm-Message-State: AJaThX42FDGB2h9VbbqYF7NVoEodWlTLaqsGa0pwjfoLV6oj6locJSVG nh6BmT6GKWBmOeiiKtBT54Byqhq9 X-Google-Smtp-Source: AGs4zMZEGOjvc/7UFxqpr5ywmIKVAIwiDyK6i8CZEWDVwrY33xPN3x9B1tAobR08dYATPT6EMzlCrA== X-Received: by 10.176.24.74 with SMTP id j10mr12541274uag.18.1511216537835; Mon, 20 Nov 2017 14:22:17 -0800 (PST) Original-Received: from x1-ubuntu ([181.60.234.59]) by smtp.gmail.com with ESMTPSA id 193sm1443912vkp.38.2017.11.20.14.22.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 14:22:16 -0800 (PST) In-reply-to: <7f9fd974-e768-b532-ad86-33adb531d189@yandex.ru> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:140179 Archived-At: Hi Dmitry! > I think the code is reasonable, but the patch needs a few > examples for emacs/test/manual/js*.js. Maybe add a new file, or > maybe reuse an existing one. I've added a test to js.js in the latest patch below. > It also wouldn't hurt that the existing examples are unchanged > with the new code. I checked all the existing examples manually and all were unchanged when applying indent-region on the entire buffer. > To allow comments between the opening paren and the arglist? > Does anybody write them there? Oops -- this comment was supposed to be after the arrow. I was thinking of return type annotation comments, but I just checked flow and I don't think they support this. We can just remove the comment > I imagine this (*) could be transformed into a single regexp, > though it would be pretty complex (rx could help, though!). > > (*) Looking at an opening paren followed by ([optional] lambda > arglist and an arrow) then [optional] comment and newline. Is there an arglist regexp already in use somewhere? I'd rather not roll my own since dealing with default argument values and spreads and such seems quite challenging. > If it's not one regexp, moving some of the new code into a > helper function (with a sensible name) seems prudent. I've done this in the latest patch. --- lisp/progmodes/js.el | 26 ++++++++++++++++++++++++-- test/manual/indent/js.js | 9 +++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 1f86909..6e057b0 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 "+\\+\\|--\\|/[/*]")))))))))) @@ -2077,6 +2079,21 @@ indentation is aligned to that column." (when comma-p (goto-char (1+ declaration-keyword-end)))))))) +(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 like is the \"=>\" token." + (and (looking-at "\\s-*\\(async\\s-*\\)?") + (save-excursion + (goto-char (match-end 0)) + (cond + ((eq (char-after) ?\() + (forward-list) ; Is this better than forward-sexp? + (looking-at-p "\\s-*=>\\s-*\\(/[/*]\\|$\\)")) + (t (looking-at-p + (concat js--name-re "\\s-*=>\\s-*\\(/[/*]\\|$\\)"))))))) + (defun js--proper-indentation (parse-status) "Return the proper indentation for the current line." (save-excursion @@ -2107,7 +2124,12 @@ 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-*\\(/[/*]\\|$\\)") + (when (eq (char-after) ?\() + (save-excursion + (forward-char) + (skip-syntax-forward " ") + (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 b0d8bca..2286cc1 100644 --- a/test/manual/indent/js.js +++ b/test/manual/indent/js.js @@ -144,6 +144,15 @@ bar( /abc/ ) +// #25904 +foo.bar.baz(very => + very +).biz(([baz={a: [123]}, boz]) => + baz +).snarf((snorf) => + snorf +); + // Local Variables: // indent-tabs-mode: nil // js-indent-level: 2 -- 2.7.4