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: Mon, 13 Nov 2017 01:02:28 +0200 Message-ID: <7f9fd974-e768-b532-ad86-33adb531d189@yandex.ru> References: <87shdp63vk.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 1510527793 13126 195.159.176.226 (12 Nov 2017 23:03:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Nov 2017 23:03:13 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Thunderbird/56.0 To: Felipe Ochoa , 25904@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 13 00:03:09 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 1eE1HQ-00031v-UY for geb-bug-gnu-emacs@m.gmane.org; Mon, 13 Nov 2017 00:03:09 +0100 Original-Received: from localhost ([::1]:51536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eE1HW-0005g2-E3 for geb-bug-gnu-emacs@m.gmane.org; Sun, 12 Nov 2017 18:03:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eE1HN-0005ew-Ts for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 18:03:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eE1HK-0006GY-Qn for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 18:03:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56891) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eE1HK-0006GQ-NK for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 18:03:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eE1HK-0002q9-CU for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2017 18:03: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: Sun, 12 Nov 2017 23:03: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.151052776110891 (code B ref 25904); Sun, 12 Nov 2017 23:03:02 +0000 Original-Received: (at 25904) by debbugs.gnu.org; 12 Nov 2017 23:02:41 +0000 Original-Received: from localhost ([127.0.0.1]:37339 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eE1Gx-0002pa-Gz for submit@debbugs.gnu.org; Sun, 12 Nov 2017 18:02:41 -0500 Original-Received: from mail-wr0-f193.google.com ([209.85.128.193]:54455) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eE1Gu-0002pJ-Vj for 25904@debbugs.gnu.org; Sun, 12 Nov 2017 18:02:37 -0500 Original-Received: by mail-wr0-f193.google.com with SMTP id l22so12874452wrc.11 for <25904@debbugs.gnu.org>; Sun, 12 Nov 2017 15:02:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=9BdIXd2PICnML8XFn2pSQQ9AX9w5xv+hd1o/44NNbik=; b=le0qJNJv5aqaphy8rPOEWeFtdIRiN5wBqTRPHU1eKKpg+m80yRfJ53WFXvLAN80d7J pWf8Iml3xs7enjB6glYzKIwT0rM/TA9JPQASIYRRcL4jpm+uIESoR1xABSnda19b9LgC Uoyyxi1TUsWMqM2WNW79yXXxkd/t/w1SeZl1+ZvPKQVPMqubRWgZ8Y98C8CpGod19cTL irhSfbdzoemf4yXh5/5MmEUzfDTzNc8WDQnqe+2eUKc07n4VF5uPAaC+ELuAKNo9KuIE XJtC/6OlQS5pehuaL2705+E3xF2Xtkjf2iDwIL1AqkZ38eoBzrmhrvhRw3tpew+52Bmd FqtQ== 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:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9BdIXd2PICnML8XFn2pSQQ9AX9w5xv+hd1o/44NNbik=; b=hwtJvs+zoz3aXb+1c6EX1P9zjt/Ily13YH1SLZYNdaNhJfKRTxMPdch2syyOS4VJLu BBJawXieBwvyXGFXBSIcDG1MQlTZmO+paOi0lBnoDeVnjkpp6JBXNnOwoYIoUqeP8m0N 0ORfHjVmzx3BQfLAeCh+ipToIqKqx//MzUSfclyHvZUJTr4/sp6UNEGGUwcHzrl0jDh3 O6Yev2ycDOWLF5mVUeMdHaK+UHHbavolnzC9R33oDjoMHRUPgx+so80VRec5TjXOzBo9 3ZAeo6Ui/HtxkHflv6W9ZHUH3cdTo+wHoizO/H+OYKB7yJR0Z2THZLbw2bzT9lH4j6Bq wKpA== X-Gm-Message-State: AJaThX5Pm2IMRSPsBSXufRQ9sYS/1rB39VmiCKBO+q4wio8yEwS9gD0F y80SoyQIQ80WGGg1IRw9/74L7Og0 X-Google-Smtp-Source: AGs4zMaq/djRuxHuSsvqNyJjMNyeZc3FxD+6MDLwlvHSCgx+kmKWfixCm6XQIl0pWdAWLSbNO1C9vQ== X-Received: by 10.223.157.204 with SMTP id q12mr5835282wre.241.1510527750738; Sun, 12 Nov 2017 15:02:30 -0800 (PST) Original-Received: from [192.168.1.3] ([185.105.174.193]) by smtp.googlemail.com with ESMTPSA id l7sm9387309wrg.69.2017.11.12.15.02.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Nov 2017 15:02:29 -0800 (PST) In-Reply-To: <87shdp63vk.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:139815 Archived-At: Hi Felipe! On 11/8/17 1:55 AM, Felipe Ochoa wrote: > 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. 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. It also wouldn't hurt that the existing examples are unchanged with the new code. >              (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 > "[/*]/\\|=>"))) OK. > @@ -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)? To allow comments between the opening paren and the arglist? Does anybody write them there? > +                          (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-*\\(/[/*]\\|$\\)"))))))) 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. Arglist matcher might be on the big side, but I'm guessing the performance will be better. Not sure how big of an issue this is. If it's not one regexp, moving some of the new code into a helper function (with a sensible name) seems prudent.