* bug#74612: 30.0.90; [PATCH] Allow passing nil to treesit-node-match-p
@ 2024-11-30 0:38 Yuan Fu
2024-11-30 7:22 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2024-11-30 0:38 UTC (permalink / raw)
To: 74612
[-- Attachment #1: Type: text/plain, Size: 164 bytes --]
Eli, are you ok with this patch on emacs-30? Almost all tree-sitter node functions allows user to pass nil for NODE, so treesit-node-match-p should too.
Yuan
[-- Attachment #2: treesit-node-match-p.patch --]
[-- Type: application/octet-stream, Size: 1301 bytes --]
From 9ab20d03e30e46e2b8502877de68eec0b511d3da Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Fri, 29 Nov 2024 16:33:28 -0800
Subject: [PATCH] Allow passing nil to treesit-node-match-p
* src/treesit.c (Ftreesit_node_match_p): Return nil if NODE is nil.
---
src/treesit.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/treesit.c b/src/treesit.c
index 4031d80f7c9..cda6d4af2ee 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -4017,7 +4017,8 @@ DEFUN ("treesit-node-match-p",
`treesit-thing-settings', or a predicate, like regexp matching node
type, etc. See `treesit-thing-settings' for more details.
-Return non-nil if NODE matches PREDICATE, nil otherwise.
+Return non-nil if NODE matches PREDICATE, nil otherwise. If NODE is
+nil, return nil.
Signals `treesit-invalid-predicate' if there's no definition of THING
in `treesit-thing-settings', or if PREDICATE is malformed. If
@@ -4025,6 +4026,8 @@ DEFUN ("treesit-node-match-p",
definition, but still signal for malformed PREDICATE. */)
(Lisp_Object node, Lisp_Object predicate, Lisp_Object ignore_missing)
{
+ if (NILP (node)) return Qnil;
+
CHECK_TS_NODE (node);
Lisp_Object parser = XTS_NODE (node)->parser;
--
2.39.5 (Apple Git-151)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#74612: 30.0.90; [PATCH] Allow passing nil to treesit-node-match-p
2024-11-30 0:38 bug#74612: 30.0.90; [PATCH] Allow passing nil to treesit-node-match-p Yuan Fu
@ 2024-11-30 7:22 ` Eli Zaretskii
2024-12-01 8:31 ` Yuan Fu
0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-11-30 7:22 UTC (permalink / raw)
To: Yuan Fu; +Cc: 74612
> From: Yuan Fu <casouri@gmail.com>
> Date: Fri, 29 Nov 2024 16:38:22 -0800
>
> Eli, are you ok with this patch on emacs-30? Almost all tree-sitter node functions allows user to pass nil for NODE, so treesit-node-match-p should too.
Does this solve an actual problem you've seen somewhere (and if so,
which problem), or does it solve a potential problem that didn't
actually happen yet?
Also, does CHECK_TS_NODE allow nil or does it currently signal an
error?
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#74612: 30.0.90; [PATCH] Allow passing nil to treesit-node-match-p
2024-11-30 7:22 ` Eli Zaretskii
@ 2024-12-01 8:31 ` Yuan Fu
2024-12-01 9:59 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2024-12-01 8:31 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 74612
> On Nov 29, 2024, at 11:22 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Fri, 29 Nov 2024 16:38:22 -0800
>>
>> Eli, are you ok with this patch on emacs-30? Almost all tree-sitter node functions allows user to pass nil for NODE, so treesit-node-match-p should too.
>
> Does this solve an actual problem you've seen somewhere (and if so,
> which problem), or does it solve a potential problem that didn't
> actually happen yet?
I encountered this problem (more like an inconvenience, since without this feature I’d need to test for nullness before passing a node to treesit-node-match-p) when using treesit-node-match-p for some new code I’m writing for master branch. Since (treesit-node-match-p node “type name”) is easier to write and shorter than (equal (treesit-node-type node) “type name”) or (string-match-p “type name regex” (treesit-node-type node)), I’ve been using it liberally in new code :)
>
> Also, does CHECK_TS_NODE allow nil or does it currently signal an
> error?
CHECK_TS_NODE currently signals an error. All the tree-sitter node functions that accepts nil has the "if (NILP (node)) return Qnil” line before CHECK_TS_NODE (or treesit_check_node)
If you’re not too comfortable with the change, we can apply it to master. It wouldn’t create any backward-incompatibility since this change makes treesit-node-match-p more lenient on its argument, not stricter. The drawback is treesit-node-match-p will be a bit more annoying to use.
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#74612: 30.0.90; [PATCH] Allow passing nil to treesit-node-match-p
2024-12-01 8:31 ` Yuan Fu
@ 2024-12-01 9:59 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-12-01 9:59 UTC (permalink / raw)
To: Yuan Fu; +Cc: 74612
> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 1 Dec 2024 00:31:05 -0800
> Cc: 74612@debbugs.gnu.org
>
>
>
> > On Nov 29, 2024, at 11:22 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> >> From: Yuan Fu <casouri@gmail.com>
> >> Date: Fri, 29 Nov 2024 16:38:22 -0800
> >>
> >> Eli, are you ok with this patch on emacs-30? Almost all tree-sitter node functions allows user to pass nil for NODE, so treesit-node-match-p should too.
> >
> > Does this solve an actual problem you've seen somewhere (and if so,
> > which problem), or does it solve a potential problem that didn't
> > actually happen yet?
>
> I encountered this problem (more like an inconvenience, since without this feature I’d need to test for nullness before passing a node to treesit-node-match-p) when using treesit-node-match-p for some new code I’m writing for master branch. Since (treesit-node-match-p node “type name”) is easier to write and shorter than (equal (treesit-node-type node) “type name”) or (string-match-p “type name regex” (treesit-node-type node)), I’ve been using it liberally in new code :)
>
> >
> > Also, does CHECK_TS_NODE allow nil or does it currently signal an
> > error?
>
> CHECK_TS_NODE currently signals an error. All the tree-sitter node functions that accepts nil has the "if (NILP (node)) return Qnil” line before CHECK_TS_NODE (or treesit_check_node)
>
> If you’re not too comfortable with the change, we can apply it to master. It wouldn’t create any backward-incompatibility since this change makes treesit-node-match-p more lenient on its argument, not stricter. The drawback is treesit-node-match-p will be a bit more annoying to use.
OK, please install on emacs-30, and thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-01 9:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 0:38 bug#74612: 30.0.90; [PATCH] Allow passing nil to treesit-node-match-p Yuan Fu
2024-11-30 7:22 ` Eli Zaretskii
2024-12-01 8:31 ` Yuan Fu
2024-12-01 9:59 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).