From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii 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:05:29 +0200 Message-ID: <83ilhr4i7a.fsf@gnu.org> References: <87wn67sjnw.fsf@gmail.com> <83lemn4jh8.fsf@gnu.org> <87r0wf7bm4.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1425"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60453@debbugs.gnu.org To: Wilhelm Kirschbaum Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 31 18:06:19 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 1pBfJJ-000064-1p for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 31 Dec 2022 18:06:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBfJ6-0002VL-3U; Sat, 31 Dec 2022 12:06: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 1pBfJ4-0002Un-TP for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2022 12:06: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 1pBfJ4-0004uG-Bl for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2022 12:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pBfJ4-0008Ao-7V for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2022 12:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Dec 2022 17:06: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.167250633631384 (code B ref 60453); Sat, 31 Dec 2022 17:06:02 +0000 Original-Received: (at 60453) by debbugs.gnu.org; 31 Dec 2022 17:05:36 +0000 Original-Received: from localhost ([127.0.0.1]:39740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBfIe-0008A8-56 for submit@debbugs.gnu.org; Sat, 31 Dec 2022 12:05:36 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41078) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBfIc-00089s-38 for 60453@debbugs.gnu.org; Sat, 31 Dec 2022 12:05:34 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBfIW-0003zu-Mm; Sat, 31 Dec 2022 12:05:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=EqLZdkQa6kk4DPiaBPk6QWiOKjzeAJ8C5/n0nRYbEkI=; b=j84VvzbeeI0BSwi8QeHi OITmADJTiM9EnwHP22SQkGBiHAH/PgSKE8doQ+v8YdaGbBTMazIU9LzWDnXzee2zf/2EGlhnrGINl /p1FTyUqCkoYco+2iNYF1tSmwWLgaNjBM6pXgigCPNB0YlHBuqjcWBUipxWZkfNTWFjrs034iIviK 7xsaGxy+F7mUWqUyUxbJR6OiaPPQIZt0AAxs16BXpn2nRnPtvhyOvDy0/sw2nh8qIZgBTKtMuLBo0 iik07DAfQuIcv2r+ipw2vVloaVL2Mtdtc8QtI3/nksSBnQKs07F38QNkNJKmW/9EzE39Sx0NfQAjm Qegf01k5m60jSA==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBfIV-0001LU-Gw; Sat, 31 Dec 2022 12:05:28 -0500 In-Reply-To: <87r0wf7bm4.fsf@gmail.com> (message from Wilhelm Kirschbaum on Sat, 31 Dec 2022 18:50:31 +0200) 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:252207 Archived-At: > From: Wilhelm Kirschbaum > Cc: 60453@debbugs.gnu.org > Date: Sat, 31 Dec 2022 18:50:31 +0200 > > > Eli Zaretskii writes: > > >> From: Wilhelm Kirschbaum > >> Date: Sat, 31 Dec 2022 16:53:08 +0200 > >> > >> > >> With the following code without tree-sitter library: > >> > >> (defvar elixir-ts-mode--treesit-range-rules > >> (treesit-range-rules > >> :embed 'heex > >> :host 'elixir > >> '((sigil (sigil_name) @name (:match "^[H]$" @name) > >> (quoted_content) > >> @heex)))) > >> > >> upon loading the mode I get the following error: > >> > >> treesit-range-rules: Symbol’s function definition is void: > >> treesit-query-compile > >> > >> This can easily be mitigated with (when > >> (treesit-available-p)...) > >> but think it should function similar to how > >> (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 > > functions > > when the tree-sitter library is not available. IOW, Lisp > > programs > > that want to use treesit-range-rules and other functions from > > treesit.el should make the treesit-available-p test _before_ > > that. > > Okay, that makes sense. I just saw this comment on > > ;; 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 > compiled. > ;; But this function is usually call in `defvar' which runs > ;; regardless whether tree-sitter is enabled. So we need this > ;; guard. > (when (treesit-available-p) > > As treesit-range-rules also gets called with defvar and it is a > consistency issue. I think the reason why this has not popped up > before is that no other modes I have seen uses treesit-range-rules > yet and think it will probably catch people off guard in the future. It's up to Yuan: if he thinks this is a good idea, he should feel free to add that test. But it's slippery slope, IMNSHO: we will very soon find ourselves adding such tests to every treesit.el function, just because some code somewhere calls that function without a prior test. IOW, IMO a single case of such callers is not enough to add a test. But that's me.