From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Wilhelm Kirschbaum Newsgroups: gmane.emacs.bugs Subject: bug#60453: 29.0.60; treesit-range-rules throw an error without tree-sitter Date: Sat, 31 Dec 2022 19:08:19 +0200 Message-ID: <87mt737abd.fsf@gmail.com> References: <87wn67sjnw.fsf@gmail.com> <83lemn4jh8.fsf@gnu.org> <87r0wf7bm4.fsf@gmail.com> <83ilhr4i7a.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22122"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.3; emacs 29.0.60 Cc: 60453@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 31 18:28:18 2022 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 1pBfec-0005bA-Mf for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 31 Dec 2022 18:28:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBfeP-0005TM-7F; Sat, 31 Dec 2022 12:28:05 -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 1pBfeN-0005TD-Ch for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2022 12:28:03 -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 1pBfeN-0002C2-1d for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2022 12:28:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pBfeM-0000FS-Jc for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2022 12:28:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Wilhelm Kirschbaum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Dec 2022 17:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60453 X-GNU-PR-Package: emacs Original-Received: via spool by 60453-submit@debbugs.gnu.org id=B60453.1672507667932 (code B ref 60453); Sat, 31 Dec 2022 17:28:02 +0000 Original-Received: (at 60453) by debbugs.gnu.org; 31 Dec 2022 17:27:47 +0000 Original-Received: from localhost ([127.0.0.1]:39750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBfe6-0000Ew-KX for submit@debbugs.gnu.org; Sat, 31 Dec 2022 12:27:46 -0500 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:54067) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBfe4-0000Ei-IV for 60453@debbugs.gnu.org; Sat, 31 Dec 2022 12:27:45 -0500 Original-Received: by mail-wm1-f49.google.com with SMTP id ja17so17545697wmb.3 for <60453@debbugs.gnu.org>; Sat, 31 Dec 2022 09:27:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=zjQwGg3Y+2hIK/RHI/OzehgknmUKHOZGrGBul5gOYaM=; b=L6qbTf9yThfeLHA68kvSQn1cwDu7xDwvSmq+b7enaUnLPA89aHGEgfhQlszYP7vuP5 msDMSzigAa7Qa5/oYFjQgh6X5JB8ThXOIoxcZuReSxwmsLMq+X0c7dXv8xEEd0bHEaBN cBUSQSjbV/S2KJ6Jrcin29s0H4jzIAdSt1aR0qlcYRUj9jWhM5CS834S/LLj51xPb2tm buF9nrAU8yMd1WDxmiNFvsxf+TooQyh54uZWMelTxi06iqNRr6ll4x563TQg+ExGLMDT up4lSihscftzVw0hM4hT8SsgNF1M9re3I+6aeMFChb73lkDy3CMqGa4asl9GforWYbXr baLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=zjQwGg3Y+2hIK/RHI/OzehgknmUKHOZGrGBul5gOYaM=; b=keydFNaRZtbYKwsb5QcGvnr0BJ2cd62KmC5k/GGqCDMT+vUkv4Js3yaCZ5LKafA5j4 P/ZHUjC1r7clfydOIKHR9Lczx/aCXaB/38Ef44G0nAXmfryEIdvlJj4DmqtJHPI67zUV ULgFaev3Y7SBy0HJtjfzLb2GLpbf/N78iFhZ2/BCFq/9AB8ziLqfwatVL650zwy+uoxh HI4d/tUh7AmcMMb4WeF8GLlAeHOULrz4uCpIjVZydPxxcg719F9DyLPeXl9qgiJo2/y6 8WZcvUeI95HooOY9CiCIpeGPcKp7fATdgPPXxD9kElm63aoHyGVxed0TNwqY5WV/bTbr zSnA== X-Gm-Message-State: AFqh2kp5eVG4wGJlwvVT7D6iPngRkNxOwOswIQoDDcz1xBYgunI1q9Ze BgooFmEfii8830Ny+ID1dDlD1DdWrV8= X-Google-Smtp-Source: AMrXdXun7QH4/aaH+SJFRtCWMyythnAKkjy3MOO5wvJH2FLmJKxzE54Dlk2D5ygdC3HTQcen8JRo8A== X-Received: by 2002:a05:600c:601e:b0:3c6:e61e:ae71 with SMTP id az30-20020a05600c601e00b003c6e61eae71mr30967104wmb.1.1672507658369; Sat, 31 Dec 2022 09:27:38 -0800 (PST) Original-Received: from melissa.local ([2c0f:ef18:1431:0:b09:9616:db04:c248]) by smtp.gmail.com with ESMTPSA id t184-20020a1c46c1000000b003b4a699ce8esm36912179wma.6.2022.12.31.09.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Dec 2022 09:27:37 -0800 (PST) In-reply-to: <83ilhr4i7a.fsf@gnu.org> 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:252209 Archived-At: Eli Zaretskii writes: >> From: Wilhelm Kirschbaum >> Cc: 60453@debbugs.gnu.org >> Date: Sat, 31 Dec 2022 18:50:31 +0200 >>=20 >>=20 >> Eli Zaretskii writes: >>=20 >> >> From: Wilhelm Kirschbaum >> >> Date: Sat, 31 Dec 2022 16:53:08 +0200 >> >>=20 >> >>=20 >> >> With the following code without tree-sitter library: >> >>=20 >> >> (defvar elixir-ts-mode--treesit-range-rules >> >> (treesit-range-rules >> >> :embed 'heex >> >> :host 'elixir >> >> '((sigil (sigil_name) @name (:match "^[H]$" @name)=20 >> >> (quoted_content) >> >> @heex)))) >> >>=20 >> >> upon loading the mode I get the following error: >> >>=20 >> >> treesit-range-rules: Symbol=E2=80=99s function definition is void: >> >> treesit-query-compile >> >>=20 >> >> This can easily be mitigated with (when=20 >> >> (treesit-available-p)...) >> >> but think it should function similar to how=20 >> >> (treesit-font-lock-rules >> >> work. >> > >> > Why does it make sense to protect treesit.el's code with >> > treesit-available-p? You aren't supposed to use treesit.el=20 >> > functions >> > when the tree-sitter library is not available. IOW, Lisp=20 >> > programs >> > that want to use treesit-range-rules and other functions from >> > treesit.el should make the treesit-available-p test _before_=20 >> > that. >>=20 >> Okay, that makes sense. I just saw this comment on >>=20 >> ;; treesit.el#618 >> (defun treesit-font-lock-rules (&rest query-specs) >> ... >> ;; Other tree-sitter function don't tend to be called unless >> ;; tree-sitter is enabled, which means tree-sitter must be=20 >> compiled. >> ;; But this function is usually call in `defvar' which runs >> ;; regardless whether tree-sitter is enabled. So we need=20 >> this >> ;; guard. >> (when (treesit-available-p) >>=20 >> As treesit-range-rules also gets called with defvar and it is a >> consistency issue. I think the reason why this has not popped=20 >> up >> before is that no other modes I have seen uses=20 >> treesit-range-rules >> yet and think it will probably catch people off guard in the=20 >> future. > > It's up to Yuan: if he thinks this is a good idea, he should=20 > feel free > to add that test. But it's slippery slope, IMNSHO: we will very=20 > soon > find ourselves adding such tests to every treesit.el function,=20 > just > because some code somewhere calls that function without a prior=20 > test. > IOW, IMO a single case of such callers is not enough to add a=20 > test. > But that's me. Okay, I will add the checks before defvar anyways to keep things consistent on my side. It does make more sense to me just to not=20 have the guards in the first place as it creates false expectation they=20 will be everywhere.