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#61356: 29.0.60; wrong-type-argument in treesit-indent-region when indenting a C buffer Date: Sat, 25 Feb 2023 03:24:54 +0100 Message-ID: References: <83a61nm96q.fsf@gnu.org> Reply-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38507"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin) Cc: 61356@debbugs.gnu.org, Yuan Fu , Theodor Thornhill To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 25 03: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 1pVkGU-0009jx-O2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Feb 2023 03:26:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVkGC-0003PA-Rp; Fri, 24 Feb 2023 21:26:04 -0500 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 1pVkGA-0003Oz-OP for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 21:26:02 -0500 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 1pVkGA-0006vM-Fc for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 21:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pVkGA-0004Tt-5w for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 21:26:02 -0500 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: Sat, 25 Feb 2023 02:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61356 X-GNU-PR-Package: emacs Original-Received: via spool by 61356-submit@debbugs.gnu.org id=B61356.167729190917142 (code B ref 61356); Sat, 25 Feb 2023 02:26:02 +0000 Original-Received: (at 61356) by debbugs.gnu.org; 25 Feb 2023 02:25:09 +0000 Original-Received: from localhost ([127.0.0.1]:38670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVkFI-0004SQ-Oy for submit@debbugs.gnu.org; Fri, 24 Feb 2023 21:25:09 -0500 Original-Received: from sonic308-19.consmr.mail.ir2.yahoo.com ([77.238.178.147]:42922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVkFG-0004Rp-7u for 61356@debbugs.gnu.org; Fri, 24 Feb 2023 21:25:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.es; s=s2048; t=1677291900; bh=04Hnh6dSb/0l0SL1ZBprk4E6rn7i9n8x97U1CkmN0N0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=aKjZh5SeMgO4ol5JE1kq8nE649oR9vPwn/aJNaFmqz7/9NUJyaH2eVsTlxyJwhoMZ4JKtxJgcJsyjTsQi8eq6i+vAjvx+FPj3dLchh4ELplEbmo9TKk8goCZVoJaQFRXM1KVPfQm/C+eQVVSOYS96R8mcqotqWD2kWtprz2+/12phKrrbIgXO9LhzOxy+16PhvLvN5UNWvoHjIYeRh7fs9YndEtMeElQxINB0IZ0sSUg7cIrNH6JHtpBVrO5geefYfshM/mwSri3+oMqRd2mirNiD8dR9Fxsr8rOZb8O01+BTjNOKMyrYOu89gOHYPMW2OkTqoJH5OfhI8OXaxDKCQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677291900; bh=qijd/Sdl3efyUTzjEhLDZQzrQBIYSTM/usw5hOep9sl=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=kUgQ4R4b2whMor/thG+8RYkQ2PuDzFE7p2WrPsSiIYj9pxHMI22pVa0wdRPf4fHieeQbZ3Y2y0Dz0j0ZUggOGz7EuZ+QRAokONUjJegdUOIWjdeDqLLpIiG5cU5I9td+CQDde6BP3lMIl6fWqYH3/xrQEjI1D6C8deSptxBwdRQ4XRvBfERMIUHf4OMQpcKTYau+19usfg5ITr7xfD7RQ5I7cZTvtx+4ZbTRvluOlEag15XYt/ju84W4+0wWg/entjgwABug5Z46jb8z8YC2NzmpjviH+JIV4DEENoO/+jWXIEF+ono531L6PcYEu+ItYzQ7AVbky6Dp9QDUR0myAg== X-YMail-OSG: _YQA24kVM1n8C7kuVrBneKqVqQWNJQV2u5USHHnS80WIAwbziCYGvCtxrkWrbBX R8Cx5CVn8be_2WSP.kVXAOuDEd00kMIig41nSOynj7HaU1_ldL0Py_7ECwgOr9DMCGH1F61vLn3q z7fj3xnMrfgPcx0bR.pUCa6xOlabXuPbq6l9rnJFDUfzJaCOjqzKh4zWj0NoFDbhUx_U6dBjWglt UDUkfxYfrlbfMMoxQdBBg9eMw.mm7X_ITHNBpxt3_Ix4aasY9uMIrPuYBetElCuYhh5ffAd58Q9C vZ8b.et9I35xu8e0ArhX09XMsau5GiN5xFkkRxiONPc44d2Q83VcMxb99f6Gog17MgcNcHoGInPW Oq7unc2f0LFZIQvlyD0EA8RhIAKKE249We85Nz6tlYKKKXqTqamAWjaWdTerv8hKp1Tx9RQd8RDE gZVZTGa6ZvjTzpFY.qO81Mo90AwSDv2BrKmQDWsCNog1s4Pu416oHitV0459PSYvfCL0KFUwMiwW 2xqa2gYWCrl8Stwak97CyreGOk2teTHYVJ.r.mFydT5Nub.RaSZ_nGey.3M9yKgVrYTTVVk8XoFZ QE7MwZAd.li0xhXwA1ZvuSS_ceA_JxWYSTDOrG.gKcfxtGkgoEBQoYAD1offv3QqJ4T4tFYMg9TE oa2epMo0QEjB1pMPk.YKa2k4eq6MDN9ZDSvT9brXIrpwqdXq8Uoyr_8D7i2wHWHOMr.JECuA4Wg7 Umt_ridVVSfhWcu8RWTSaXYlN.hIaOC2A2ayQCZSOOdbpMgbjbWSsJVyvb7atKnvORbDIdmufw8W peqnqh8ZU_O7h8SKxF78ZCmpxeSrubE.szkt14uAak X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sat, 25 Feb 2023 02:25:00 +0000 Original-Received: by hermes--production-ir2-65c64dfd66-q88mm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 39a5ef0efd5378adf7919a7396fc527a; Sat, 25 Feb 2023 02:24:55 +0000 (UTC) In-Reply-To: <83a61nm96q.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 09 Feb 2023 12:20:45 +0200") X-Mailer: WebService/1.1.21221 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:256673 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> Date: Tue, 07 Feb 2023 23:20:09 +0100 >> From: Daniel Mart=C3=ADn via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >>=20 >>=20 >> Steps to reproduce the problem: >>=20 >> emacs -Q >> C-x C-f emacs/src/xdisp.c RET >> M-x c-ts-mode RET >> C-x h >> TAB >>=20 >> Expected result: >>=20 >> The buffer is reindented. >>=20 >> Actual results: >>=20 >> The operation fails with this error: >>=20 >> Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p n= il) >> treesit-indent-region(1 1214226) >> indent-region(1 1214226) >> indent-for-tab-command(nil) >> funcall-interactively(indent-for-tab-command nil) >> call-interactively(indent-for-tab-command nil nil) >> command-execute(indent-for-tab-command) > > Thank you for your report. > > Yuan and Theo, could you please look into this? I briefly stepped > through the code involved in the problem, and it sounds like it makes > some assumptions regarding the nodes which are not necessarily true in > Real Life. c-ts-mode from the tip of the emacs-29 branch can indent xdisp.c without failures if I apply the patch from bug#61691 and the patch attached to this email message. It is very slow, though, compared to c-mode. I have a very fast machine and it took around 10 minutes to indent the whole file, while c-mode indented the file in 30-40 seconds. I guess the algorithm in treesit-indent-region doesn't scale very well for very big files like xdisp.c. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Check-the-anchor-along-with-the-offset-in-treesit-in.patch >From d082bfb92a17f3968910182009939300ed51a3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Sat, 25 Feb 2023 03:07:55 +0100 Subject: [PATCH] Check the anchor along with the offset in treesit-indent-region * lisp/treesit.el (treesit-indent-region): To compute a valid column, having a non-nil offset is not enough, we need a non-nil anchor as well. --- lisp/treesit.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 045fdf21cba..1decfc3d7cf 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1533,7 +1533,7 @@ treesit-indent-region (dotimes (jdx idx) (let ((anchor (aref meta-vec (* jdx meta-len))) (offset (aref meta-vec (+ 1 (* jdx meta-len))))) - (when offset + (when (and anchor offset) (let ((col (save-excursion (goto-char anchor) (+ offset (current-column))))) -- 2.34.1 --=-=-=--