From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Noah Peart Newsgroups: gmane.emacs.bugs Subject: bug#67357: [PATCH] Fix c-ts-mode block indent when first-siblings are comments Date: Tue, 21 Nov 2023 17:50:52 -0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="000000000000ae57b1060ab3f31a" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22649"; mail-complaints-to="usenet@ciao.gmane.io" To: 67357@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 22 02:52:21 2023 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 1r5cPd-0005d7-Dr for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Nov 2023 02:52:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5cPL-0005Bm-4H; Tue, 21 Nov 2023 20:52: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 1r5cPH-0005BR-UY for bug-gnu-emacs@gnu.org; Tue, 21 Nov 2023 20:51:59 -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 1r5cPH-0008V5-MB for bug-gnu-emacs@gnu.org; Tue, 21 Nov 2023 20:51:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r5cPK-0006Nr-JY for bug-gnu-emacs@gnu.org; Tue, 21 Nov 2023 20:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noah Peart Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Nov 2023 01:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 67357 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170061787824470 (code B ref -1); Wed, 22 Nov 2023 01:52:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Nov 2023 01:51:18 +0000 Original-Received: from localhost ([127.0.0.1]:57769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5cOb-0006Mc-PD for submit@debbugs.gnu.org; Tue, 21 Nov 2023 20:51:18 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:51926) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5cOa-0006MQ-AF for submit@debbugs.gnu.org; Tue, 21 Nov 2023 20:51:17 -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 1r5cOS-00051W-0m for bug-gnu-emacs@gnu.org; Tue, 21 Nov 2023 20:51:08 -0500 Original-Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5cOQ-0008Rt-7Q for bug-gnu-emacs@gnu.org; Tue, 21 Nov 2023 20:51:07 -0500 Original-Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6d7e51638e7so712397a34.1 for ; Tue, 21 Nov 2023 17:51:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700617864; x=1701222664; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=O/6rere6puuXSNoChZqTp9EILX7SU6VnhHGyggSqYrI=; b=eAUpuZlgxrx2Xrbmf11cdHGbynuWAwrIf49CwxES5tlSvhJhQHetIJlaakYE688XwJ rED+J3EwDWm4LNC/bNhIsg/5NSCYs9MDtE7FUEsx1EhakE0WWV2JQNaYG+Ioaf7sET37 YgFefQWkNxgiL53zJRXLwCVIl0AmLtjOErH2AYk0AzM0UKkmqeQnGO78zsihal2SA7nS OmySeGEYvp66fkWU2Jxzn039Q2tfCYTd2MmtBOFLyq0kbsAI+qIl88Dmx72TWMGxMTrA a5zrNwYfCfixo4DxYl5PEu3w/uRJt2xC/ynfVRBbIXMQSB3mArM7uH1qjSvar+C0ka7e UZMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700617864; x=1701222664; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=O/6rere6puuXSNoChZqTp9EILX7SU6VnhHGyggSqYrI=; b=Rbg9RokncO/caDxn1IrszV0GLeaUE1KojK7v2xJc9CtlwG/nJY0AtNH0cD5P7QQ7jv 6LSiN2b6wqUY7I0f8wYxeAoLoazaj4SWS505HOLpR3cprYXQVhv1Yx8UjjFuSdqJ4rtX VEaUPzvHXd1eE9oA13FBwBPVropaWHAYe38nvtf8dL00GEKWbG05mJkAXQWgHf5vnk47 +nnHiCAEZUjGmkGT2kA0McJI61PM3QygxwXQkq/q146mLNxyCOBi1A1AxcIZUMpK3sbk +GSuQ2SI4f2dwApVtuMrf+VozG6tp4Q71W9aIuYVsAbGjMR9krxpSdzh/3V3AYyxjmPl OMBQ== X-Gm-Message-State: AOJu0YxGvl3UyUl334nWsgVO+kRrg27GLhpw8gagUuPkRwlji/9q8kn9 h+a5lBZpwPUfs/yOzEYBGJceiWnfCcE4SHvJioq8gfy5kixalRe9qf4= X-Google-Smtp-Source: AGHT+IGvleYWSNCaV0yKsDGieLQZmW7VVMso8ihOo/mVrawqjEaxs5tafLhMWiRV2GDYa4TcVR/m6e0tkYY7IiQU828= X-Received: by 2002:a05:6871:e40c:b0:1e9:d8a4:5523 with SMTP id py12-20020a056871e40c00b001e9d8a45523mr1423963oac.41.1700617863969; Tue, 21 Nov 2023 17:51:03 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::336; envelope-from=noah.v.peart@gmail.com; helo=mail-ot1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:274748 Archived-At: --000000000000ae57b1060ab3f31a Content-Type: multipart/alternative; boundary="000000000000ae57b0060ab3f318" --000000000000ae57b0060ab3f318 Content-Type: text/plain; charset="UTF-8" Tags: patch I wasn't sure if these should be two separate bugs, so I separated them just in case. * lisp/progmodes/c-ts-mode.el(c-ts-mode--indent-styles): Fix indentation in block statements for cases when the first-sibling(s) are comments or nested keywords (else_clause/do while). Bug: The first statement in a compound statement that is preceded by a comment (or multiple comments) isn't indented. For example, the `if` statement isnt indented in the following code in `c-ts-mode` using `linux` style. int main() { while (true) { /* foo */ if (true) { // this line isnt indented puts ("Hello"); // and this isnt either } } } * lisp/progmodes/c-ts-mode.el(c-ts-mode--indent-styles): Fix indentation for else_clause and do-while in bracket-less block statements using `linux` style. Bug: There is no matching indent rule for bracket-less else_clause statements and the "while" in a bracket-less do-while statement is indented to the same level as the do body. To reproduce, using `linux` style in `c-ts-mode`. int main() { if (true) puts("Hello"); else puts("No matched rule!"); do puts("Hello"); while (indented_as_part_of_block); } In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0) of 2023-11-18 built on noah-X580VD Repository revision: 47b497b4dac91e5ea56102018223bdeb5e21a93b Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101004 System Description: Ubuntu 22.04.3 LTS Configured using: 'configure --prefix=/usr/local --with-modules --with-tree-sitter --with-threads --with-x-toolkit=gtk3 --with-xwidgets --with-gnutls --with-json --with-mailutils --with-jpeg --with-png --with-rsvg --with-tiff --with-xml2 --with-xpm --with-imagemagick CC=gcc-12 CXX=gcc-12' --000000000000ae57b0060ab3f318 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Tags: patch

I wasn't sure if these should be tw= o separate bugs, so I separated them just=C2=A0
in case.

* lisp/= progmodes/c-ts-mode.el(c-ts-mode--indent-styles): Fix indentation
in blo= ck statements for cases when the first-sibling(s) are comments or
nested= keywords (else_clause/do while).

Bug: The first statement in a comp= ound statement that is preceded by a
comment (or multiple comments) isn&= #39;t indented.

For example, the `if` statement isnt indented in the= following code in
`c-ts-mode` using `linux` style.

=C2=A0 =C2=A0= int main() {
=C2=A0 =C2=A0 =C2=A0 while (true) { /* foo */
=C2=A0 = =C2=A0 =C2=A0if (true) { // this line isnt indented
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 puts ("Hello"); // and this isnt either
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 }

= * lisp/progmodes/c-ts-mode.el(c-ts-mode--indent-styles): Fix indentationfor else_clause and do-while in bracket-less block statements using
`li= nux` style.

Bug: There is no matching indent rule for bracket-less e= lse_clause
statements and the "while" in a bracket-less do-whi= le statement is
indented to the same level as the do body.

To rep= roduce, using `linux` style in `c-ts-mode`.

=C2=A0 =C2=A0 int main()= {
=C2=A0 =C2=A0 =C2=A0 if (true)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 puts(&= quot;Hello");
=C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 pu= ts("No matched rule!");
=C2=A0 =C2=A0 =C2=A0 do
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 puts("Hello");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 w= hile (indented_as_part_of_block);
=C2=A0 =C2=A0 }


In GNU Emac= s 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo ver= sion 1.16.0) of 2023-11-18 built on noah-X580VD
Repository revision: 47b= 497b4dac91e5ea56102018223bdeb5e21a93b
Repository branch: master
Windo= wing system distributor 'The X.Org Foundation', version 11.0.121010= 04
System Description: Ubuntu 22.04.3 LTS

Configured using:
= =C2=A0'configure --prefix=3D/usr/local --with-modules --with-tree-sitte= r
--with-threads --with-x-toolkit=3Dgtk3 --with-xwidgets --with-gnutls--with-json --with-mailutils --with-jpeg --with-png --with-rsvg
--with= -tiff --with-xml2 --with-xpm --with-imagemagick CC=3Dgcc-12
CXX=3Dgcc-12= '
--000000000000ae57b0060ab3f318-- --000000000000ae57b1060ab3f31a Content-Type: text/x-patch; charset="US-ASCII"; name="c-ts-mode-first-sib-comments.patch" Content-Disposition: attachment; filename="c-ts-mode-first-sib-comments.patch" Content-Transfer-Enc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AKK05hbWU6IEJsb2NrLVN0YXRlbWVudCB3 aGVyZSBmaXJzdCBzaWJsaW5ncyBhcmUgY29tbWVudHMgKExpbnV4IFN0eWxlKQorCis9LT0KK2lu dCBtYWluKCkgeworICB3aGlsZSAodHJ1ZSkgeyAvKiBmb28gKi8KKyAgICBpZiAodHJ1ZSkgeyAv LyBiYXIKKyAgICAgIHB1dHMgKCJIZWxsbyIpOworICAgIH0KKyAgfQorICBmb3IgKDs7KSB7ICAv LyAxLiBmb29vCisgICAgLyogMi4gYmFhYSAqLworICAgIC8qIDMuIHJyciAqLworICAgIGlmICh0 cnVlKQorICAgICAgLy8gMi4gYmFhYQorICAgICAgcHV0cyAoIkhlbGxvIik7CisgIH0KKyAgaWYg KDEpIHsgLy8gMQorICAgIC8qCisgICAgICogMgorICAgICAqLworICAgIGlmICgxKSAvKjMqLyB7 CisgICAgICAvKiA0ICovCisgICAgICBwdXRzKCJIZWxsbyIpOworICAgIH0KKyAgfQorfQorPS09 LT0KKwogTmFtZTogSW5pdGlhbGl6ZXIgTGlzdCAoTGludXggU3R5bGUpIChCdWcjNjEzOTgpCiAK ID0tPQotLSAKMi4zNC4xCgo= --000000000000ae57b1060ab3f31a--