From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: john muhl Newsgroups: gmane.emacs.bugs Subject: bug#74298: [PATCH] ; Improve comment indenting in 'lua-ts-mode' Date: Sun, 10 Nov 2024 13:00:31 -0600 Message-ID: <87ldxq9ank.fsf@pub.pink> References: <87v7wu9ar3.fsf@pub.pink> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4379"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.12.1; emacs 31.0.50 To: 74298@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 10 20:01:10 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tADBN-0000wk-LO for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Nov 2024 20:01:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tADBH-0006AY-EM; Sun, 10 Nov 2024 14:01:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tADBG-0006AE-BM for bug-gnu-emacs@gnu.org; Sun, 10 Nov 2024 14:01:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tADBG-0001T1-0U for bug-gnu-emacs@gnu.org; Sun, 10 Nov 2024 14:01:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=Px6NElh4I8aBmxlCKqd6noSiL+x5tplbX0JpwW/LHjs=; b=LXFD21lK63DmmjfcBuizYqPMD1rYV5eJb8ke7ltfZmKCiOoFJ3ahSuzLg+ZtHPpri6sEacDo7+Zz5AElAK8+ToP1b4gOnyrstzbYR1TFDu4VZ3DStSZHiu/xQyFyWYKHWRckjsgJF7g8EHZgxHv53WGof0zA0mupWyAeqkxzX5pfmpJgyscNoQ3RmAT30MzswcQWu5tst76XAtB5ouWmSaohcuLj4QMHoFrC7BCxvOqcI5c2eSS4BS6QBexx35sBXfKMEKcTLfgpZuv4lKKRDjid2VSFh32p7IfXi1RLNjVMOC7UZIoY9v0oFDt+M4y1y6SJEkg/ufA6tqKa8IBE1g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tADBF-0008Rt-Rk for bug-gnu-emacs@gnu.org; Sun, 10 Nov 2024 14:01:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: john muhl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Nov 2024 19:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74298 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74298-submit@debbugs.gnu.org id=B74298.173126524032439 (code B ref 74298); Sun, 10 Nov 2024 19:01:01 +0000 Original-Received: (at 74298) by debbugs.gnu.org; 10 Nov 2024 19:00:40 +0000 Original-Received: from localhost ([127.0.0.1]:56626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tADAu-0008R9-2o for submit@debbugs.gnu.org; Sun, 10 Nov 2024 14:00:40 -0500 Original-Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]:50151) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tADAs-0008Qx-Hx for 74298@debbugs.gnu.org; Sun, 10 Nov 2024 14:00:39 -0500 Original-Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2ACF825400FF for <74298@debbugs.gnu.org>; Sun, 10 Nov 2024 14:00:33 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sun, 10 Nov 2024 14:00:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1731265233; x=1731351633; bh=Px6NElh4I8 aBmxlCKqd6noSiL+x5tplbX0JpwW/LHjs=; b=FqZcnZyhgosGG3pxmUvnMi4pLP 9mEA3GRypprGuArRljqxc8bo30S60UKuEc2qlcKe0qMLZXH3S06JilOK7kdooONr SpfwJEe1kGG4+eBz3qwsYKpnFEw8RdI9mt5UTHyYOtPe7rL9cWNGCsts/BIQtLkg 81Jmb8h8R8FnXy9JsnpofzTKAZi/fZx/EjqWTCOwDRTzNFNi898/2Uii8Gb4OKZB hnzSFBm5ERyJjzy3FTPEh6BSFS3ffQTcv+paUqRzH4bPQoKFKWpj0i1jVJWt3sZI +mXFN9dee3mkoNt4LnGBfptwFjVzojbWYCVP5yQ2HITAda9P63Yv1y3yTwqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731265233; x=1731351633; bh=Px6NElh4I8aBmxlCKqd6noSiL+x5tplbX0J pwW/LHjs=; b=h/5AJpckMd0vgmUOZcKqENTEiiDntGloAmKpsiWSgpdctvrRMDL RIxbm8kKAQl5cPrP8b85FvGcEeaTwQIgm+EAmI+HCqQwZhdW4SNnHh8EinST+FxP B0UArzTHjaSoHvA9EBSX5rnaJxmalP1HyYghFIyi55bgRzhWKZaBHVGmcCwOsfGp 247ykBdhayvlMtB8yHG0B7Jr+mZOZ3xUnI+kxIbsRDSafCfb6rv0EGbRuLDKupnC mfRaGMo0uhg9OtpauGcKi40QRXVUZIIPoTITfbSN5+IGXqulEeZBTVScNAmEUIDe 27FxBonvE18rmiZ/DWPmGkPWlSYZsEfStpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddtgdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffujg hffgffkfggtgesmhdtreertdertdenucfhrhhomhepjhhohhhnuchmuhhhlhcuoehjmhes phhusgdrphhinhhkqeenucggtffrrghtthgvrhhnpefgleehkeehveevtdefjedtuddvie fhgfekudelveeuheekgeffleeuvdetheetueenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehjmhesphhusgdrphhinhhkpdhnsggprhgtphhtth hopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeejgedvleekseguvggssghu ghhsrdhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: i74194916:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for <74298@debbugs.gnu.org>; Sun, 10 Nov 2024 14:00:32 -0500 (EST) In-Reply-To: <87v7wu9ar3.fsf@pub.pink> (john muhl's message of "Sun, 10 Nov 2024 12:58:24 -0600") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295200 Archived-At: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Improve-comment-indenting-in-lua-ts-mode.patch >From cdcbdeafa2b35a7584b7c4c5a19e999476e3a897 Mon Sep 17 00:00:00 2001 From: john muhl Date: Sun, 10 Nov 2024 11:26:33 -0600 Subject: [PATCH] ; Improve comment indenting in 'lua-ts-mode' * lisp/progmodes/lua-ts-mode.el (lua-ts--simple-indent-rules): Align single line comments with the surrounding context. (lua-ts--comment-first-sibling-matcher): Check that comment is the first sibling. (lua-ts--multi-line-comment-start): New function. * test/lisp/progmodes/lua-ts-mode-resources/indent.erts: Add tests. (Bug#74298) --- lisp/progmodes/lua-ts-mode.el | 17 ++++++-- .../lua-ts-mode-resources/indent.erts | 42 +++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index a7763377177..e5a2fafd279 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -289,7 +289,8 @@ lua-ts--font-lock-settings (defvar lua-ts--simple-indent-rules `((lua - ((or (node-is "comment") + ((or (and (node-is "comment") (parent-is "chunk")) + lua-ts--multi-line-comment-start (parent-is "comment_content") (parent-is "string_content") (node-is "]]")) @@ -473,9 +474,10 @@ lua-ts--nested-function-last-function-matcher (= 1 (length (cadr sparse-tree))))) (defun lua-ts--comment-first-sibling-matcher (node &rest _) - "Matches if NODE if it's previous sibling is a comment." + "Matches NODE if its previous sibling is a comment." (let ((sibling (treesit-node-prev-sibling node))) - (equal "comment" (treesit-node-type sibling)))) + (and (= 0 (treesit-node-index sibling t)) + (equal "comment" (treesit-node-type sibling))))) (defun lua-ts--top-level-function-call-matcher (node &rest _) "Matches if NODE is within a top-level function call." @@ -508,6 +510,15 @@ lua-ts--variable-declaration-continuation-anchor (line-beginning-position)) (point)))) +(defun lua-ts--multi-line-comment-start (node &rest _) + "Matches if NODE is the beginning of a multi-line comment." + (and node + (equal "comment" (treesit-node-type node)) + (save-excursion + (goto-char (treesit-node-start node)) + (forward-char 2) ; Skip the -- part. + (looking-at "\\[\\[")))) + (defvar lua-ts--syntax-table (let ((table (make-syntax-table))) (modify-syntax-entry ?+ "." table) diff --git a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts index ba7bad1b452..b0ece4cc261 100644 --- a/test/lisp/progmodes/lua-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/lua-ts-mode-resources/indent.erts @@ -360,6 +360,10 @@ multi-line ]] return true end + + --[[ +Long comment. + ]] =-= --[[ Multi-line @@ -373,6 +377,44 @@ multi-line ]] return true end + + --[[ +Long comment. + ]] +=-=-= + +Name: Comment Indent + +=-= +local fn1 = function (a, b) +-- comment +return a + b +end + +local tb1 = { + first = 1, +-- comment + second = 2, +} + +local tb9 = { one = 1, +-- comment + two = 2 } +=-= +local fn1 = function (a, b) + -- comment + return a + b +end + +local tb1 = { + first = 1, + -- comment + second = 2, +} + +local tb9 = { one = 1, + -- comment + two = 2 } =-=-= Name: Argument Indent -- 2.47.0 --=-=-= Content-Type: text/plain john muhl writes: > Tags: patch > > This improves nested comment indenting such that: > > local tbl = { > one = 1, > -- comment > two = 2, > } > > becomes: > > local tbl = { > one = 1, > -- comment > two = 2, > } --=-=-=--