From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Randy Taylor Newsgroups: gmane.emacs.bugs Subject: bug#66845: 29.1; cmake-ts-mode indentation broken Date: Wed, 01 Nov 2023 02:45:26 +0000 Message-ID: <4m1KSu7eJ_B7nNCVOnvZM_edTrQhMTtxiKFwUB4zNoYufrWuTYcq_tL1iIRml2xqDRdTDavJBnE7B4iNmswVLwzGXI96E_FNcXkCeDqUzVo=@rjt.dev> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="b1_yZRPEuPn2C5cFkv1G3JmWjjaMeRMNwWtMj0UfzhI" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39637"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66845@debbugs.gnu.org, Yuan Fu To: Juan Palacios Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 01 03:46:49 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 1qy1Fp-000A43-1V for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Nov 2023 03:46:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qy1FX-0001Ft-TF; Tue, 31 Oct 2023 22:46:31 -0400 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 1qy1FU-0001Fd-G1 for bug-gnu-emacs@gnu.org; Tue, 31 Oct 2023 22:46:28 -0400 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 1qy1FU-0002QE-7q for bug-gnu-emacs@gnu.org; Tue, 31 Oct 2023 22:46:28 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qy1G1-00083P-Ua for bug-gnu-emacs@gnu.org; Tue, 31 Oct 2023 22:47:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Randy Taylor Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Nov 2023 02:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66845 X-GNU-PR-Package: emacs Original-Received: via spool by 66845-submit@debbugs.gnu.org id=B66845.169880679030907 (code B ref 66845); Wed, 01 Nov 2023 02:47:01 +0000 Original-Received: (at 66845) by debbugs.gnu.org; 1 Nov 2023 02:46:30 +0000 Original-Received: from localhost ([127.0.0.1]:49605 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qy1FW-00082Q-4N for submit@debbugs.gnu.org; Tue, 31 Oct 2023 22:46:30 -0400 Original-Received: from mail-4018.proton.ch ([185.70.40.18]:57341) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qy1FT-000827-2s for 66845@debbugs.gnu.org; Tue, 31 Oct 2023 22:46:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rjt.dev; s=protonmail; t=1698806745; x=1699065945; bh=9zfUqoxhKBSrqlggfD0qpCSIfeR+LPRXfXOu2iTMUJE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=AcUT1oyXRjzadFrdCUPXewcNoMhN5zN/t7t4fZwhattOvwizeX9ipzvqgb0pRJ1pM IhciKHd4I+cEXm4OlyxKQiwqEzq3TG74dLYph6wmvuIGJeo+Xz6jhe7JeaqsCXdquf VLCkMUSfqZIrOyZYhl6gVH3xO02WH8VMD0wqb3c0lX5fMM60V6cow+WwajEQUoBCG2 4CYBkCXdClM3skyeO/b8r+ISTB8J0lxKZ2nsQ1Jv4mAoNgWI40ur9AEthYQPa1mTP2 RQSWqaQ4N8GZYTOnZQpEX9kJO7bhkgokShcTmIIoIESsm6Zh5bYlQHUWwTSDRlD20h c4RHBhcvZdVwA== In-Reply-To: Feedback-ID: 44397038:user:proton 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:273584 Archived-At: This is a multi-part message in MIME format. --b1_yZRPEuPn2C5cFkv1G3JmWjjaMeRMNwWtMj0UfzhI Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tuesday, October 31st, 2023 at 07:35, Juan Palacios wrote: > Using cmake grammar from https://github.com/uyha/tree-sitter-cmake >=20 > Reproduction: > 1. emacs -q > 2. C-x C-f test.cmake > 3. M-x cmake-ts-mode > 4. Insert the following text: > if(TRUE) > message("indent") > endif() > 5. Move the point to the beginning of the second line. > 6. TAB > 7. Notice that no indentation is performed. >=20 > treesit-simple-indent-rules local value: > ((cmake > ((node-is ")") > parent-bol 0) > ((node-is "else_command") > parent-bol 0) > ((node-is "elseif_command") > parent-bol 0) > ((node-is "endforeach_command") > parent-bol 0) > ((node-is "endfunction_command") > parent-bol 0) > ((node-is "endif_command") > parent-bol 0) > ((parent-is "foreach_loop") > parent-bol cmake-ts-mode-indent-offset) > ((parent-is "function_def") > parent-bol cmake-ts-mode-indent-offset) > ((parent-is "if_condition") > parent-bol cmake-ts-mode-indent-offset) > ((parent-is "normal_command") > parent-bol cmake-ts-mode-indent-offset))) >=20 > treesit-explore-mode shows: > (if_condition > (if_command (if) ( > (argument_list > (argument (unquoted_argument))) > )) > (body > (normal_command (identifier) ( > (argument_list > (argument > (quoted_argument " (quoted_element) "))) > ))) > (endif_command (endif) ( ))) >=20 I've attached a patch fixing this while retaining compatibility with older grammars. 2 new versions of the grammar, v0.3.0 and v0.4.0 (and anything beyond for now) wrap things in new nodes. Yuan, It's been awhile since I've touched any tree-sitter stuff so I'm probably missing something obvious, but it seems to me like the function I've added in the patch (cmake-ts-mode--argument-list-body-offset) is working around a bug somewhere? I'm not sure why the start of line_comment is considered parent-bol for indentation. For example, with this test cmake file: (test.cmake) if(TRUE) # Comment. message("indent") endif() We get: (source_file (if_condition (if_command (if) ( (argument_list (argument (unquoted_argument))) )) (body (line_comment) (normal_command (identifier) ( (argument_list (argument (quoted_argument " (quoted_element) "))) ))) (endif_command (endif) ( )))) With cmake-ts-mode--argument-list-body-offset always returning cmake-ts-mode-indent-offset (which is what I would expect), the `parent-is "body"` rule will cause this indentation: if(TRUE) # Comment. message("indent") endif() Am I being silly or is there indeed something odd going on? --b1_yZRPEuPn2C5cFkv1G3JmWjjaMeRMNwWtMj0UfzhI Content-Type: text/x-patch; name=0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch RnJvbSA1NDQzOTZiN2FmYTU1YzRkMTJmYzZmMDMxOTgxOTkwMTc1ODJiOGRmIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBSYW5keSBUYXlsb3IgPGRldkByanQuZGV2PgpEYXRlOiBUdWUs IDMxIE9jdCAyMDIzIDIyOjA4OjI1IC0wNDAwClN1YmplY3Q6IFtQQVRDSF0gRml4IGNtYWtlLXR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