From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#62412: 29.0.60; strange c++ indentation behavior with tree sitter Date: Sat, 25 Mar 2023 11:43:45 +0000 Message-ID: References: <2496F2A0-3EB1-4CD2-B299-E1DC41B7C23B@gmail.com> <46A6C705-97DA-4D17-999B-0536F01EFCA7@thornhill.no> 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="15159"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , Theodor Thornhill , 62412@debbugs.gnu.org To: Herman@debbugs.gnu.org, =?UTF-8?Q?G=C3=A9za?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 25 13:15:06 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 1pg2nZ-0003mv-Lw for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Mar 2023 13:15:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pg2mb-0004Dl-EA; Sat, 25 Mar 2023 08:14:05 -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 1pg2mZ-0004CP-NK for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 08:14:03 -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 1pg2mZ-00029M-FO for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 08:14:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pg2OL-0003nt-Jy for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 07:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Mar 2023 11:49: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.167974491014577 (code B ref 62412); Sat, 25 Mar 2023 11:49:01 +0000 Original-Received: (at 62412) by debbugs.gnu.org; 25 Mar 2023 11:48:30 +0000 Original-Received: from localhost ([127.0.0.1]:41872 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pg2Np-0003n2-GX for submit@debbugs.gnu.org; Sat, 25 Mar 2023 07:48:29 -0400 Original-Received: from mail-yw1-f170.google.com ([209.85.128.170]:41644) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pg2Nn-0003mW-Si for 62412@debbugs.gnu.org; Sat, 25 Mar 2023 07:48:28 -0400 Original-Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-5445009c26bso81841677b3.8 for <62412@debbugs.gnu.org>; Sat, 25 Mar 2023 04:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679744902; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FFnxUIu/V0icWpOQ75ljMRj8TO/h1v7LpM+cPokr39M=; b=YK92hplwlXLRP1/shBp4TSOxy0xj8raY4exOOjb2btz1iTucpyT1J62UHnOuRxuUpQ XcabBIU9rPyl6IMYyjnWr5nu9ZMTa1JrV6lQ3NgDaEfTeTnrmJkI54+e5K2lLlbEc9E7 41yCMN52obIKTIxoFlhPeBGz1anGSJpO3IRzr3QXNb7KX/c88cSLa4b5/lhgc0MJCeRk BHgqgow0gmR5h4Sroxi+6/paN3dmuv0kqZdgDkhQsNTksJpfZgzN10oFm9d5bT+suf3d iEbpumdDF6m1uLUIPAZzYApr61cpZ5iXHZ5HSMUhrwGa0zAntMlDdJ7uriIAZozIvS6Z Kvmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679744902; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FFnxUIu/V0icWpOQ75ljMRj8TO/h1v7LpM+cPokr39M=; b=eRQ7vK/zSdNow/FuzLpnMp89F4gbLi9YANlNQJyeMorm/UZyJPUZ5b48Vna8BWX8pG oV3H0TDrk0NT75pGN+RFM3sfxsXxTuiXzeKQ30Q8E9cMDutfT8mAfUA83tMLiykUrpXW v3FWZa1fvhAVXS7R3HGHH84pfj25JreJi1EHfdnHA4PW9qXrJunf8khsWEVXra78AUWP JDlZ+VVt755OHJaKC5YeyrgCdcz7N++c1+LadaHIBo5PPv5qWVksElPVkqfxcXdfEuTI RjI0qljGe2qRMq+AMyuBZwS5TqlQv8l09reW0ic8t8mAf5qtMmmexTVwd1o3zBFDGdhH +pEQ== X-Gm-Message-State: AAQBX9dvXFNXsUJgaB9LhTvkUNqorUq7YZKAYUcv0cRPx/w0w4Huax+o jthxKr1V9naySFB4Oek7vn0M6LDpor24gr3HOAGMO+Se X-Google-Smtp-Source: AK7set/5oA1LpOUNYSgaSoe7ohQC/EyBvG5rLWyUdB13lekmNpLIpE6tcV4S0KR796Nh5gZUCxtw7pWl77DES68l6DQ= X-Received: by 2002:a05:6830:1bcf:b0:68b:e0dc:abc7 with SMTP id v15-20020a0568301bcf00b0068be0dcabc7mr1950435ota.4.1679744513907; Sat, 25 Mar 2023 04:41:53 -0700 (PDT) In-Reply-To: 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:258544 Archived-At: On Sat, Mar 25, 2023 at 10:26=E2=80=AFAM Herman, G=C3=A9za wrote: > > That's the difference. c++-ts-mode appends "{}():;,#" to > electric-indent-chars, while c++-mode doesn't do this. > > Nevertheless, I think that the calculated intendation should be a > correct number. Even if the user turns off electric-indent-mode, but > dedices to call re-indenting manually for a half-written for loop, emacs > should re-intent the line properly. At least, this specific example > works OK with c++-mode. > > (note that I understand that this problem is not trivial, tree > sitter/emacs may get confused if the buffer cannot be properly parsed) There can be no "correct" indentation in a buffer with an invalid state. But there are heuristics. Here, it can be argued that c++-mode's heuristics are better. Let's assume you turn off electric-indent-mode. In c++-mode, pressing RET after: int main() { "correctly" indents the next line. In c++-ts-mode, it doesn't. Both programs are ill-formed but you're right that after correcting that, by say adding 'return 0; RET }', the c++-mode version of the same program is closer to being correctly indented. But this heuristic is not always great, so it's a stick with two ends. Now let's take another invalid program: int foo() class bar { | <- cursor here } In c++-mode typing TAB indents the class line to the second column, which is arguably worse than c++-ts-mode, which doesn't do anything. That's because you may well want to work on that class and then only remember that you need the ';' for the declaration of 'foo'. IMO, it's a question of getting used to it in the end. And using electric-pair-mode helps a lot, as some have pointed out. Jo=C3=A3o