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: Tue, 07 Nov 2017 18:55:11 -0500 Message-ID: <87shdp63vk.fsf@gmail.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: blaine.gmane.org 1510098976 13553 195.159.176.226 (7 Nov 2017 23:56:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 7 Nov 2017 23:56:16 +0000 (UTC) To: 25904@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 08 00:56: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 1eCDj1-00033z-8J for geb-bug-gnu-emacs@m.gmane.org; Wed, 08 Nov 2017 00:56:11 +0100 Original-Received: from localhost ([::1]:56354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCDj2-0007Fv-0o for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Nov 2017 18:56:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCDiv-0007Fe-Ji for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2017 18:56:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eCDis-0003Pu-IF for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2017 18:56:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48549) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eCDis-0003Pm-Dx for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2017 18:56:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eCDis-0004GC-0p for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2017 18:56:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Felipe Ochoa Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Nov 2017 23:56: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.151009892316326 (code B ref 25904); Tue, 07 Nov 2017 23:56:01 +0000 Original-Received: (at 25904) by debbugs.gnu.org; 7 Nov 2017 23:55:23 +0000 Original-Received: from localhost ([127.0.0.1]:57230 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCDiF-0004FG-Bs for submit@debbugs.gnu.org; Tue, 07 Nov 2017 18:55:23 -0500 Original-Received: from mail-vk0-f43.google.com ([209.85.213.43]:50019) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCDiD-0004F3-Rp for 25904@debbugs.gnu.org; Tue, 07 Nov 2017 18:55:22 -0500 Original-Received: by mail-vk0-f43.google.com with SMTP id t184so636600vka.6 for <25904@debbugs.gnu.org>; Tue, 07 Nov 2017 15:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=rQwF4W1NYwSOOI7yg7VJ1wMk38m9EeoktDnVtS7btQ8=; b=V2kIJHEPGC+5Z4/0vNG75g/EmUFR09cUOTKWgRwnf+6HTwVX4SyS04t04z1R4DkTcW sf39w79TerUbn5sfkf0Wi4KGA3snnsGbqdr5AuCkWuwThcA5C0jVPWsLVN8HGMUAoASC IEqjpJ+1omfW/BiXFdg7lp2ga9+dQd7MFrGtunMjxnvomKWjxKlUEZg6AtjTPeHRF+Zs dw4/O7gWqyjxfRvvzDSU93gbIBDMdZ4TMyFA6S9yrVRKv3zhLfkxOXBpL4KFHkS2rkOi 2YWqC4wy4Z72GY0Hu/HfSiGKa214emjWu82z62EOIpKEYOqRCyVQ3pqnuWWNYapBpCBG Zexg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=rQwF4W1NYwSOOI7yg7VJ1wMk38m9EeoktDnVtS7btQ8=; b=SmGCECpSPi0P4wph1PtiUBb73qufnU2m6fiBHRShTVZglPyY4Lt9hqqdrt2FnV+KI3 oe2/qsJRwo/zcVc6Zr6C2iYVOQfKpXYDlKm/Y16T+qVgLPTK2T2ebnyGopm93ngFB0pS n2B2bj95l4k3F3VhWWuV/e3uauhIh8HlVj4JmQ//v7QC5b6hVQp+BQIm5scYr8gnf//e TWGZ35xaCXhMhTRCKkcg6pcUCJc3ivNV6/c/1mzGlr1OThb3Z7cBsDsxmRRFfSmbNSn/ FXrGrZJPY/X9qIyXeDrT3jWIt3y+D38NwzSpqMcRODgnY8JFwUSY3atnGL0ELWZJVZLG detA== X-Gm-Message-State: AJaThX6cFv8E1P/YNouLJ29W8pLXgKFH97eMkzHizWt91RPYxVCMxGDj KEh4V2wMfgKZkSH4usZU6JPOlP5/ X-Google-Smtp-Source: ABhQp+RpX3b8UQ3ANVEP6oUYIdWvSHILeAIRoa8OzTWFeSTmVxlxuSv0TYLKmBmK0PXRv0ryjrBKPg== X-Received: by 10.31.89.7 with SMTP id n7mr372085vkb.77.1510098916000; Tue, 07 Nov 2017 15:55:16 -0800 (PST) Original-Received: from x1-ubuntu ([181.60.234.59]) by smtp.gmail.com with ESMTPSA id s16sm487533vka.53.2017.11.07.15.55.14 for <25904@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 15:55:15 -0800 (PST) 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:139587 Archived-At: 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