From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel =?UTF-8?Q?Mart=C3=ADn?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#62412: 29.0.60; strange c++ indentation behavior with tree sitter Date: Sun, 26 Mar 2023 15:25:15 +0200 Message-ID: References: <2496F2A0-3EB1-4CD2-B299-E1DC41B7C23B@gmail.com> <46A6C705-97DA-4D17-999B-0536F01EFCA7@thornhill.no> Reply-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17579"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin) Cc: Yuan Fu , 62412@debbugs.gnu.org, geza.herman@gmail.com To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 26 15:26:24 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 1pgQO7-0004K4-Us for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Mar 2023 15:26:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgQNq-0004ps-6c; Sun, 26 Mar 2023 09:26:06 -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 1pgQNn-0004pO-QT for bug-gnu-emacs@gnu.org; Sun, 26 Mar 2023 09:26:04 -0400 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 1pgQNn-0005gU-92 for bug-gnu-emacs@gnu.org; Sun, 26 Mar 2023 09:26:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pgQNl-0000ez-Qd for bug-gnu-emacs@gnu.org; Sun, 26 Mar 2023 09:26:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Mar 2023 13:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62412 X-GNU-PR-Package: emacs Original-Received: via spool by 62412-submit@debbugs.gnu.org id=B62412.16798371312496 (code B ref 62412); Sun, 26 Mar 2023 13:26:01 +0000 Original-Received: (at 62412) by debbugs.gnu.org; 26 Mar 2023 13:25:31 +0000 Original-Received: from localhost ([127.0.0.1]:44266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgQNG-0000eC-Dt for submit@debbugs.gnu.org; Sun, 26 Mar 2023 09:25:30 -0400 Original-Received: from sonic301-21.consmr.mail.ir2.yahoo.com ([77.238.176.98]:33550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgQND-0000dr-Gx for 62412@debbugs.gnu.org; Sun, 26 Mar 2023 09:25:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.es; s=s2048; t=1679837120; bh=3HxmsSTZavL05/J+mMo/CAjtZBmrx03HC4lUcZ4SKXo=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=SBvjrFnMC8WXbNtKGRFki3fK4lqUryHHALPsV9oPsfY7kuCM6MFSvbv1b57HsZcJFbP7eVLrszI4UrgI/DdzmrZRXKhaRuk0R8c/mPzoMEKcU2J0vmEKiOev1wwhdT92nHORAXdmeupwS4fi8EqrtLBBYaAomCQ24WX/Vb7yLPPcF/VA1tjtrt1GHKQO0vX+bpvAsH0TwIQRsYe2GrSeOS2g1+jmpYVv4yMzN6zxj2MS8oTY1FcLwMIsIDBzZ1WYcRoIJ4WvPHW4gjUxYoQUEmN3D8jFSGxEIfj0+mrQ1jX5X5CIq5xLBNfHsqA3ucPaXpeZhBfpfQf/zA68M4nBHg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1679837120; bh=r79q4OohKRTYyPfNAOrCkKtvzAIO19gpM8fC7s440t2=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=bznkN06nC7Sf+s8K3+7Mp/D0kkdt0MwwzcdXFi4ZD6p2Ve8S603xnvJi/L2f2MCnooXJ/L44P8ehue5FuA03PMdBxKN9mmpNFqReKJ7fY4rBv9OrTLp/4cQg1AqrR/0mYJMsju6Pdl5cEQZs9PfVVN9TIJlqUFxs3RFhoMcn3876UgA7JMPPVTla1AdHg0I67Tf26Wrjh7d4vqZZiFD086juu9IDfTtahGviEbGUlhxBrD3jZzjiAf23bCV2jtxbDJOAJG6HcyKs7HpayOkSikjJdX07LK2NdphBnaWszhGud8BZEWG+lBdlb7cV8GINDYBArOCAAvCepWaeD+00dw== X-YMail-OSG: X6CEv_YVM1lLwm3bk71GGB4zn_Y4DNHBr0IhAM8PD0nx5NFdWGWpo9FEfza0bab 7h4vzZuOOOj0_c6.YWk3lau3tu86h0H1iqp5F1oaiGAodE0umVid_TCGVOb5OEx3MhE252F1CZb9 pSfdjK17zuHPavryQwQIr6YCFaKq2xHM.jeOQMK6wNm1aVeTcbuN.Ru04x_gzrQmrnpLqunwlG3s xlrFWFM62Lx_LJ.55x8.JResfix3tP9TWaWq983gEb81G0YLRi4cZQqDVIPGwxJLjnmsY5aOuFVn HvemIdky6rcmR5xXzXOoon2B7P4PnMCgrJmcy6jjqmU5HY2viu9e0Wg2yNurtoU8JrayWNQVnxki 2VaAy1J6YydS6_m6yE9j4QMDO1u9N77ayEHI25.DTmSPjG.ST5iP5UAipEIf_r_vZizndf4HiR9X SaexV6zkzRsZZSqed1hevWwGWLZq.8ZgGlApzACR5SI2DrvkTJqQRRP.tx0OgVfYe7Wr76boSmWZ wd8xvT_LiU_qbgDGAG.HECJ97pQLScNis6ojV78Hs9yT6W6sjgOizZ.NqUpI8owOxfJ8igbf6sel ByRNaLI5PtFBhB6VDJ1pPZVs5Jy12aN0LfjNZPA8UZe.Eg0VS8WeXTc17fgZrhfvsKRqLiH_kjr0 fELIFsftUm9UWGZvIOUJLdgjC9KatfU_dF1HEdrjKnYy3xBUiMzfgkab3c2eMF1vh6FlJjloIAAY RCFJe5wJQnI7G6SSiwJCyXD8j0bJqkg6UgQtg1sMjGOu_CDW3CBGISLjJovlJOrKQNU9sW_wWqXG ni2GpPs4mvnCON3SIdtHoo82Zi7yVAhfH0GjlIw7Io X-Sonic-MF: X-Sonic-ID: 7d33e869-1bfc-4163-b5dc-798d3a95d802 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Sun, 26 Mar 2023 13:25:20 +0000 Original-Received: by hermes--production-ir2-5b7d458747-rxkcm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 7d3370177d3fe044b4068cabab889c6a; Sun, 26 Mar 2023 13:25:16 +0000 (UTC) In-Reply-To: <46A6C705-97DA-4D17-999B-0536F01EFCA7@thornhill.no> (Theodor Thornhill's message of "Fri, 24 Mar 2023 21:04:24 +0100") X-Mailer: WebService/1.1.21284 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:258678 Archived-At: Theodor Thornhill writes: > I'll look more deeply into the cause of this, but the rule is covering some preproc directives iirc. > > Unfortunately tree-sitter behaves better when auto pairs is used. I > would advise people to use electric-pairs-mode (if that's the correct > name, on mobile now) to avoid these sorts of issues. > Yes, I think that having an error node in the indentation rules is not a good idea. It can cause unexpected issues like the one described in this thread. I'd explore the idea of removing error nodes from the rules before resorting to tweak the electric or pairing features of Emacs. Let's look into the problem that the introduction of the error node tried to solve, the indentation of preprocessor directives. Starting with this code: int main() { | } if I type '#', automatic indentation does not happen because, at that stage, the AST doesn't recognize the full preprocessor directive (the node in the AST is an error node). If I continue writing the preprocessor directive (say, "#ifdef DEBUG"), the preprocessor node is created correctly, but it would require a manual TAB to go to column 0 because we haven't inserted any electric character while we completed the directive. The same manual TAB is required by c++-mode, so I wouldn't see this as a regression. However, there might be still minor divergences between c++-mode and c++-ts-mode. For example: int main() { #if } This in-progress code would indent correctly in c++-mode, but on c-ts-mode the node is an error node, so we won't reliably know that it should indent to column 0. If we want to fix these minor divergences, I see two possible approaches: - Investigate if the C/C++ grammars can be improved to cover these cases better. - Without changing the grammars, could we insert our own preprocessor nodes in the AST tree by checking if the first non-whitespace character of the line is the beginning of #assert, #define, #include, #if, #ifndef, #elif, etc.?