aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/coding.c2
-rw-r--r--src/fns.c9
-rw-r--r--src/pgtkterm.c3
-rw-r--r--src/treesit.c24
-rw-r--r--src/treesit.h1
5 files changed, 29 insertions, 10 deletions
diff --git a/src/coding.c b/src/coding.c
index 4e59f2b6a1b..49dcd8634f3 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -1431,7 +1431,7 @@ encode_coding_utf_8 (struct coding_system *coding)
1431 ptrdiff_t produced_chars = 0; 1431 ptrdiff_t produced_chars = 0;
1432 int c; 1432 int c;
1433 1433
1434 if (CODING_UTF_8_BOM (coding) == utf_with_bom) 1434 if (CODING_UTF_8_BOM (coding) != utf_without_bom)
1435 { 1435 {
1436 ASSURE_DESTINATION (3); 1436 ASSURE_DESTINATION (3);
1437 EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3); 1437 EMIT_THREE_BYTES (UTF_8_BOM_1, UTF_8_BOM_2, UTF_8_BOM_3);
diff --git a/src/fns.c b/src/fns.c
index bbc9a7f9621..d8bd7d318b0 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -38,6 +38,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
38#include "puresize.h" 38#include "puresize.h"
39#include "gnutls.h" 39#include "gnutls.h"
40 40
41#ifdef HAVE_TREE_SITTER
42#include "treesit.h"
43#endif
44
41enum equal_kind { EQUAL_NO_QUIT, EQUAL_PLAIN, EQUAL_INCLUDING_PROPERTIES }; 45enum equal_kind { EQUAL_NO_QUIT, EQUAL_PLAIN, EQUAL_INCLUDING_PROPERTIES };
42static bool internal_equal (Lisp_Object, Lisp_Object, 46static bool internal_equal (Lisp_Object, Lisp_Object,
43 enum equal_kind, int, Lisp_Object); 47 enum equal_kind, int, Lisp_Object);
@@ -2828,6 +2832,11 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
2828 bool_vector_bytes (size))); 2832 bool_vector_bytes (size)));
2829 } 2833 }
2830 2834
2835#ifdef HAVE_TREE_SITTER
2836 if (TS_NODEP (o1))
2837 return treesit_node_eq (o1, o2);
2838#endif
2839
2831 /* Aside from them, only true vectors, char-tables, compiled 2840 /* Aside from them, only true vectors, char-tables, compiled
2832 functions, and fonts (font-spec, font-entity, font-object) 2841 functions, and fonts (font-spec, font-entity, font-object)
2833 are sensible to compare, so eliminate the others now. */ 2842 are sensible to compare, so eliminate the others now. */
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 5158492ca09..c00e13550bd 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -2959,7 +2959,8 @@ pgtk_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x,
2959 if (w == XWINDOW (f->selected_window)) 2959 if (w == XWINDOW (f->selected_window))
2960 { 2960 {
2961 int frame_x = (WINDOW_TO_FRAME_PIXEL_X (w, x) 2961 int frame_x = (WINDOW_TO_FRAME_PIXEL_X (w, x)
2962 + WINDOW_LEFT_FRINGE_WIDTH (w)); 2962 + WINDOW_LEFT_FRINGE_WIDTH (w)
2963 + WINDOW_LEFT_MARGIN_WIDTH (w));
2963 int frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, y); 2964 int frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, y);
2964 pgtk_im_set_cursor_location (f, frame_x, frame_y, 2965 pgtk_im_set_cursor_location (f, frame_x, frame_y,
2965 w->phys_cursor_width, 2966 w->phys_cursor_width,
diff --git a/src/treesit.c b/src/treesit.c
index 55463122d14..33a7e3c8528 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -2154,11 +2154,24 @@ If NODE is nil, return nil. */)
2154 return make_treesit_node (XTS_NODE (node)->parser, child); 2154 return make_treesit_node (XTS_NODE (node)->parser, child);
2155} 2155}
2156 2156
2157/* Return true if NODE1 and NODE2 are the same node. Assumes they are
2158 TS_NODE type. */
2159bool treesit_node_eq (Lisp_Object node1, Lisp_Object node2)
2160{
2161 treesit_initialize ();
2162 TSNode treesit_node_1 = XTS_NODE (node1)->node;
2163 TSNode treesit_node_2 = XTS_NODE (node2)->node;
2164 return ts_node_eq (treesit_node_1, treesit_node_2);
2165}
2166
2157DEFUN ("treesit-node-eq", 2167DEFUN ("treesit-node-eq",
2158 Ftreesit_node_eq, 2168 Ftreesit_node_eq,
2159 Streesit_node_eq, 2, 2, 0, 2169 Streesit_node_eq, 2, 2, 0,
2160 doc: /* Return non-nil if NODE1 and NODE2 are the same node. 2170 doc: /* Return non-nil if NODE1 and NODE2 refer to the same node.
2161If any one of NODE1 and NODE2 is nil, return nil. */) 2171If any one of NODE1 and NODE2 is nil, return nil.
2172This function uses the same equivalence metric as `equal', and returns
2173non-nil if NODE1 and NODE2 refer to the same node in a syntax tree
2174produced by tree-sitter. */)
2162 (Lisp_Object node1, Lisp_Object node2) 2175 (Lisp_Object node1, Lisp_Object node2)
2163{ 2176{
2164 if (NILP (node1) || NILP (node2)) 2177 if (NILP (node1) || NILP (node2))
@@ -2166,12 +2179,7 @@ If any one of NODE1 and NODE2 is nil, return nil. */)
2166 CHECK_TS_NODE (node1); 2179 CHECK_TS_NODE (node1);
2167 CHECK_TS_NODE (node2); 2180 CHECK_TS_NODE (node2);
2168 2181
2169 treesit_initialize (); 2182 bool same_node = treesit_node_eq (node1, node2);
2170
2171 TSNode treesit_node_1 = XTS_NODE (node1)->node;
2172 TSNode treesit_node_2 = XTS_NODE (node2)->node;
2173
2174 bool same_node = ts_node_eq (treesit_node_1, treesit_node_2);
2175 return same_node ? Qt : Qnil; 2183 return same_node ? Qt : Qnil;
2176} 2184}
2177 2185
diff --git a/src/treesit.h b/src/treesit.h
index 909609737d3..5382bc58817 100644
--- a/src/treesit.h
+++ b/src/treesit.h
@@ -191,6 +191,7 @@ extern bool treesit_node_uptodate_p (Lisp_Object);
191extern void treesit_delete_parser (struct Lisp_TS_Parser *); 191extern void treesit_delete_parser (struct Lisp_TS_Parser *);
192extern void treesit_delete_query (struct Lisp_TS_Query *); 192extern void treesit_delete_query (struct Lisp_TS_Query *);
193extern bool treesit_named_node_p (TSNode); 193extern bool treesit_named_node_p (TSNode);
194extern bool treesit_node_eq (Lisp_Object, Lisp_Object);
194 195
195#endif /* HAVE_TREE_SITTER */ 196#endif /* HAVE_TREE_SITTER */
196 197