Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/editors/emacs/files/patch-src_treesit.c
46591 views
1
--- src/treesit.c.orig 2025-07-05 09:56:00 UTC
2
+++ src/treesit.c
3
@@ -415,17 +415,17 @@ static Lisp_Object Vtreesit_str_plus;
4
static Lisp_Object Vtreesit_str_question_mark;
5
static Lisp_Object Vtreesit_str_star;
6
static Lisp_Object Vtreesit_str_plus;
7
-static Lisp_Object Vtreesit_str_pound_equal;
8
-static Lisp_Object Vtreesit_str_pound_match;
9
-static Lisp_Object Vtreesit_str_pound_pred;
10
+static Lisp_Object Vtreesit_str_pound_eq_question_mark;
11
+static Lisp_Object Vtreesit_str_pound_match_question_mark;
12
+static Lisp_Object Vtreesit_str_pound_pred_question_mark;
13
static Lisp_Object Vtreesit_str_open_bracket;
14
static Lisp_Object Vtreesit_str_close_bracket;
15
static Lisp_Object Vtreesit_str_open_paren;
16
static Lisp_Object Vtreesit_str_close_paren;
17
static Lisp_Object Vtreesit_str_space;
18
-static Lisp_Object Vtreesit_str_equal;
19
-static Lisp_Object Vtreesit_str_match;
20
-static Lisp_Object Vtreesit_str_pred;
21
+static Lisp_Object Vtreesit_str_eq_question_mark;
22
+static Lisp_Object Vtreesit_str_match_question_mark;
23
+static Lisp_Object Vtreesit_str_pred_question_mark;
24
static Lisp_Object Vtreesit_str_empty;
25
26
/* This is the limit on recursion levels for some tree-sitter
27
@@ -632,6 +632,22 @@ treesit_load_language_push_for_each_suffix (Lisp_Objec
28
}
29
}
30
31
+/* This function is a compatibility shim. Tree-sitter 0.25 introduced
32
+ ts_language_abi_version as a replacement for ts_language_version, and
33
+ tree-sitter 0.26 removed ts_language_version. Here we use the fact
34
+ that 0.25 bumped TREE_SITTER_LANGUAGE_VERSION to 15, to use the new
35
+ function instead of the old one, when Emacs is compiled against
36
+ tree-sitter version 0.25 or newer. */
37
+static uint32_t
38
+treesit_language_abi_version (const TSLanguage *ts_lang)
39
+{
40
+#if TREE_SITTER_LANGUAGE_VERSION >= 15
41
+ return ts_language_abi_version (ts_lang);
42
+#else
43
+ return ts_language_version (ts_lang);
44
+#endif
45
+}
46
+
47
/* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer
48
to the language definition.
49
50
@@ -746,7 +762,7 @@ treesit_load_language (Lisp_Object language_symbol,
51
{
52
*signal_symbol = Qtreesit_load_language_error;
53
*signal_data = list2 (Qversion_mismatch,
54
- make_fixnum (ts_language_version (lang)));
55
+ make_fixnum (treesit_language_abi_version (lang)));
56
return NULL;
57
}
58
return lang;
59
@@ -817,7 +833,7 @@ Return nil if a grammar library for LANGUAGE is not av
60
&signal_data);
61
if (ts_language == NULL)
62
return Qnil;
63
- uint32_t version = ts_language_version (ts_language);
64
+ uint32_t version = treesit_language_abi_version (ts_language);
65
return make_fixnum((ptrdiff_t) version);
66
}
67
}
68
@@ -2604,12 +2620,12 @@ See Info node `(elisp)Pattern Matching' for detailed e
69
return Vtreesit_str_star;
70
if (BASE_EQ (pattern, QCplus))
71
return Vtreesit_str_plus;
72
- if (BASE_EQ (pattern, QCequal))
73
- return Vtreesit_str_pound_equal;
74
- if (BASE_EQ (pattern, QCmatch))
75
- return Vtreesit_str_pound_match;
76
- if (BASE_EQ (pattern, QCpred))
77
- return Vtreesit_str_pound_pred;
78
+ if (BASE_EQ (pattern, QCequal) || BASE_EQ (pattern, QCeq_q))
79
+ return Vtreesit_str_pound_eq_question_mark;
80
+ if (BASE_EQ (pattern, QCmatch) || BASE_EQ (pattern, QCmatch_q))
81
+ return Vtreesit_str_pound_match_question_mark;
82
+ if (BASE_EQ (pattern, QCpred) || BASE_EQ (pattern, QCpred_q))
83
+ return Vtreesit_str_pound_pred_question_mark;
84
Lisp_Object opening_delimeter
85
= VECTORP (pattern)
86
? Vtreesit_str_open_bracket : Vtreesit_str_open_paren;
87
@@ -2640,7 +2656,9 @@ A PATTERN in QUERY can be
88
:*
89
:+
90
:equal
91
+ :eq?
92
:match
93
+ :match?
94
(TYPE PATTERN...)
95
[PATTERN...]
96
FIELD-NAME:
97
@@ -2803,7 +2821,7 @@ treesit_predicate_equal (Lisp_Object args, struct capt
98
return !NILP (Fstring_equal (text1, text2));
99
}
100
101
-/* Handles predicate (#match "regexp" @node). Return true if "regexp"
102
+/* Handles predicate (#match? "regexp" @node). Return true if "regexp"
103
matches the text spanned by @node; return false otherwise.
104
Matching is case-sensitive. If everything goes fine, don't touch
105
SIGNAL_DATA; if error occurs, set it to a suitable signal data. */
106
@@ -2813,26 +2831,24 @@ treesit_predicate_match (Lisp_Object args, struct capt
107
{
108
if (list_length (args) != 2)
109
{
110
- *signal_data = list2 (build_string ("Predicate `match' requires two "
111
+ *signal_data = list2 (build_string ("Predicate `match?' requires two "
112
"arguments but got"),
113
Flength (args));
114
return false;
115
}
116
- Lisp_Object regexp = XCAR (args);
117
- Lisp_Object capture_name = XCAR (XCDR (args));
118
+ Lisp_Object arg1 = XCAR (args);
119
+ Lisp_Object arg2 = XCAR (XCDR (args));
120
+ Lisp_Object regexp = SYMBOLP (arg2) ? arg1 : arg2;
121
+ Lisp_Object capture_name = SYMBOLP (arg2) ? arg2 : arg1;
122
123
- /* It's probably common to get the argument order backwards. Catch
124
- this mistake early and show helpful explanation, because Emacs
125
- loves you. (We put the regexp first because that's what
126
- string-match does.) */
127
- if (!STRINGP (regexp))
128
- xsignal1 (Qtreesit_query_error,
129
- build_string ("The first argument to `match' should "
130
- "be a regexp string, not a capture name"));
131
- if (!SYMBOLP (capture_name))
132
- xsignal1 (Qtreesit_query_error,
133
- build_string ("The second argument to `match' should "
134
- "be a capture name, not a string"));
135
+ if (!STRINGP (regexp) || !SYMBOLP (capture_name))
136
+ {
137
+ *signal_data = list2 (build_string ("Predicate `match?' takes a regexp "
138
+ "and a node capture (order doesn't "
139
+ "matter), but got"),
140
+ Flength (args));
141
+ return false;
142
+ }
143
144
Lisp_Object node = Qnil;
145
if (!treesit_predicate_capture_name_to_node (capture_name, captures, &node,
146
@@ -2916,11 +2932,11 @@ treesit_eval_predicates (struct capture_range captures
147
Lisp_Object predicate = XCAR (tail);
148
Lisp_Object fn = XCAR (predicate);
149
Lisp_Object args = XCDR (predicate);
150
- if (!NILP (Fstring_equal (fn, Vtreesit_str_equal)))
151
+ if (!NILP (Fstring_equal (fn, Vtreesit_str_eq_question_mark)))
152
pass &= treesit_predicate_equal (args, captures, signal_data);
153
- else if (!NILP (Fstring_equal (fn, Vtreesit_str_match)))
154
+ else if (!NILP (Fstring_equal (fn, Vtreesit_str_match_question_mark)))
155
pass &= treesit_predicate_match (args, captures, signal_data);
156
- else if (!NILP (Fstring_equal (fn, Vtreesit_str_pred)))
157
+ else if (!NILP (Fstring_equal (fn, Vtreesit_str_pred_question_mark)))
158
pass &= treesit_predicate_pred (args, captures, signal_data);
159
else
160
{
161
@@ -4192,8 +4208,11 @@ syms_of_treesit (void)
162
DEFSYM (QCstar, ":*");
163
DEFSYM (QCplus, ":+");
164
DEFSYM (QCequal, ":equal");
165
+ DEFSYM (QCeq_q, ":eq?");
166
DEFSYM (QCmatch, ":match");
167
+ DEFSYM (QCmatch_q, ":match?");
168
DEFSYM (QCpred, ":pred");
169
+ DEFSYM (QCpred_q, ":pred?");
170
171
DEFSYM (Qnot_found, "not-found");
172
DEFSYM (Qsymbol_error, "symbol-error");
173
@@ -4324,12 +4343,12 @@ the symbol of that THING. For example, (or sexp sente
174
Vtreesit_str_star = build_pure_c_string ("*");
175
staticpro (&Vtreesit_str_plus);
176
Vtreesit_str_plus = build_pure_c_string ("+");
177
- staticpro (&Vtreesit_str_pound_equal);
178
- Vtreesit_str_pound_equal = build_pure_c_string ("#equal");
179
- staticpro (&Vtreesit_str_pound_match);
180
- Vtreesit_str_pound_match = build_pure_c_string ("#match");
181
- staticpro (&Vtreesit_str_pound_pred);
182
- Vtreesit_str_pound_pred = build_pure_c_string ("#pred");
183
+ staticpro (&Vtreesit_str_pound_eq_question_mark);
184
+ Vtreesit_str_pound_eq_question_mark = build_pure_c_string ("#eq?");
185
+ staticpro (&Vtreesit_str_pound_match_question_mark);
186
+ Vtreesit_str_pound_match_question_mark = build_pure_c_string ("#match?");
187
+ staticpro (&Vtreesit_str_pound_pred_question_mark);
188
+ Vtreesit_str_pound_pred_question_mark = build_pure_c_string ("#pred?");
189
staticpro (&Vtreesit_str_open_bracket);
190
Vtreesit_str_open_bracket = build_pure_c_string ("[");
191
staticpro (&Vtreesit_str_close_bracket);
192
@@ -4340,12 +4359,12 @@ the symbol of that THING. For example, (or sexp sente
193
Vtreesit_str_close_paren = build_pure_c_string (")");
194
staticpro (&Vtreesit_str_space);
195
Vtreesit_str_space = build_pure_c_string (" ");
196
- staticpro (&Vtreesit_str_equal);
197
- Vtreesit_str_equal = build_pure_c_string ("equal");
198
- staticpro (&Vtreesit_str_match);
199
- Vtreesit_str_match = build_pure_c_string ("match");
200
- staticpro (&Vtreesit_str_pred);
201
- Vtreesit_str_pred = build_pure_c_string ("pred");
202
+ staticpro (&Vtreesit_str_eq_question_mark);
203
+ Vtreesit_str_eq_question_mark = build_pure_c_string ("eq?");
204
+ staticpro (&Vtreesit_str_match_question_mark);
205
+ Vtreesit_str_match_question_mark = build_pure_c_string ("match?");
206
+ staticpro (&Vtreesit_str_pred_question_mark);
207
+ Vtreesit_str_pred_question_mark = build_pure_c_string ("pred?");
208
staticpro (&Vtreesit_str_empty);
209
Vtreesit_str_empty = build_pure_c_string ("");
210
211
212