From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#25904: Formatting bug with js-mode Date: Thu, 23 Nov 2017 23:41:45 +0200 Message-ID: References: <87shdp63vk.fsf@gmail.com> <7f9fd974-e768-b532-ad86-33adb531d189@yandex.ru> <87y3n0mvzd.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1511473336 4379 195.159.176.226 (23 Nov 2017 21:42:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 23 Nov 2017 21:42:16 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Thunderbird/57.0 Cc: 25904@debbugs.gnu.org To: Felipe Ochoa Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 23 22:42:11 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 1eHzG6-0000aF-TP for geb-bug-gnu-emacs@m.gmane.org; Thu, 23 Nov 2017 22:42:11 +0100 Original-Received: from localhost ([::1]:46107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHzGC-00066u-90 for geb-bug-gnu-emacs@m.gmane.org; Thu, 23 Nov 2017 16:42:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHzG1-00066Y-Qd for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2017 16:42:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHzFy-00057n-MQ for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2017 16:42:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45560) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eHzFy-00056y-I8 for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2017 16:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eHzFy-0005TD-4i for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2017 16:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Nov 2017 21:42:02 +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.151147331721016 (code B ref 25904); Thu, 23 Nov 2017 21:42:02 +0000 Original-Received: (at 25904) by debbugs.gnu.org; 23 Nov 2017 21:41:57 +0000 Original-Received: from localhost ([127.0.0.1]:54241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHzFt-0005St-9C for submit@debbugs.gnu.org; Thu, 23 Nov 2017 16:41:57 -0500 Original-Received: from mail-wm0-f51.google.com ([74.125.82.51]:35658) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHzFq-0005Sf-QU for 25904@debbugs.gnu.org; Thu, 23 Nov 2017 16:41:55 -0500 Original-Received: by mail-wm0-f51.google.com with SMTP id y80so19043430wmd.0 for <25904@debbugs.gnu.org>; Thu, 23 Nov 2017 13:41:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:cc:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=s64jCXpQZFf1LmPbn/ngUt/Eebm8X/T8F9Rs3VDOF9E=; b=M+68pI0hzWMDVCa4p+qDHSkVbIcVuzlBX+5f/ElqPfpVQNNbvL3tFIQnVZcwJXmiDN EZuowMiBKuKiPMOXjuZicjQF0G7APoFfr5MmY4usf0dEnDASytAs1ZnOuQEcx7bH7mxd rpVIi92NmTxNlQZOnhlIQWx4R/hKaGIYCa6RqByEQT4AFNeFiOfImlkyXx1yn1+C2Wtb gEZmxixK5gIrUWciXAFALprCtVW1oPiFjKAyV+AX6m96ZPdmBZp1uTJ8YiKq2X2ZuPiF lngM4lj8saE7KcLzbrCTrGtRDvgnDoqzK8W0ATcXnn2ctOzuQuTEo6DT7ZEFKktXFBWq dHFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:cc:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=s64jCXpQZFf1LmPbn/ngUt/Eebm8X/T8F9Rs3VDOF9E=; b=DWmtOc4xnYza3C0xWLonb6CNIjfYorhRqQYjzrAGE04upW3xwAw3Gg+wdCb5OgeJFc 7EmyVRtBkXHQXyfRW46atTvfr9RDSrdN/iNx6YG4aFgAF8FAstb9Kn1jdC/hQwGsd8t2 rcy5EGxPq7uxoCcjElldCDemvznMR6c7vj28mZcQBXhFYND32t4Fbn6npQ8kZn+2oe82 MyOLVTUjU4rA2kn13jdoyOdyUGDywH17xIWwe90h1uq8IDGHkAZxNgYIXTg+7maAWcge 5PEqNPckJAn9oWAmohPCIby47grLOF0dtthDG7c6pjoCAMNNW140yZlYtcDXQoBJdLr5 oiKw== X-Gm-Message-State: AJaThX6I4yIOIEqT4QDifQgCKYu7LinJYOWfvvP0Txw+Ps5kVfjPvwsU FB/bAQhmQ8G7BBi3i5/VpQUfprvR X-Google-Smtp-Source: AGs4zMaSGhh03qGc2ixCPSc0doTfTCIU6IXkc1+qQsFasBR84UwUIdmYYDxigvQkQJrgKFXpApDVqA== X-Received: by 10.28.175.73 with SMTP id y70mr9028453wme.21.1511473308614; Thu, 23 Nov 2017 13:41:48 -0800 (PST) Original-Received: from [192.168.1.3] ([185.105.174.193]) by smtp.googlemail.com with ESMTPSA id k30sm34968828wrf.63.2017.11.23.13.41.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 13:41:47 -0800 (PST) In-Reply-To: <87y3n0mvzd.fsf@gmail.com> Content-Language: en-US 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:140277 Archived-At: On 11/21/17 12:22 AM, Felipe Ochoa wrote: > I've added a test to js.js in the latest patch below. Thanks. >> 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 Sure. > 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. No, sorry, I forgot about destructuring and etc. forward-list is fine here. >> 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. Thanks. > +(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-*\\)?") This looks weird: the regexp will always match. Better to write it as (if (looking-at NON-OPT-REGEXP) (goto-char ...)), where NON-OPT-REGEXP does not include the optional qualifier (?). And the (save-excursion...) form seems unnecessary, since the caller already uses it. > +       (save-excursion > +         (goto-char (match-end 0)) > +         (cond > +          ((eq (char-after) ?\() > +           (forward-list) ; Is this better than forward-sexp? I think so: it should be a bit faster, and it doesn't require you to bind forward-sexp-function to nil (for e.g. js2-mode). > +           (looking-at-p "\\s-*=>\\s-*\\(/[/*]\\|$\\)")) > +          (t (looking-at-p > +              (concat js--name-re "\\s-*=>\\s-*\\(/[/*]\\|$\\)"))))))) Should we extract "\\s-*=>\\s-*\\(/[/*]\\|$\\)" to a local variable, or a constant? > (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 " ") This seems a bit extraneous: the regexps in the called function all start with "\\s-*", right? Let's maybe have the one or the other. > +                         (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 We write references to debbugs as bug#25904. bug-reference-mode can linkify the result. > +foo.bar.baz(very => > +  very > +).biz(([baz={a: [123]}, boz]) => > +  baz > +).snarf((snorf) => > +  snorf > +); > + Thank you. Please attach the resulting patch as a file produced by 'git format-patch', with a ChangeLog style message entry, as described in CONTRIBUTE.