From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#60453: 29.0.60; treesit-range-rules throw an error without tree-sitter Date: Sun, 1 Jan 2023 16:19:56 -0800 Message-ID: <45DCDC27-F7FF-4CEB-A667-2407CAB10321@gmail.com> References: <87wn67sjnw.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="1062"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 60453@debbugs.gnu.org To: Wilhelm Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 02 01:21:13 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 1pC8Zl-000Ack-4N for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Jan 2023 01:21:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pC8Zc-0004rz-8W; Sun, 01 Jan 2023 19:21: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 1pC8Za-0004rf-VR for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 19:21: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 1pC8Za-0007I2-MO for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 19:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pC8Za-0006Yo-AZ for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 19:21:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87wn67sjnw.fsf@gmail.com> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jan 2023 00:21: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.167261880625124 (code B ref 60453); Mon, 02 Jan 2023 00:21:02 +0000 Original-Received: (at 60453) by debbugs.gnu.org; 2 Jan 2023 00:20:06 +0000 Original-Received: from localhost ([127.0.0.1]:42021 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC8Yg-0006XA-56 for submit@debbugs.gnu.org; Sun, 01 Jan 2023 19:20:06 -0500 Original-Received: from mail-pj1-f51.google.com ([209.85.216.51]:55046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC8Ye-0006WT-54 for 60453@debbugs.gnu.org; Sun, 01 Jan 2023 19:20:04 -0500 Original-Received: by mail-pj1-f51.google.com with SMTP id o2so23024420pjh.4 for <60453@debbugs.gnu.org>; Sun, 01 Jan 2023 16:20:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=LTvUSmykm12xlo8yxZ5oTTV1JoXH16TmBuNC/vufrmc=; b=L827zgT8Z6Gd4GvClWg7QLRK8jo36ceQ5LPUCBnLOrwz+BGzf2B8qK1GrNqpsDJ+JI xMh7SJpOzFzmeowFkOeppyvHyfhKJW/EJ2eOYZJ7Abvwm6iAY2k02OM8R2ru08g4kE2a 7KBLbzovkSGNXeQqM/G4lsS4Dbhf8mlHPqYdDocEpqSLoiw4FC8umA3MdjU+xPLaxQSI tAC3vX6t2oxM3sxTvgrQ68gAbmusw+STYxKC+nUHsp/3eU8ODQdG5KG7icbEQZxKqF6X HfKei+lbc3ln8ITWWL5RuO7PVFssf40Fw5Q/RmHVyfICI2un2ZDQl0muUs4xq/bIKRv5 KUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LTvUSmykm12xlo8yxZ5oTTV1JoXH16TmBuNC/vufrmc=; b=7O9Yiub6ivx/RtnzVpi11B77vr5rfo5a7M+Z7fUnhMguO2BsvXdT7n4n6bFux+rFR/ Hptoo8b6o6DeQ9UImq+hCCo1eIaXqYtyS5VWLRPuzRMZNtsCyUgmw80cxNnYgUuJXTyt RDCq/L4b1bJ00SGnwR3LOzsnaK22w043v/F1pO7BCDKfKRAis4BZerQVlTWn+HpSh3ev X6IX6VYkrAACsMtnjay5Ifow+L73gqxmmVVCulhjlj+v6lmD6dZbhBwt3sufiRg4kxx2 LsnTo2HlL3++3mE5SWfps3d/7Xa6kZAm1NGlnPPyFngYeCIHg3TDXiE+97oB89u2H49w 3+eA== X-Gm-Message-State: AFqh2krClvVYwjODDXMw6kTJGXGrRyBbWLomoXaDXBaa79lTO7VT3LY6 v4RXYjoz9fUbyD0UcYvQ78g= X-Google-Smtp-Source: AMrXdXuKbkbMFJOfhgW9YMiekVNwtDBgEix0n7hzDjk24VOLRSCekYxRsTVvVaVS5+qoO7D/f4xJEA== X-Received: by 2002:a17:902:8ec7:b0:192:4f85:b91d with SMTP id x7-20020a1709028ec700b001924f85b91dmr46134927plo.46.1672618798420; Sun, 01 Jan 2023 16:19:58 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id p2-20020a170902c70200b001898aa48d17sm9315652plp.185.2023.01.01.16.19.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jan 2023 16:19:58 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:252296 Archived-At: Wilhelm Kirschbaum writes: > Eli Zaretskii writes: > >>> 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=E2=80=99s 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. > > 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 have > the > guards in the first place as it creates false expectation they will be > everywhere. I wonder if we should remove that guard in treesit-font-lock-rules... It looked like a good idea at the time, but now I can see it creating confusion going forward. Yuan