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: Fri, 24 Nov 2023 06:45:24 -0800 Message-ID: References: <834jhchqha.fsf@gnu.org> <08e16d44-174d-87e6-aa17-8cf55202227b@gutov.dev> <83wmu8fsj7.fsf@gnu.org> <8334wvfdna.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004b3434060ae70181" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36572"; mail-complaints-to="usenet@ciao.gmane.io" Cc: dmitry@gutov.dev, casouri@gmail.com, 67357@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 24 15:46:25 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 1r6XRm-0009Hd-U2 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Nov 2023 15:46:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6XRR-0005nL-RJ; Fri, 24 Nov 2023 09:46:01 -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 1r6XRO-0005mp-4T for bug-gnu-emacs@gnu.org; Fri, 24 Nov 2023 09:45:58 -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 1r6XRN-0001Ta-Qr for bug-gnu-emacs@gnu.org; Fri, 24 Nov 2023 09:45:57 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r6XRR-0006Rj-TB for bug-gnu-emacs@gnu.org; Fri, 24 Nov 2023 09:46:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noah Peart Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Nov 2023 14:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67357 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 67357-submit@debbugs.gnu.org id=B67357.170083715124760 (code B ref 67357); Fri, 24 Nov 2023 14:46:01 +0000 Original-Received: (at 67357) by debbugs.gnu.org; 24 Nov 2023 14:45:51 +0000 Original-Received: from localhost ([127.0.0.1]:36054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6XRG-0006RI-EL for submit@debbugs.gnu.org; Fri, 24 Nov 2023 09:45:50 -0500 Original-Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]:60856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6XRC-0006R3-04 for 67357@debbugs.gnu.org; Fri, 24 Nov 2023 09:45:48 -0500 Original-Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1f060e059a3so1169393fac.1 for <67357@debbugs.gnu.org>; Fri, 24 Nov 2023 06:45:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700837136; x=1701441936; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Qzqjpw6J7M6rgOl6tJ089dGw8kw2DR79CTp81R3FntU=; b=ZnQHnu/zx36owxdILpG3V4MB6zCR2ASTebctCssQmfapiJIqs1E6b9baMnFGX+swFA Fdx/SM70bOYGbQ2+4AtpQsMvRH8EYkznSAp7pbFH94ZCWEUo6YKUUbRXZpPKCZIfWy19 hb5X1zsd3tXvDKUAz/fg0jX9SQE88DypSBroyPQ5UgaF1+tk3Z4u6qj2ueWYrVWnwjPV 4kPOJ8Ehi4XuQHQdsCpJ0XLCJGeCZ0jJXDvjlHozeTWvZ5cGLDYBPxJvQYSkp/0d1gEP q3Ar0HU/I9S/3geQLICDzIuNp3AuSMZZ7jdI5Yp+nbDZ20Q1sq6sHFBe7Ssgfq13CM4d 4vGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700837136; x=1701441936; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Qzqjpw6J7M6rgOl6tJ089dGw8kw2DR79CTp81R3FntU=; b=r1shpSJfO+y5SBkfw3Fnp+Y+wLGiR7xCq4mmwJd7p7vrvdM7w0icpMpjIT3lnlu6ke 7owGi/SbLC9EbHUV+qxN9v1E3TO3lYiB52PBPglazBOlkQjs9xbyLZhW2BmByDMuKfcj 4sIyH2HXoJMnkXLFydLvUKxycgqxP8DIUNwAYiPG3RuSvLkVBvv/flQKf5ZofeBnGZiI fRc9Ud8/WSQUXQ0p80pmTJfbX9CmDDfn+ONaaZdgio98UcxJ3y3ngWk93qUYS8KxhuDA 210uoLuq3odav5wMBhQ1hP7wDL+NP/BAAqX2WYwQXqq3okbutcGNAlt70bZ+yUKEvJDV PLtg== X-Gm-Message-State: AOJu0YzblAGJDXu587IkoBJCzvvtGOEmwh81K8KiWfBcypDR/2iIsuXx /xeiEnZJfYf1yiryZ4viwQemOEQTCqNHV7aN790= X-Google-Smtp-Source: AGHT+IFZLN6Y2b3B782Ubamjoc/S2YhumVHKimEvzkn3SG0MKhx4FEqH9imdalFpP53tCCcGzRS9dlEDXcs7XmvaQ0Q= X-Received: by 2002:a05:6870:524b:b0:1a6:a547:ffe1 with SMTP id o11-20020a056870524b00b001a6a547ffe1mr3637257oai.21.1700837135691; Fri, 24 Nov 2023 06:45:35 -0800 (PST) In-Reply-To: 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:274866 Archived-At: --0000000000004b3434060ae70181 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I did notice an issue with testing solutions in `c-ts-mode-resources/indent.erts`. In cases where no indentation is applied (eg. comment is first-sibling) or there is no matching rule (eg. else_clause), the test case can still pass since the test cases are written with the proper indentation already. So, despit= e no indentation being applied, the result still matches the expected result. On Fri, Nov 24, 2023 at 6:35=E2=80=AFAM Noah Peart = wrote: > > I'm sorry I insist on a complete recipe with all the details > > Ok, lemme try again :) > > To reproduce the indentation bugs for unbracketed `else_clause`, and > do-while: > 1. open a buffer and insert the following: > > int main() { > if (true) > puts("Hello"); > else > puts("No matched rule!"); // 1 > do > puts("Hello"); > while (indented_as_part_of_block); // 2 > } > > 2. call `M-x example-setup` to configure `c-ts-mode` > 3. `M-x indent-region` to indent the whole buffer > You should see that the line with comment `1` has not been > indented, and the line with comment `2` has been indented to the > same level as the previous line. > > To reproduce the indentation bugs when comments are the first > siblings: > 1. open a buffer and insert: > > int main() { > while (true) { /* foo */ > if (true) { // 1 > puts ("Hello"); // 2 > } > } > } > > 2. call `M-x example-setup` to configure `c-ts-mode` > 3. `M-x indent-region` to indent the whole buffer > > You should see that the lines with comments `1` and `2` have > not been indented at all. > > On Fri, Nov 24, 2023 at 6:07=E2=80=AFAM Eli Zaretskii wrot= e: > >> > From: Noah Peart >> > Date: Fri, 24 Nov 2023 05:47:34 -0800 >> > Cc: Eli Zaretskii , casouri@gmail.com, >> 67357@debbugs.gnu.org >> > >> > Sorry for the confusion: to setup the `c-ts-mode` buffers to reproduce >> bugs, >> > run the following to configure `c-ts-mode` with `linux` style: >> > >> > (defun example-setup () >> > (interactive) >> > (c-ts-mode) >> > (setq-local indent-tabs-mode nil) >> > (setq-local c-ts-mode-indent-offset 2) >> > (c-ts-mode-set-style 'linux)) >> >> Thanks, but what to do after (or before?) the above, to actually >> reproduce the problem? >> >> I'm sorry I insist on a complete recipe with all the details, but IME >> without having such a recipe, it is all too easy to create >> misunderstandings about the problem, and harder to test solutions. >> > --0000000000004b3434060ae70181 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I did notice an issue with testing solutions in `c-ts-mode= -resources/indent.erts`.
In cases where no indentation is applied (eg. = comment is first-sibling) or there
is no matching rule (eg. else_= clause), the test case can still pass since=C2=A0
the test cases = are written with the proper indentation already.=C2=A0 So, despite
no indentation being applied, the result still=C2=A0matches the expected = result.

On Fri, Nov 24, 2023 at 6:35=E2=80=AFAM Noah Peart <noah.v.peart@gmail.com> wrote:
&= gt; I'm sorry I insist on a complete recipe with all the details
Ok, lemme try again :)

To reproduce t= he indentation bugs for unbracketed `else_clause`, and=C2=A0
do-w= hile:
1. open a buffer and insert the following:

=C2=A0 =C2=A0 int main() {
=C2=A0 =C2=A0 =C2=A0 if (true)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 puts("Hello");
=C2=A0 =C2=A0 =C2= =A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 puts("No matched rule!"); // 1
=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 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 while (indented_as_= part_of_block);=C2=A0 // 2
=C2=A0 =C2=A0 }

= 2. call `M-x example-setup` to configure `c-ts-mode`
3. `M-x inde= nt-region` to indent the whole buffer
You should see that the lin= e with comment `1` has not been
indented, and the line with comme= nt `2` has been indented to the=C2=A0
same level as the previous = line.

To reproduce the indentation bugs when comme= nts are the first
siblings:
1. open a buffer and insert= :

=C2=A0 =C2=A0 int main() {
=C2=A0 =C2=A0 =C2= =A0 while (true) { /* foo */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (true) { // 1
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 puts ("Hello"); // 2
=C2=A0 =C2=A0 =C2=A0 =C2=A0}=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 }

2. call `M-x example-setup` to configure `c-ts-mode`
3. `M-x i= ndent-region` to indent the whole buffer

You shoul= d see that the lines with comments `1` and `2` have
not bee= n indented at all.

On Fri, Nov 24, 2023 at 6:07=E2=80=AFAM Eli Zaretsk= ii <eliz@gnu.org&g= t; wrote:
> F= rom: Noah Peart <noah.v.peart@gmail.com>
> Date: Fri, 24 Nov 2023 05:47:34 -0800
> Cc: Eli Zaretskii <eliz@gnu.org>, casouri@gmail.com, 67357@debbugs.gnu.org
>
> Sorry for the confusion: to setup the `c-ts-mode` buffers to reproduce= bugs,
> run the following to configure `c-ts-mode` with `linux` style:
>
>=C2=A0 =C2=A0 =C2=A0(defun example-setup ()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(interactive)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(c-ts-mode)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(setq-local indent-tabs-mode nil)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(setq-local c-ts-mode-indent-offset 2)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(c-ts-mode-set-style 'linux))

Thanks, but what to do after (or before?) the above, to actually
reproduce the problem?

I'm sorry I insist on a complete recipe with all the details, but IME without having such a recipe, it is all too easy to create
misunderstandings about the problem, and harder to test solutions.
--0000000000004b3434060ae70181--