From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 06 12:05:12 2024 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 06 12:24:49 2024 Received: (at 73662) by debbugs.gnu.org; 6 Oct 2024 16:24:49 +0000 Received: from localhost ([127.0.0.1]:42110 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sxU3t-0002WA-Bh for submit@debbugs.gnu.org; Sun, 06 Oct 2024 12:24:49 -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: 73662 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 15:24:58 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 07 Nov 2024 12:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator