From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60496: 29.0.60; c-ts-mode: Broken indentation with linux style conditionals Date: Sat, 07 Jan 2023 13:18:38 +0100 Message-ID: <87ilhitu5d.fsf@thornhill.no> References: <68A07E57-06EE-4F38-A2BC-A426B85BE56A@gmail.com> <1d37d77b75e3ede545e68c9521fcb171@sadiqpk.org> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33997"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , 60496@debbugs.gnu.org To: Mohammed Sadiq Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 07 13:19:23 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 1pE8AU-0008Yh-Ls for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 07 Jan 2023 13:19:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pE8AD-0004xY-Fo; Sat, 07 Jan 2023 07:19:05 -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 1pE8AB-0004xQ-Ed for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2023 07:19:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pE8AA-00088Y-OZ for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2023 07:19:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pE8AA-0006AI-5n for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2023 07:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Jan 2023 12:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60496 X-GNU-PR-Package: emacs Original-Received: via spool by 60496-submit@debbugs.gnu.org id=B60496.167309392423668 (code B ref 60496); Sat, 07 Jan 2023 12:19:02 +0000 Original-Received: (at 60496) by debbugs.gnu.org; 7 Jan 2023 12:18:44 +0000 Original-Received: from localhost ([127.0.0.1]:56649 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pE89s-00069f-5o for submit@debbugs.gnu.org; Sat, 07 Jan 2023 07:18:44 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:24204) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pE89p-00069U-Qm for 60496@debbugs.gnu.org; Sat, 07 Jan 2023 07:18:42 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1673093920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=No37CIdGg+jF0emiGDmwzmAWV4WHrnhks1luzB3AhX4=; b=N0pWBXpnE3MI1pR6t+t9qiFTPM9gQkzgkQqX2FBwInr9bKbVc5nvA08Nd9GLBIkNVtkkry V+Z9AfnLj7g/0Fqogh4Tua7LcY3ZAo4wM3GXu2zgYxWZVCth4z8ftGYfcnRn9NbJqZ541v nyqNY476k1b3tMv2PTGwYJy9TZY/7mDwma66t+S1L7sV1I62xPgj1XMSvIQRZrlF9kex73 F1XOcopusFwF+S3Ydg7+XJutBjm+PdiLXem4eUuK+rTlyhfu0UyZ5Tk+6O37nRnH3SilYV NUJ02Qhcqr7OXVlHbikXzlnnhSn3jS+kIXNRgHqiko49ch7QPHVvSz1SZOyRXQ== In-Reply-To: <1d37d77b75e3ede545e68c9521fcb171@sadiqpk.org> (Mohammed Sadiq's message of "Tue, 03 Jan 2023 14:39:52 +0530") X-Migadu-Flow: FLOW_OUT 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:252794 Archived-At: Mohammed Sadiq writes: > On 2023-01-03 03:59, Yuan Fu wrote: >> Mohammed Sadiq writes: >>=20 >>> Indentation of the following C code with linux style is broken: >>> int main (void) >>> { >>> if (a) { >>> func_a (); >>> } else if (b) { >>> func_b (); >>> } else { >>> func_c (); >>> } >>> } >>>=20 >> Thanks. I=E2=80=99m not familiar with the linux style, is the problem wi= th the >> closing brackets? Could you give me a correct example so I know exactly >> what=E2=80=99s wrong? >> Yuan > > > The expected indentation style for the given code (this one is provided > by c-mode), with the default indentation values: > > int > main (void) > { > if (a) { > func_a (); > } else if (b) { > func_b (); > } else { > func_c (); > } > } Yuan, this is a regression after the c-ts-mode--bracket-children-anchor. IIRC this was one of the cases that gave me headeaches. IIUC now the grand-parent cannot help because we could have infinite else ifs, right? And the c grammar nests these "alternative:" nodes deeper and deeper. Reverting to diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index dec866f762f..6c8c671550a 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -118,7 +118,7 @@ c-ts-mode--indent-styles `(((parent-is "translation_unit") parent-bol 0) ((node-is ")") parent 1) ((node-is "]") parent-bol 0) - ((node-is "}") c-ts-mode--bracket-children-anchor 0) + ((node-is "}") parent-bol 0) ((node-is "else") parent-bol 0) ((node-is "case") parent-bol 0) ((node-is "preproc_arg") no-indent) @@ -134,7 +134,7 @@ c-ts-mode--indent-styles ((match "preproc_function_def" "compound_statement") point-min = 0) ((match "preproc_call" "compound_statement") point-min 0) ((parent-is "compound_statement") - c-ts-mode--bracket-children-anchor c-ts-mode-indent-offset) + parent-bol c-ts-mode-indent-offset) ((parent-is "function_definition") parent-bol 0) ((parent-is "conditional_expression") first-sibling 0) ((parent-is "assignment_expression") parent-bol c-ts-mode-inden= t-offset) @@ -155,7 +155,7 @@ c-ts-mode--indent-styles '(((node-is "access_specifier") parent-bol 0))) ((parent-is "field_declaration_list") parent-bol c-ts-mode-inde= nt-offset) ((parent-is "initializer_list") parent-bol c-ts-mode-indent-off= set) - ((parent-is "if_statement") parent-bol c-ts-mode-indent-offset) + ((parent-is "if_statement") c-ts-mode--bracket-children-anchor = c-ts-mode-indent-offset) ((parent-is "for_statement") parent-bol c-ts-mode-indent-offset) ((parent-is "while_statement") parent-bol c-ts-mode-indent-offs= et) ((parent-is "switch_statement") parent-bol c-ts-mode-indent-off= set) Fixes this issue, but then we again have the problem with code such as: ``` int main (void) { for(; ;) { // wrong... } } ``` Theo