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: Thu, 15 Mar 2018 20:06:57 -0500 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" X-Trace: blaine.gmane.org 1521162373 10430 195.159.176.226 (16 Mar 2018 01:06:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 16 Mar 2018 01:06:13 +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 Fri Mar 16 02:06:08 2018 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 1ewdou-0002Zf-87 for geb-bug-gnu-emacs@m.gmane.org; Fri, 16 Mar 2018 02:06:08 +0100 Original-Received: from localhost ([::1]:54543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewdqv-000051-I7 for geb-bug-gnu-emacs@m.gmane.org; Thu, 15 Mar 2018 21:08:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewdqp-0008WM-6J for bug-gnu-emacs@gnu.org; Thu, 15 Mar 2018 21:08:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewdql-00064N-2q for bug-gnu-emacs@gnu.org; Thu, 15 Mar 2018 21:08:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ewdqk-000648-U4 for bug-gnu-emacs@gnu.org; Thu, 15 Mar 2018 21:08:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ewdqk-00018T-Ie for bug-gnu-emacs@gnu.org; Thu, 15 Mar 2018 21:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Felipe Ochoa Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Mar 2018 01:08: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.15211624654342 (code B ref 25904); Fri, 16 Mar 2018 01:08:02 +0000 Original-Received: (at 25904) by debbugs.gnu.org; 16 Mar 2018 01:07:45 +0000 Original-Received: from localhost ([127.0.0.1]:35558 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewdqT-00017y-2F for submit@debbugs.gnu.org; Thu, 15 Mar 2018 21:07:45 -0400 Original-Received: from mail-ot0-f182.google.com ([74.125.82.182]:39774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewdqR-00017l-O6 for 25904@debbugs.gnu.org; Thu, 15 Mar 2018 21:07:44 -0400 Original-Received: by mail-ot0-f182.google.com with SMTP id h8-v6so8821208oti.6 for <25904@debbugs.gnu.org>; Thu, 15 Mar 2018 18:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=RAmUm5XiGkuiDQHCuqcy2hB4q6zHDjTaxBVtaKBkfK4=; b=UAwTMPL7Tv+L+7mtwZBOjdl7UgTidJUVTVgLyi4m5FVtNWoL2X2yq1EBsMWNzNYffm RjS07LppKA09eVHUa6DKA7G9SarZdxjosL+8Rd61hGb8p/qZWWPyZpq1BNvKU08ZwWbn 9SgW9co5tjru0itAhzdKr/RMWDgalkjAP2g1ySf4FwrDHhKiMEk0OfqzCLwQAi0Fpr52 y3UIKOwvouGa6EDTztrEo6MecVyGW+tkOSMCq603Zy5KzdjpQegvA5tppzcxL2pbp3NR KdAd9NQe8FjZEDXy6zpp7FbZFnCd2YMOdMdxTy7UWiGoKHc5GWBfnNnH+lKMrctALWVP 93yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=RAmUm5XiGkuiDQHCuqcy2hB4q6zHDjTaxBVtaKBkfK4=; b=KQbfV7qLzQBRJAi4TOyU5JBazBJxOzHefCZNrSOkmlxrF4F6lqjQJLiLNMZYZjx2hB eM9k7G5qF1aLgWHB40Yy/elXVe0YGzNNwabpLDey7DzdAFexIYBbcBAtlv9JM3rvg6/c jP2nnWzG7ljM8zhxUQQwdpQHwytEKVmpOzXbu+ep97i1m4J8DbG5TjJV8JLKA4nV5XB4 /i+cQmdB3sIdPITedkHYMwVRJHllpt/Sle2sjh4bh/PzL93n0cea+92A1AVX0K89o5CS kBurLsbY50V0ZOC+VsGyKq2/gcOQ26TD56OtV34OCqCWljkWf30Miy/riLX8i/opoBLf vAeg== X-Gm-Message-State: AElRT7Ff3YhvI099DyAubWvPKTkNPIdvLxnY2qu1N38pKSWIBnicu5/j 8peWji9MqFGBXaoIJpotP54BtMeUqHfL3WsAwqg= X-Google-Smtp-Source: AG47ELsvY1ztzch7KwD/lnjUzspipz9FilWX6/vh5yBtnyE08FrLkR15+egOZqqwOnbfJy39CFJ/nvHuA7RdC+vqNc0= X-Received: by 10.157.76.133 with SMTP id m5mr6651388otf.179.1521162458039; Thu, 15 Mar 2018 18:07:38 -0700 (PDT) Original-Received: by 10.74.97.93 with HTTP; Thu, 15 Mar 2018 18:06:57 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: -FA29TTvOiZcU-UDVMWSxccTLus 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:144315 Archived-At: This has taken a *little* longer than I'd hoped, but here's a new patch with all the discussed changes. Hopefully I got the commit message formatting and content right >From 0c7eed3fd9f7f77a071296c191e8569471bac4e5 Mon Sep 17 00:00:00 2001 From: Felipe Ochoa Date: Tue, 7 Nov 2017 16:50:42 -0500 Subject: [PATCH] Fixes js indentation after arrow function without parens From: felipe * lisp/progmodes/js.el (js--proper-indentation) (js--looking-at-broken-arrow-function-p) * test/manual/indent/js.js: Indent expression following an arrow as though it were enclosed in parentheses (Bug#25904) --- lisp/progmodes/js.el | 24 ++++++++++++++++++++++-- test/manual/indent/js.js | 9 +++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index f30e591..5a333a9 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1849,7 +1849,9 @@ js--continued-expression-p (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 "+\\+\\|--\\|/[/*]")))))))))) @@ -2078,6 +2080,23 @@ js--maybe-goto-declaration-keyword-end (when comma-p (goto-char (1+ declaration-keyword-end)))))))) +(defconst js--line-terminating-arrow "\\s-*=>\\s-*\\(/[/*]\\|$\\)" + "Regexp to match a \"=>\" token if it's the last non-whitespace, non-comment token in a line.") + +(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." + (when (looking-at "\\s-*async\\s-*") + (goto-char (match-end 0))) + (cond + ((eq (char-after) ?\() + (forward-list) + (looking-at-p js--line-terminating-arrow)) + (t (looking-at-p + (concat js--name-re js--line-terminating-arrow))))) + (defun js--proper-indentation (parse-status) "Return the proper indentation for the current line." (save-excursion @@ -2108,7 +2127,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-*\\(/[/*]\\|$\\)") + (progn (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 b0d8bca..fc39c12 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.7.4