From unknown Sun Jun 22 20:56:52 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found Resent-From: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik Original-Sender: "Debbugs-submit" Resent-CC: theo@thornhill.no, casouri@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Sun, 06 Oct 2024 16:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73661 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 73661@debbugs.gnu.org Cc: theo@thornhill.no,casouri@gmail.com X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: theo@thornhill.no,casouri@gmail.com Received: via spool by submit@debbugs.gnu.org id=B.17282307115678 (code B ref -1); Sun, 06 Oct 2024 16:06:02 +0000 Received: (at submit) by debbugs.gnu.org; 6 Oct 2024 16:05:11 +0000 Received: from localhost ([127.0.0.1]:42029 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxTkp-0001Qg-H3 for submit@debbugs.gnu.org; Sun, 06 Oct 2024 12:05:11 -0400 Received: from lists.gnu.org ([209.51.188.17]:36296) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxRZm-0001yu-Ng for submit@debbugs.gnu.org; Sun, 06 Oct 2024 09:45:35 -0400 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 1sxRZg-0007IW-G1 for bug-gnu-emacs@gnu.org; Sun, 06 Oct 2024 09:45:28 -0400 Received: from mx.kolabnow.com ([212.103.80.155]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxRZe-0006Dd-8v for bug-gnu-emacs@gnu.org; Sun, 06 Oct 2024 09:45:28 -0400 Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 5C7833507C10 for ; Sun, 6 Oct 2024 15:45:13 +0200 (CEST) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-type:content-type:mime-version:message-id:date:date :subject:subject:from:from:received:received:received; s= dkim20240523; t=1728222312; x=1730036713; bh=G7bB9JI+eM/59pmRDsm H2GdLFjDiYyQDdLIRiJENz6U=; b=JvW9FQkIkxAW2kf9FbwJxNGCHUWiGTGdU5p QXtz2bsWeaZytCR0keiLawU2moInPXKmUFGR1vR+9ir8tIZ7HXUeuO87Uii5jJot Lol+HkmcgjNUf/rA65ZDQ7QgBu7Qulq9qCYt/0Uv/YBptcvr1MtYGxVll/9RRUtT 5U/vR0q270qfA+F5LzOreFgwwjigZiFKNU7j1NjKGACa95VzWchdwqm8Nob7Hdvt TrU9P6d0Pibi+5RWGPxRY8Ae2QGbD5pz6Oto0uSks+W8cgmJDa6leKJmRVu4Ln9B iLvrOMmlXV8hMjdG2c55sEk6vkkuuAxmwVyfZGZG2Edt5qd9Ymg== X-Virus-Scanned: amavis at mykolab.com X-Spam-Flag: NO X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-1 tagged_above=-10 required=5 tests=[ALL_TRUSTED=-1] autolearn=ham autolearn_force=no Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out011.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id V0ZQgO51btPv for ; Sun, 6 Oct 2024 15:45:12 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 367FC3507C0F for ; Sun, 6 Oct 2024 15:45:11 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 74E2D20AA57A for ; Sun, 6 Oct 2024 15:45:11 +0200 (CEST) From: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik Date: Sun, 06 Oct 2024 15:44:55 +0200 Message-ID: <87y131wdk8.fsf@lambda.is> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=212.103.80.155; envelope-from=j@lambda.is; helo=mx.kolabnow.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Mailman-Approved-At: Sun, 06 Oct 2024 12:05:07 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch Indenting would give up when initializer lists and similar constructs were broken up over multiple lines where the first item was not also beginning-of-line. Items should anchor on the first sibling (like with function calls and init-lists in general). The search for a sibling to anchor on should stop at the first sibling at bol or the first sibling in the (sub)tree. This brings indent up to c-mode parity for code like: return { x1, x2, ..., y1, x2, ... }; In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu) of 2024-10-06 built on ada Repository revision: c8e5f2ee9f6155ef545c2fe8ddf702c4f16a6eea Repository branch: master System Description: Debian GNU/Linux 12 (bookworm) Configured using: 'configure --with-x-toolkit=no --with-xpm=ifavailable --with-jpeg=ifavailable --with-png=ifavailable --with-gif=ifavailable --with-tiff=ifavailable --with-gnutls=ifavailable --with-tree-sitter --with-native-compilation --prefix=/home/j/src/emacs/build/root' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Anchor-to-first-sibling-unless-bol-sibling-found.patch >From 0bf96b008b57298ffcc63b9bb8222358ce966c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 4 Oct 2024 21:38:33 +0200 Subject: [PATCH] Anchor to first sibling unless bol-sibling found The behavior differed between c-mode/c++-mode and *-ts-mode for initializer lists where the first element was not at beginning-of-line. The anchor-prev-sibling function gave up and returned nil, but it should (probably) anchor on the first element in the initializer list, such as this: return { v1, v2, ..., y1, y2, ... }; c-ts-mode behaved better and figured out how to align, but I added a test for a similar compound literal to prevent regressions. * lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): Anchor at first sibling unless bol is found. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New initializer list and compound literal test. --- lisp/progmodes/c-ts-mode.el | 9 +++-- .../progmodes/c-ts-mode-resources/indent.erts | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 303c994637c..3f6a7422aa0 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -338,10 +338,13 @@ c-ts-mode--anchor-prev-sibling ;; If the start of the previous sibling isn't at the ;; beginning of a line, something's probably not quite ;; right, go a step further. (E.g., comment after a - ;; statement.) + ;; statement.) If the previous sibling is the first named + ;; node then anchor to that, e.g. when returning an aggregate + ;; and starting the items on the same line as {. (_ (goto-char (treesit-node-start prev-sibling)) - (if (looking-back (rx bol (* whitespace)) - (line-beginning-position)) + (if (or (looking-back (rx bol (* whitespace)) + (line-beginning-position))) + (null (treesit-node-prev-sibling prev-sibling t)) (setq continue nil) (setq prev-sibling (treesit-node-prev-sibling prev-sibling))))))) diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index 599173832b5..a13a74cf8b3 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts @@ -208,6 +208,21 @@ int main() } =-=-= +Name: Return Compund Literal + +=-= +struct pair { int fst, snd; }; +struct pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return (struct pair) { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} + +=-=-= + Name: Switch-Case statement =-= @@ -486,6 +501,30 @@ namespace A { } =-=-= +Name: Return Aggregate Initialized Struct + +=-= +struct pair { int x, y; } +pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} +=-= +struct pair { int x, y; } +pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} +=-=-= + Code: (lambda () (c-ts-mode) -- 2.39.5 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 06 12:24:50 2024 Received: (at control) by debbugs.gnu.org; 6 Oct 2024 16:24:50 +0000 Received: from localhost ([127.0.0.1]:42112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxU3t-0002WE-NN for submit@debbugs.gnu.org; Sun, 06 Oct 2024 12:24:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41454) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxU3s-0002Vt-6q; Sun, 06 Oct 2024 12:24:48 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxU3f-0005us-NX; Sun, 06 Oct 2024 12:24:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=RSOtJLDXCN+eyhsYqL+cwfZOUfzbFWZUQMOmDdH1nFI=; b=DmM7R6rCtq40j+hpM4BY zmqBcB1Zk/jsGb1byANuTiO9tXz7O0X6fjz+2zZPIP8FWxffRWIM7DXQMJNrKxuCvJ24UDmW6zGoe 3iNgyDJk913a7YXKX5ltT0ukHXUNz+mdiKCNFy8RBtVB/3ENotlN+lqFqHD7xj1Na/mUo70J/Eej2 ftidXUjMp5XL6aLLe7/ZpKL2vJyJi18/mxumUZP1+ZsAqnpM2/dywAxApQxj2478js0gcrg/OCJ4r HsG3WJaMiQivOk7pKcd4l6mTarvYB4dMGpVF9TCZ11qaeEzICzT0twcEwVDZry+ZiHfDaEQpyzycX JPPaKYki2e3Ltg==; Date: Sun, 06 Oct 2024 19:24:31 +0300 Message-Id: <86zfnhtd1c.fsf@gnu.org> From: Eli Zaretskii To: =?utf-8?Q?J=C3=B8rgen?= Kvalsvik In-Reply-To: <87iku5qqf3.fsf@lambda.is> (message from =?utf-8?Q?J=C3=B8rge?= =?utf-8?Q?n?= Kvalsvik on Sun, 06 Oct 2024 16:03:44 +0200) Subject: Re: bug#73662: [PATCH] Anchor to first sibling unless bol-sibling found References: <87iku5qqf3.fsf@lambda.is> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control Cc: casouri@gmail.com, 73662@debbugs.gnu.org, theo@thornhill.no X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) merge 73662 73661 thanks > Cc: theo@thornhill.no,casouri@gmail.com > From: Jørgen Kvalsvik > Date: Sun, 06 Oct 2024 16:03:44 +0200 > > Indenting would give up when initializer lists and similar constructs > were broken up over multiple lines where the first item was not also > beginning-of-line. Items should anchor on the first sibling (like with > function calls and init-lists in general). The search for a sibling to > anchor on should stop at the first sibling at bol or the first sibling > in the (sub)tree. > > This brings indent up to c-mode parity for code like: > > return { x1, x2, ..., > y1, x2, ... }; This is an exact duplicate of bug 73661, which you submitted just a few minutes ago. So I'm merging them. From unknown Sun Jun 22 20:56:52 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Oct 2024 00:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73661 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik Cc: 73661@debbugs.gnu.org, Eli Zaretskii , Theodor Thornhill Received: via spool by 73661-submit@debbugs.gnu.org id=B73661.172834642523703 (code B ref 73661); Tue, 08 Oct 2024 00:14:01 +0000 Received: (at 73661) by debbugs.gnu.org; 8 Oct 2024 00:13:45 +0000 Received: from localhost ([127.0.0.1]:49516 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxxrE-0006AF-U0 for submit@debbugs.gnu.org; Mon, 07 Oct 2024 20:13:45 -0400 Received: from mail-pl1-f171.google.com ([209.85.214.171]:51227) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxxrD-0006A6-0K for 73661@debbugs.gnu.org; Mon, 07 Oct 2024 20:13:43 -0400 Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20b58f2e1f4so33633465ad.2 for <73661@debbugs.gnu.org>; Mon, 07 Oct 2024 17:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728346354; x=1728951154; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DkgrBfV3QDFVOmYYPKt++P2McGK/O+cpoha+NaUCltM=; b=fB2Cb2FVxBO1/ASs8XMP2IgHbC6GPS4wXq09fT58l+9XTcY/+W8xY4R1wWhFpiBHRk zaKaM3kQ2Lr7kTRFokOnrtHf9HAP8mQTlQjPIJbKOMOjJdxan/Jf0hhlPllj8yRsNwqY CSPYUgQ2PDjzg7JZ31EonC8ebYfDjGfyTmtOqYGZjtyqLJpjcWgL5eYqeBGY+33D5XCX vuGOROJkmG9MA1M+ATIlJ27HckfSR6oa5Ur1XhVFnjGVFV+uXFcMapSRKzYgqhRhP6H9 GVMfYekBMBvQxXRPs+9LigUV/xtwNgoMjeqbOS9Oi09hy18GMF7DXh0o6WEO2486m0I+ BXdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728346354; x=1728951154; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DkgrBfV3QDFVOmYYPKt++P2McGK/O+cpoha+NaUCltM=; b=GYXZu3Aop+ceXBqA13kvtEBztIhWPjmriUkyYxzQZ2qWvumcaL86rQQcpf919yp/cU 6XGL64HpSMhqTwrhP/7RQLdWFNB3KijYgbU0vehzPxC+fwX1rKf5HHVJNZnUk5BWJJnH b51hESUoMnUdD9JDdK6MBMFj65ykzt7Z2/KzQGnPkQPSXcEqLYcRjdtJI8O7yFBLis/n JIn5f/bTykTZ3NWk4K8WcMHz0kWkMVFqMmJVHMhaACq1gxUByPreMNgG1VfdotaAIjiy q8oIYn+9AQ0o6sPk7WpIMTyX3Lra8w7IsDBvUoal5oE/vuA/sDT5yJs9AlTdqBm6fYvg ousw== X-Gm-Message-State: AOJu0Ywj4YbPsKtZhWX2yKHt5JWL/byLvCfNbx+GCZ7vNHLIbODM2BUr GNGs5yspQKyu0Zx5JiCWgU7KgLRbjzjgWf7gN3lhBLHbrJuSWGHG X-Google-Smtp-Source: AGHT+IG4gBPox+HQaZx7A6vw/5qX2Sh/GzZl3juw62rNbJrS+Vw8bE4wIJMxs3DRc5SMiBJNGU5jgA== X-Received: by 2002:a17:902:cec6:b0:20b:61ec:7d3c with SMTP id d9443c01a7336-20bff1c6365mr221965235ad.49.1728346354165; Mon, 07 Oct 2024 17:12:34 -0700 (PDT) Received: from smtpclient.apple ([2601:646:8f81:6120:a0ef:b832:57b2:425a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c13969477sm45084705ad.194.2024.10.07.17.12.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2024 17:12:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) From: Yuan Fu In-Reply-To: <87y131wdk8.fsf@lambda.is> Date: Mon, 7 Oct 2024 17:12:22 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <87y131wdk8.fsf@lambda.is> X-Mailer: Apple Mail (2.3776.700.51) X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Oct 6, 2024, at 6:44=E2=80=AFAM, J=C3=B8rgen Kvalsvik = wrote: >=20 > Tags: patch >=20 >=20 > Indenting would give up when initializer lists and similar constructs > were broken up over multiple lines where the first item was not also > beginning-of-line. Items should anchor on the first sibling (like = with > function calls and init-lists in general). The search for a sibling to > anchor on should stop at the first sibling at bol or the first sibling > in the (sub)tree. >=20 > This brings indent up to c-mode parity for code like: >=20 > return { x1, x2, ..., > y1, x2, ... }; Awesome! Thanks for the patch. Have you signed the copyright assignment? = Eli, does this count as a significant contribution that requires the = copyright assignment? Yuan= From unknown Sun Jun 22 20:56:52 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found Resent-From: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Oct 2024 07:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73661 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Yuan Fu Cc: 73661@debbugs.gnu.org, Eli Zaretskii , Theodor Thornhill Received: via spool by 73661-submit@debbugs.gnu.org id=B73661.172837111612016 (code B ref 73661); Tue, 08 Oct 2024 07:06:01 +0000 Received: (at 73661) by debbugs.gnu.org; 8 Oct 2024 07:05:16 +0000 Received: from localhost ([127.0.0.1]:50537 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sy4HT-00037f-8v for submit@debbugs.gnu.org; Tue, 08 Oct 2024 03:05:16 -0400 Received: from mx.kolabnow.com ([212.103.80.154]:49460) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sy3XD-0000ar-CX for 73661@debbugs.gnu.org; Tue, 08 Oct 2024 02:17:28 -0400 Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 1BEBB354BF0; Tue, 8 Oct 2024 08:17:13 +0200 (CEST) Authentication-Results: ext-mx-out013.mykolab.com (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject :mime-version:date:date:message-id:received:received:received; s=dkim20240523; t=1728368232; x=1730182633; bh=t55tyGWzimDA3BuS nyRhvqXnxfgnnrvRXxU4ENokO94=; b=CAh6aeS+41sgnbKA0S2K7jj4w+EVcJLY +qrXSKY9ho/Hs4GA0VpuSvgfpLnDEcQ61peWN+DRixjSrLhgsZ4F633KonQVBAAv 38rxb0qZIAhfCfne1UhIlyUx+NF6ZW36i2nxq2Fugwk5Gj0M1Q7zisxpwQJUMuz4 tLAJTvCAwBoBxHFrhAWksSHU6ynwa0GtoRaki2E+5smmWoQyrJMf/6i6brJtQtnD F8jVXp0IFFqjsVnvWnaKvVfhRyL3LmF/5DdCHiTDj/wui5vag3xa0zziUE+ZPWoQ o/lBOlkwu59GGj21bW+ei09VXZCCncuf1ah6xVwMBMP3fsg52xA2fQ== X-Virus-Scanned: amavis at mykolab.com X-Spam-Flag: NO X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-1 tagged_above=-10 required=5 tests=[ALL_TRUSTED=-1] autolearn=ham autolearn_force=no Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out013.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id LSTZuElezKjz; Tue, 8 Oct 2024 08:17:12 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 0964B354BE4; Tue, 8 Oct 2024 08:17:11 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 88A2D20958D1; Tue, 8 Oct 2024 08:17:11 +0200 (CEST) Message-ID: <39fb6d1e-4c91-4c6b-a7c1-877a1cc245c6@lambda.is> Date: Tue, 8 Oct 2024 08:17:10 +0200 MIME-Version: 1.0 References: <87y131wdk8.fsf@lambda.is> Content-Language: en-US From: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Mailman-Approved-At: Tue, 08 Oct 2024 03:05:13 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 10/8/24 02:12, Yuan Fu wrote: > > >> On Oct 6, 2024, at 6:44 AM, Jørgen Kvalsvik wrote: >> >> Tags: patch >> >> >> Indenting would give up when initializer lists and similar constructs >> were broken up over multiple lines where the first item was not also >> beginning-of-line. Items should anchor on the first sibling (like with >> function calls and init-lists in general). The search for a sibling to >> anchor on should stop at the first sibling at bol or the first sibling >> in the (sub)tree. >> >> This brings indent up to c-mode parity for code like: >> >> return { x1, x2, ..., >> y1, x2, ... }; > > Awesome! Thanks for the patch. Have you signed the copyright assignment? Eli, does this count as a significant contribution that requires the copyright assignment? > > Yuan I have requested the paperwork, but not signed yet. From unknown Sun Jun 22 20:56:52 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Oct 2024 12:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73661 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Yuan Fu Cc: 73661@debbugs.gnu.org, theo@thornhill.no, j@lambda.is Received: via spool by 73661-submit@debbugs.gnu.org id=B73661.17283888427804 (code B ref 73661); Tue, 08 Oct 2024 12:01:01 +0000 Received: (at 73661) by debbugs.gnu.org; 8 Oct 2024 12:00:42 +0000 Received: from localhost ([127.0.0.1]:51431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sy8tO-00021o-EB for submit@debbugs.gnu.org; Tue, 08 Oct 2024 08:00:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53178) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sy8tM-00021Z-JM for 73661@debbugs.gnu.org; Tue, 08 Oct 2024 08:00:41 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy8t5-00038B-Cm; Tue, 08 Oct 2024 08:00:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=7Zf1ZwCJVuVntJ42QEkQ172u3GR6xjqyWxayK5GdMfs=; b=pjeGHPiZ/FYE vfc0w60R8KOfJcu2ksbwmi1WAmCmOmb6FZ6SJK/3tdTEJJbuXaEfURxMxxQuTspAzFS3aVwD647P+ ing+gmm8Wp6z38Fr7CQ6mjimkiagzX44UQ+oK9zdz1sxinanXeVl/0YTnZjb6tJC0LcT8vkjytDQt Wq2EPQMoHLYb50FgyScy7d68MQjv/kgIPs/gk83DzgaLWLCSGFdwJt+x+eJpgM1POSAVqPfRIMj/2 jwybWGW/OyrVF3wuKrFLmmFeVCy3HpqhPwJkCZyVc7rwiIiOqD1AvjTwsN/kx2CzYuEn6qAVTpPvO KMug0tzGs9P42xBcwUXdXA==; Date: Tue, 08 Oct 2024 14:59:59 +0300 Message-Id: <86v7y2st34.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Yuan Fu on Mon, 7 Oct 2024 17:12:22 -0700) References: <87y131wdk8.fsf@lambda.is> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Yuan Fu > Date: Mon, 7 Oct 2024 17:12:22 -0700 > Cc: 73661@debbugs.gnu.org, > Theodor Thornhill , > Eli Zaretskii > > Awesome! Thanks for the patch. Have you signed the copyright assignment? Eli, does this count as a significant contribution that requires the copyright assignment? This is small enough to accept without paperwork. From unknown Sun Jun 22 20:56:52 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik Subject: bug#73661: closed (Re: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found) Message-ID: References: <65500369-261B-4FC9-805B-94F77EC4A21F@gmail.com> <87y131wdk8.fsf@lambda.is> X-Gnu-PR-Message: they-closed 73661 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 73661@debbugs.gnu.org Date: Thu, 10 Oct 2024 07:08:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1728544082-27235-1" This is a multi-part message in MIME format... ------------=_1728544082-27235-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #73661: [PATCH] Anchor to first sibling unless bol-sibling found which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 73661@debbugs.gnu.org. --=20 73661: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D73661 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1728544082-27235-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 73661-done) by debbugs.gnu.org; 10 Oct 2024 07:07:59 +0000 Received: from localhost ([127.0.0.1]:58509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1synHC-000752-DP for submit@debbugs.gnu.org; Thu, 10 Oct 2024 03:07:58 -0400 Received: from mail-pj1-f47.google.com ([209.85.216.47]:43159) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1synH8-00074l-90 for 73661-done@debbugs.gnu.org; Thu, 10 Oct 2024 03:07:56 -0400 Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2e2e050b1c3so50182a91.0 for <73661-done@debbugs.gnu.org>; Thu, 10 Oct 2024 00:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728543997; x=1729148797; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HE/T5T20j/mwGRKKYVAKkW/2+HtIdPVZcJ9cW1GLB9Y=; b=RpG6R1GOpaGzXI/cDHP8jnze3Ij9fC6NAZA2kCk0HLdDsuqrha9ctl+BfhTsvMMvR4 GWhQAzJTZnQsWvqd3Ps6B00lcX45OLEoqJNaxvTKn5s0Fkcma++tX6TRs/aZW1bduf5N cAvI/3CXOaQ39iaKDI8/PGdY+5vlv8iIReNmD94imRTesSFj3ZHIQFAdhUSymflNEdlt Apobbwv42llLNqZzBuaKRob2IujDv2BWZ4VEdNwGzbHrmBA0KKBeDKI3/lmcyfUPEeYo tNpwIANZtg5KNS8ORXF1xOZxysSHUMNk+sCppxYT+XTHCKvWO5JWGNJlabhrV4gmwJvo X2KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728543997; x=1729148797; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HE/T5T20j/mwGRKKYVAKkW/2+HtIdPVZcJ9cW1GLB9Y=; b=lkc9f5H5ayDJ9SLbgr0gcx1FevIRa2yu/B1KoyvGVU7HKfHj1hLTt5vucjy65mFLR1 iotxAAlEwdpSmg0iKLk0WQHIguKVdm1JVyKpudWMrRrWwM0qHvZm7XNQ7LV0WIYG+QbH zJ4KcTsUbXlD1LT7CXKo9jdLeLYE808DfI/etQx3re2/PtR5qDZ6erXd7SpaodQU/AkT fB4lilV9Jfp3Vh48RSZurTG9OxkMvF7/sAfStkAYNx51G4UHLB7hd7IFGJevgWF3jGGo UvZXZJyJNmsHgfIAEGgHWFXfJdl3Uu42bUZSaANU1wUe+wNOzBUsbsb+g9lbL6iDdmZe CpQg== X-Forwarded-Encrypted: i=1; AJvYcCUSANTZGKaRRIUGiiBbBy+DUVbKpdkKERjyZD6NP7sxcg1i5PPdx5EImth+c3X8cBj1YYyYNlF1oigs@debbugs.gnu.org X-Gm-Message-State: AOJu0Yx967ga+1gkSaLwoWyrwV6sZWAx1aqdh0XgjP3HvXKCPjciuQyR SrVgrqv3k1Ga4i448umKKu313noICiBvsag16B9apCsoE/N999QR X-Google-Smtp-Source: AGHT+IHlbgEpn7locogkHJGenekGgrA8KrbnRea5W7/go6hwBoOe48dFDrE2ncW1x5D9AfUXELRfZQ== X-Received: by 2002:a17:90a:8a8d:b0:2e2:bdaa:baad with SMTP id 98e67ed59e1d1-2e2c804262bmr3441682a91.7.1728543997277; Thu, 10 Oct 2024 00:06:37 -0700 (PDT) Received: from smtpclient.apple ([2601:646:8f81:6120:f11e:b651:2f41:7105]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2d5fcc759sm564521a91.57.2024.10.10.00.06.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Oct 2024 00:06:36 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found From: Yuan Fu In-Reply-To: <86v7y2st34.fsf@gnu.org> Date: Thu, 10 Oct 2024 00:06:25 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <65500369-261B-4FC9-805B-94F77EC4A21F@gmail.com> References: <87y131wdk8.fsf@lambda.is> <86v7y2st34.fsf@gnu.org> To: Eli Zaretskii X-Mailer: Apple Mail (2.3776.700.51) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 73661-done Cc: 73661-done@debbugs.gnu.org, Theodor Thornhill , =?utf-8?Q?J=C3=B8rgen_Kvalsvik?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Oct 8, 2024, at 4:59=E2=80=AFAM, Eli Zaretskii = wrote: >=20 >> From: Yuan Fu >> Date: Mon, 7 Oct 2024 17:12:22 -0700 >> Cc: 73661@debbugs.gnu.org, >> Theodor Thornhill , >> Eli Zaretskii >>=20 >> Awesome! Thanks for the patch. Have you signed the copyright = assignment? Eli, does this count as a significant contribution that = requires the copyright assignment? >=20 > This is small enough to accept without paperwork. Merged. Thanks! Yuan= ------------=_1728544082-27235-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 6 Oct 2024 16:05:11 +0000 Received: from localhost ([127.0.0.1]:42029 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxTkp-0001Qg-H3 for submit@debbugs.gnu.org; Sun, 06 Oct 2024 12:05:11 -0400 Received: from lists.gnu.org ([209.51.188.17]:36296) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxRZm-0001yu-Ng for submit@debbugs.gnu.org; Sun, 06 Oct 2024 09:45:35 -0400 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 1sxRZg-0007IW-G1 for bug-gnu-emacs@gnu.org; Sun, 06 Oct 2024 09:45:28 -0400 Received: from mx.kolabnow.com ([212.103.80.155]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxRZe-0006Dd-8v for bug-gnu-emacs@gnu.org; Sun, 06 Oct 2024 09:45:28 -0400 Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 5C7833507C10 for ; Sun, 6 Oct 2024 15:45:13 +0200 (CEST) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-type:content-type:mime-version:message-id:date:date :subject:subject:from:from:received:received:received; s= dkim20240523; t=1728222312; x=1730036713; bh=G7bB9JI+eM/59pmRDsm H2GdLFjDiYyQDdLIRiJENz6U=; b=JvW9FQkIkxAW2kf9FbwJxNGCHUWiGTGdU5p QXtz2bsWeaZytCR0keiLawU2moInPXKmUFGR1vR+9ir8tIZ7HXUeuO87Uii5jJot Lol+HkmcgjNUf/rA65ZDQ7QgBu7Qulq9qCYt/0Uv/YBptcvr1MtYGxVll/9RRUtT 5U/vR0q270qfA+F5LzOreFgwwjigZiFKNU7j1NjKGACa95VzWchdwqm8Nob7Hdvt TrU9P6d0Pibi+5RWGPxRY8Ae2QGbD5pz6Oto0uSks+W8cgmJDa6leKJmRVu4Ln9B iLvrOMmlXV8hMjdG2c55sEk6vkkuuAxmwVyfZGZG2Edt5qd9Ymg== X-Virus-Scanned: amavis at mykolab.com X-Spam-Flag: NO X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-1 tagged_above=-10 required=5 tests=[ALL_TRUSTED=-1] autolearn=ham autolearn_force=no Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out011.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id V0ZQgO51btPv for ; Sun, 6 Oct 2024 15:45:12 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 367FC3507C0F for ; Sun, 6 Oct 2024 15:45:11 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 74E2D20AA57A for ; Sun, 6 Oct 2024 15:45:11 +0200 (CEST) From: =?utf-8?Q?J=C3=B8rgen_Kvalsvik?= To: bug-gnu-emacs@gnu.org Subject: [PATCH] Anchor to first sibling unless bol-sibling found X-Debbugs-Cc: theo@thornhill.no,casouri@gmail.com Date: Sun, 06 Oct 2024 15:44:55 +0200 Message-ID: <87y131wdk8.fsf@lambda.is> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=212.103.80.155; envelope-from=j@lambda.is; helo=mx.kolabnow.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 06 Oct 2024 12:05:07 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch Indenting would give up when initializer lists and similar constructs were broken up over multiple lines where the first item was not also beginning-of-line. Items should anchor on the first sibling (like with function calls and init-lists in general). The search for a sibling to anchor on should stop at the first sibling at bol or the first sibling in the (sub)tree. This brings indent up to c-mode parity for code like: return { x1, x2, ..., y1, x2, ... }; In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu) of 2024-10-06 built on ada Repository revision: c8e5f2ee9f6155ef545c2fe8ddf702c4f16a6eea Repository branch: master System Description: Debian GNU/Linux 12 (bookworm) Configured using: 'configure --with-x-toolkit=no --with-xpm=ifavailable --with-jpeg=ifavailable --with-png=ifavailable --with-gif=ifavailable --with-tiff=ifavailable --with-gnutls=ifavailable --with-tree-sitter --with-native-compilation --prefix=/home/j/src/emacs/build/root' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Anchor-to-first-sibling-unless-bol-sibling-found.patch >From 0bf96b008b57298ffcc63b9bb8222358ce966c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 4 Oct 2024 21:38:33 +0200 Subject: [PATCH] Anchor to first sibling unless bol-sibling found The behavior differed between c-mode/c++-mode and *-ts-mode for initializer lists where the first element was not at beginning-of-line. The anchor-prev-sibling function gave up and returned nil, but it should (probably) anchor on the first element in the initializer list, such as this: return { v1, v2, ..., y1, y2, ... }; c-ts-mode behaved better and figured out how to align, but I added a test for a similar compound literal to prevent regressions. * lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): Anchor at first sibling unless bol is found. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New initializer list and compound literal test. --- lisp/progmodes/c-ts-mode.el | 9 +++-- .../progmodes/c-ts-mode-resources/indent.erts | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 303c994637c..3f6a7422aa0 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -338,10 +338,13 @@ c-ts-mode--anchor-prev-sibling ;; If the start of the previous sibling isn't at the ;; beginning of a line, something's probably not quite ;; right, go a step further. (E.g., comment after a - ;; statement.) + ;; statement.) If the previous sibling is the first named + ;; node then anchor to that, e.g. when returning an aggregate + ;; and starting the items on the same line as {. (_ (goto-char (treesit-node-start prev-sibling)) - (if (looking-back (rx bol (* whitespace)) - (line-beginning-position)) + (if (or (looking-back (rx bol (* whitespace)) + (line-beginning-position))) + (null (treesit-node-prev-sibling prev-sibling t)) (setq continue nil) (setq prev-sibling (treesit-node-prev-sibling prev-sibling))))))) diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index 599173832b5..a13a74cf8b3 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts @@ -208,6 +208,21 @@ int main() } =-=-= +Name: Return Compund Literal + +=-= +struct pair { int fst, snd; }; +struct pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return (struct pair) { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} + +=-=-= + Name: Switch-Case statement =-= @@ -486,6 +501,30 @@ namespace A { } =-=-= +Name: Return Aggregate Initialized Struct + +=-= +struct pair { int x, y; } +pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} +=-= +struct pair { int x, y; } +pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} +=-=-= + Code: (lambda () (c-ts-mode) -- 2.39.5 --=-=-=-- ------------=_1728544082-27235-1-- From unknown Sun Jun 22 20:56:52 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: =?UTF-8?Q?J=C3=B8rgen?= Kvalsvik Subject: bug#73662: closed (Re: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found) Message-ID: References: <65500369-261B-4FC9-805B-94F77EC4A21F@gmail.com> <87iku5qqf3.fsf@lambda.is> X-Gnu-PR-Message: they-closed 73662 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 73662@debbugs.gnu.org Date: Thu, 10 Oct 2024 07:08:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1728544083-27235-3" This is a multi-part message in MIME format... ------------=_1728544083-27235-3 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #73661: [PATCH] Anchor to first sibling unless bol-sibling found which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 73662@debbugs.gnu.org. --=20 73661: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D73661 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1728544083-27235-3 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 73661-done) by debbugs.gnu.org; 10 Oct 2024 07:07:59 +0000 Received: from localhost ([127.0.0.1]:58509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1synHC-000752-DP for submit@debbugs.gnu.org; Thu, 10 Oct 2024 03:07:58 -0400 Received: from mail-pj1-f47.google.com ([209.85.216.47]:43159) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1synH8-00074l-90 for 73661-done@debbugs.gnu.org; Thu, 10 Oct 2024 03:07:56 -0400 Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2e2e050b1c3so50182a91.0 for <73661-done@debbugs.gnu.org>; Thu, 10 Oct 2024 00:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728543997; x=1729148797; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HE/T5T20j/mwGRKKYVAKkW/2+HtIdPVZcJ9cW1GLB9Y=; b=RpG6R1GOpaGzXI/cDHP8jnze3Ij9fC6NAZA2kCk0HLdDsuqrha9ctl+BfhTsvMMvR4 GWhQAzJTZnQsWvqd3Ps6B00lcX45OLEoqJNaxvTKn5s0Fkcma++tX6TRs/aZW1bduf5N cAvI/3CXOaQ39iaKDI8/PGdY+5vlv8iIReNmD94imRTesSFj3ZHIQFAdhUSymflNEdlt Apobbwv42llLNqZzBuaKRob2IujDv2BWZ4VEdNwGzbHrmBA0KKBeDKI3/lmcyfUPEeYo tNpwIANZtg5KNS8ORXF1xOZxysSHUMNk+sCppxYT+XTHCKvWO5JWGNJlabhrV4gmwJvo X2KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728543997; x=1729148797; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HE/T5T20j/mwGRKKYVAKkW/2+HtIdPVZcJ9cW1GLB9Y=; b=lkc9f5H5ayDJ9SLbgr0gcx1FevIRa2yu/B1KoyvGVU7HKfHj1hLTt5vucjy65mFLR1 iotxAAlEwdpSmg0iKLk0WQHIguKVdm1JVyKpudWMrRrWwM0qHvZm7XNQ7LV0WIYG+QbH zJ4KcTsUbXlD1LT7CXKo9jdLeLYE808DfI/etQx3re2/PtR5qDZ6erXd7SpaodQU/AkT fB4lilV9Jfp3Vh48RSZurTG9OxkMvF7/sAfStkAYNx51G4UHLB7hd7IFGJevgWF3jGGo UvZXZJyJNmsHgfIAEGgHWFXfJdl3Uu42bUZSaANU1wUe+wNOzBUsbsb+g9lbL6iDdmZe CpQg== X-Forwarded-Encrypted: i=1; AJvYcCUSANTZGKaRRIUGiiBbBy+DUVbKpdkKERjyZD6NP7sxcg1i5PPdx5EImth+c3X8cBj1YYyYNlF1oigs@debbugs.gnu.org X-Gm-Message-State: AOJu0Yx967ga+1gkSaLwoWyrwV6sZWAx1aqdh0XgjP3HvXKCPjciuQyR SrVgrqv3k1Ga4i448umKKu313noICiBvsag16B9apCsoE/N999QR X-Google-Smtp-Source: AGHT+IHlbgEpn7locogkHJGenekGgrA8KrbnRea5W7/go6hwBoOe48dFDrE2ncW1x5D9AfUXELRfZQ== X-Received: by 2002:a17:90a:8a8d:b0:2e2:bdaa:baad with SMTP id 98e67ed59e1d1-2e2c804262bmr3441682a91.7.1728543997277; Thu, 10 Oct 2024 00:06:37 -0700 (PDT) Received: from smtpclient.apple ([2601:646:8f81:6120:f11e:b651:2f41:7105]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2d5fcc759sm564521a91.57.2024.10.10.00.06.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Oct 2024 00:06:36 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: bug#73661: [PATCH] Anchor to first sibling unless bol-sibling found From: Yuan Fu In-Reply-To: <86v7y2st34.fsf@gnu.org> Date: Thu, 10 Oct 2024 00:06:25 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <65500369-261B-4FC9-805B-94F77EC4A21F@gmail.com> References: <87y131wdk8.fsf@lambda.is> <86v7y2st34.fsf@gnu.org> To: Eli Zaretskii X-Mailer: Apple Mail (2.3776.700.51) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 73661-done Cc: 73661-done@debbugs.gnu.org, Theodor Thornhill , =?utf-8?Q?J=C3=B8rgen_Kvalsvik?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Oct 8, 2024, at 4:59=E2=80=AFAM, Eli Zaretskii = wrote: >=20 >> From: Yuan Fu >> Date: Mon, 7 Oct 2024 17:12:22 -0700 >> Cc: 73661@debbugs.gnu.org, >> Theodor Thornhill , >> Eli Zaretskii >>=20 >> Awesome! Thanks for the patch. Have you signed the copyright = assignment? Eli, does this count as a significant contribution that = requires the copyright assignment? >=20 > This is small enough to accept without paperwork. Merged. Thanks! Yuan= ------------=_1728544083-27235-3 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 6 Oct 2024 16:05:12 +0000 Received: from localhost ([127.0.0.1]:42031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxTkt-0001TX-QY for submit@debbugs.gnu.org; Sun, 06 Oct 2024 12:05:12 -0400 Received: from lists.gnu.org ([209.51.188.17]:39640) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxRrk-0003EW-TG for submit@debbugs.gnu.org; Sun, 06 Oct 2024 10:04:09 -0400 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 1sxRre-0000Gi-CM for bug-gnu-emacs@gnu.org; Sun, 06 Oct 2024 10:04:02 -0400 Received: from mx.kolabnow.com ([212.103.80.155]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxRrb-00083o-TT for bug-gnu-emacs@gnu.org; Sun, 06 Oct 2024 10:04:02 -0400 Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 5B37F38159F for ; Sun, 6 Oct 2024 16:03:57 +0200 (CEST) Authentication-Results: ext-mx-out013.mykolab.com (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-type:content-type:mime-version:message-id:date:date :subject:subject:from:from:received:received:received; s= dkim20240523; t=1728223436; x=1730037837; bh=cZRzFiP1i1UhQXfoWvF cxK0HHwPEtI6hp+K60h5T7hc=; b=PavtFV5KbXxnQjEexC/e3X932O8+hr0a5q+ IUK91SGIRbOs5N2yKLWJ+GeYtzGmgLfr+MnAtQCaqyjssdQUCFhVcQNh3JV+taTc 6BTIhPRCwN75fFmXkGf8Td/kysbl1nhSw4YNZIpCzNBNrLGA5V4ai3ARgtf9i0XT +VUiwb2r8VTNQuZ3KezaZtzmxhN3K/0PMT7IQmFu56pBaL08zv3qMDnZTFJI2LiI iV5B4lhE3eVmX5wSv9U/+u19QULmuynJzISJIzQUUIn8n0dxFrfBxrOV55W+xUAi kNWP1h4/uxrCRPKgYTC2MU9UUjBySBTzwU7GICmuNQSV+1lKYWw== X-Virus-Scanned: amavis at mykolab.com X-Spam-Flag: NO X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-1 tagged_above=-10 required=5 tests=[ALL_TRUSTED=-1] autolearn=ham autolearn_force=no Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out013.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id YMJV2qEizLSk for ; Sun, 6 Oct 2024 16:03:56 +0200 (CEST) Received: from int-mx011.mykolab.com (unknown [10.9.13.11]) by mx.kolabnow.com (Postfix) with ESMTPS id 735D338159E for ; Sun, 6 Oct 2024 16:03:56 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx011.mykolab.com (Postfix) with ESMTPS id 4AEC430987CA for ; Sun, 6 Oct 2024 16:03:56 +0200 (CEST) From: =?utf-8?Q?J=C3=B8rgen_Kvalsvik?= To: bug-gnu-emacs@gnu.org Subject: [PATCH] Anchor to first sibling unless bol-sibling found X-Debbugs-Cc: theo@thornhill.no,casouri@gmail.com Date: Sun, 06 Oct 2024 16:03:44 +0200 Message-ID: <87iku5qqf3.fsf@lambda.is> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=212.103.80.155; envelope-from=j@lambda.is; helo=mx.kolabnow.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 06 Oct 2024 12:05:07 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch Indenting would give up when initializer lists and similar constructs were broken up over multiple lines where the first item was not also beginning-of-line. Items should anchor on the first sibling (like with function calls and init-lists in general). The search for a sibling to anchor on should stop at the first sibling at bol or the first sibling in the (sub)tree. This brings indent up to c-mode parity for code like: return { x1, x2, ..., y1, x2, ... }; In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu) of 2024-10-06 built on ada Repository revision: c8e5f2ee9f6155ef545c2fe8ddf702c4f16a6eea Repository branch: master System Description: Debian GNU/Linux 12 (bookworm) Configured using: 'configure --with-x-toolkit=no --with-xpm=ifavailable --with-jpeg=ifavailable --with-png=ifavailable --with-gif=ifavailable --with-tiff=ifavailable --with-gnutls=ifavailable --with-tree-sitter --with-native-compilation --prefix=/home/j/src/emacs/build/root' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Anchor-to-first-sibling-unless-bol-sibling-found.patch >From 0bf96b008b57298ffcc63b9bb8222358ce966c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 4 Oct 2024 21:38:33 +0200 Subject: [PATCH] Anchor to first sibling unless bol-sibling found The behavior differed between c-mode/c++-mode and *-ts-mode for initializer lists where the first element was not at beginning-of-line. The anchor-prev-sibling function gave up and returned nil, but it should (probably) anchor on the first element in the initializer list, such as this: return { v1, v2, ..., y1, y2, ... }; c-ts-mode behaved better and figured out how to align, but I added a test for a similar compound literal to prevent regressions. * lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling): Anchor at first sibling unless bol is found. * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New initializer list and compound literal test. --- lisp/progmodes/c-ts-mode.el | 9 +++-- .../progmodes/c-ts-mode-resources/indent.erts | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 303c994637c..3f6a7422aa0 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -338,10 +338,13 @@ c-ts-mode--anchor-prev-sibling ;; If the start of the previous sibling isn't at the ;; beginning of a line, something's probably not quite ;; right, go a step further. (E.g., comment after a - ;; statement.) + ;; statement.) If the previous sibling is the first named + ;; node then anchor to that, e.g. when returning an aggregate + ;; and starting the items on the same line as {. (_ (goto-char (treesit-node-start prev-sibling)) - (if (looking-back (rx bol (* whitespace)) - (line-beginning-position)) + (if (or (looking-back (rx bol (* whitespace)) + (line-beginning-position))) + (null (treesit-node-prev-sibling prev-sibling t)) (setq continue nil) (setq prev-sibling (treesit-node-prev-sibling prev-sibling))))))) diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts b/test/lisp/progmodes/c-ts-mode-resources/indent.erts index 599173832b5..a13a74cf8b3 100644 --- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts @@ -208,6 +208,21 @@ int main() } =-=-= +Name: Return Compund Literal + +=-= +struct pair { int fst, snd; }; +struct pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return (struct pair) { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} + +=-=-= + Name: Switch-Case statement =-= @@ -486,6 +501,30 @@ namespace A { } =-=-= +Name: Return Aggregate Initialized Struct + +=-= +struct pair { int x, y; } +pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} +=-= +struct pair { int x, y; } +pair +make_pair(int long_identifier_a[], int long_identifier_b[], + int offset_a, int offset_b) +{ + int base_offset = 10; + return { long_identifier_a[base_offset + offset_b], + long_identifier_b[base_offset + offset_b] }; +} +=-=-= + Code: (lambda () (c-ts-mode) -- 2.39.5 --=-=-=-- ------------=_1728544083-27235-3--