aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-01-19 22:20:23 +0800
committerPo Lu2023-01-19 22:20:23 +0800
commitf99f7599315bb11531d49fc6483f4d64242f6903 (patch)
tree7bc00126967e37cea6c8223fc27e1cabfd6be10e /src
parenta496509cedb17109d0e6297a74e2ff8ed526333c (diff)
parent9161a302c9f9fbfa1a8f33181bb332d2c5df3aa7 (diff)
downloademacs-f99f7599315bb11531d49fc6483f4d64242f6903.tar.gz
emacs-f99f7599315bb11531d49fc6483f4d64242f6903.zip
Merge remote-tracking branch 'origin/master' into feature/android
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c10
-rw-r--r--src/treesit.c66
-rw-r--r--src/xterm.c2
3 files changed, 54 insertions, 24 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 100e42fc1f9..88ca69b0dd8 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -525,14 +525,14 @@ get_truename_buffer (register Lisp_Object filename)
525 return Qnil; 525 return Qnil;
526} 526}
527 527
528/* Run buffer-list-update-hook if Vrun_hooks is non-nil, and BUF is NULL 528/* Run buffer-list-update-hook if Vrun_hooks is non-nil and BUF does
529 or does not have buffer hooks inhibited. BUF is NULL when called by 529 not have buffer hooks inhibited. */
530 make-indirect-buffer, since it does not inhibit buffer hooks. */
531 530
532static void 531static void
533run_buffer_list_update_hook (struct buffer *buf) 532run_buffer_list_update_hook (struct buffer *buf)
534{ 533{
535 if (! (NILP (Vrun_hooks) || (buf && buf->inhibit_buffer_hooks))) 534 eassert (buf);
535 if (! (NILP (Vrun_hooks) || buf->inhibit_buffer_hooks))
536 call1 (Vrun_hooks, Qbuffer_list_update_hook); 536 call1 (Vrun_hooks, Qbuffer_list_update_hook);
537} 537}
538 538
@@ -907,7 +907,7 @@ does not run the hooks `kill-buffer-hook',
907 set_buffer_internal_1 (old_b); 907 set_buffer_internal_1 (old_b);
908 } 908 }
909 909
910 run_buffer_list_update_hook (NULL); 910 run_buffer_list_update_hook (b);
911 911
912 return buf; 912 return buf;
913} 913}
diff --git a/src/treesit.c b/src/treesit.c
index 3886fed346e..917db582676 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -42,8 +42,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
42#undef ts_node_end_byte 42#undef ts_node_end_byte
43#undef ts_node_eq 43#undef ts_node_eq
44#undef ts_node_field_name_for_child 44#undef ts_node_field_name_for_child
45#undef ts_node_first_child_for_byte
46#undef ts_node_first_named_child_for_byte
47#undef ts_node_has_error 45#undef ts_node_has_error
48#undef ts_node_is_extra 46#undef ts_node_is_extra
49#undef ts_node_is_missing 47#undef ts_node_is_missing
@@ -99,8 +97,6 @@ DEF_DLL_FN (TSNode, ts_node_descendant_for_byte_range,
99DEF_DLL_FN (uint32_t, ts_node_end_byte, (TSNode)); 97DEF_DLL_FN (uint32_t, ts_node_end_byte, (TSNode));
100DEF_DLL_FN (bool, ts_node_eq, (TSNode, TSNode)); 98DEF_DLL_FN (bool, ts_node_eq, (TSNode, TSNode));
101DEF_DLL_FN (const char *, ts_node_field_name_for_child, (TSNode, uint32_t)); 99DEF_DLL_FN (const char *, ts_node_field_name_for_child, (TSNode, uint32_t));
102DEF_DLL_FN (TSNode, ts_node_first_child_for_byte, (TSNode, uint32_t));
103DEF_DLL_FN (TSNode, ts_node_first_named_child_for_byte, (TSNode, uint32_t));
104DEF_DLL_FN (bool, ts_node_has_error, (TSNode)); 100DEF_DLL_FN (bool, ts_node_has_error, (TSNode));
105DEF_DLL_FN (bool, ts_node_is_extra, (TSNode)); 101DEF_DLL_FN (bool, ts_node_is_extra, (TSNode));
106DEF_DLL_FN (bool, ts_node_is_missing, (TSNode)); 102DEF_DLL_FN (bool, ts_node_is_missing, (TSNode));
@@ -174,8 +170,6 @@ init_treesit_functions (void)
174 LOAD_DLL_FN (library, ts_node_end_byte); 170 LOAD_DLL_FN (library, ts_node_end_byte);
175 LOAD_DLL_FN (library, ts_node_eq); 171 LOAD_DLL_FN (library, ts_node_eq);
176 LOAD_DLL_FN (library, ts_node_field_name_for_child); 172 LOAD_DLL_FN (library, ts_node_field_name_for_child);
177 LOAD_DLL_FN (library, ts_node_first_child_for_byte);
178 LOAD_DLL_FN (library, ts_node_first_named_child_for_byte);
179 LOAD_DLL_FN (library, ts_node_has_error); 173 LOAD_DLL_FN (library, ts_node_has_error);
180 LOAD_DLL_FN (library, ts_node_is_extra); 174 LOAD_DLL_FN (library, ts_node_is_extra);
181 LOAD_DLL_FN (library, ts_node_is_missing); 175 LOAD_DLL_FN (library, ts_node_is_missing);
@@ -232,8 +226,6 @@ init_treesit_functions (void)
232#define ts_node_end_byte fn_ts_node_end_byte 226#define ts_node_end_byte fn_ts_node_end_byte
233#define ts_node_eq fn_ts_node_eq 227#define ts_node_eq fn_ts_node_eq
234#define ts_node_field_name_for_child fn_ts_node_field_name_for_child 228#define ts_node_field_name_for_child fn_ts_node_field_name_for_child
235#define ts_node_first_child_for_byte fn_ts_node_first_child_for_byte
236#define ts_node_first_named_child_for_byte fn_ts_node_first_named_child_for_byte
237#define ts_node_has_error fn_ts_node_has_error 229#define ts_node_has_error fn_ts_node_has_error
238#define ts_node_is_extra fn_ts_node_is_extra 230#define ts_node_is_extra fn_ts_node_is_extra
239#define ts_node_is_missing fn_ts_node_is_missing 231#define ts_node_is_missing fn_ts_node_is_missing
@@ -2095,6 +2087,41 @@ return nil. */)
2095 return make_treesit_node (XTS_NODE (node)->parser, sibling); 2087 return make_treesit_node (XTS_NODE (node)->parser, sibling);
2096} 2088}
2097 2089
2090/* Our reimplementation of ts_node_first_child_for_byte. The current
2091 implementation of that function has problems (see bug#60127), so
2092 before it's fixed upstream, we use our own reimplementation of it.
2093 Return true if there is a valid sibling, return false otherwise.
2094 If the return value is false, the position of the cursor is
2095 undefined. (We use cursor because technically we can't make a null
2096 node for ourselves, also, using cursor is more convenient.)
2097
2098 TODO: Remove this function once tree-sitter fixed the bug. */
2099static bool treesit_cursor_first_child_for_byte
2100(TSTreeCursor *cursor, ptrdiff_t pos, bool named)
2101{
2102 if (!ts_tree_cursor_goto_first_child (cursor))
2103 return false;
2104
2105 TSNode node = ts_tree_cursor_current_node (cursor);
2106 while (ts_node_end_byte (node) <= pos)
2107 {
2108 if (ts_tree_cursor_goto_next_sibling (cursor))
2109 node = ts_tree_cursor_current_node (cursor);
2110 else
2111 /* Reached the end and still can't find a valid sibling. */
2112 return false;
2113 }
2114 while (named && (!ts_node_is_named (node)))
2115 {
2116 if (ts_tree_cursor_goto_next_sibling (cursor))
2117 node = ts_tree_cursor_current_node (cursor);
2118 else
2119 /* Reached the end and still can't find a named sibling. */
2120 return false;
2121 }
2122 return true;
2123}
2124
2098DEFUN ("treesit-node-first-child-for-pos", 2125DEFUN ("treesit-node-first-child-for-pos",
2099 Ftreesit_node_first_child_for_pos, 2126 Ftreesit_node_first_child_for_pos,
2100 Streesit_node_first_child_for_pos, 2, 3, 0, 2127 Streesit_node_first_child_for_pos, 2, 3, 0,
@@ -2119,16 +2146,17 @@ Note that this function returns an immediate child, not the smallest
2119 2146
2120 ptrdiff_t byte_pos = buf_charpos_to_bytepos (buf, XFIXNUM (pos)); 2147 ptrdiff_t byte_pos = buf_charpos_to_bytepos (buf, XFIXNUM (pos));
2121 TSNode treesit_node = XTS_NODE (node)->node; 2148 TSNode treesit_node = XTS_NODE (node)->node;
2122 TSNode child;
2123 if (NILP (named))
2124 child = ts_node_first_child_for_byte (treesit_node, byte_pos - visible_beg);
2125 else
2126 child = ts_node_first_named_child_for_byte (treesit_node,
2127 byte_pos - visible_beg);
2128 2149
2129 if (ts_node_is_null (child)) 2150 TSTreeCursor cursor = ts_tree_cursor_new (treesit_node);
2130 return Qnil; 2151 ptrdiff_t treesit_pos = byte_pos - visible_beg;
2152 bool success;
2153 success = treesit_cursor_first_child_for_byte (&cursor, treesit_pos,
2154 !NILP (named));
2155 TSNode child = ts_tree_cursor_current_node (&cursor);
2156 ts_tree_cursor_delete (&cursor);
2131 2157
2158 if (!success)
2159 return Qnil;
2132 return make_treesit_node (XTS_NODE (node)->parser, child); 2160 return make_treesit_node (XTS_NODE (node)->parser, child);
2133} 2161}
2134 2162
@@ -3270,9 +3298,9 @@ a regexp. */)
3270 3298
3271 Lisp_Object parser = XTS_NODE (root)->parser; 3299 Lisp_Object parser = XTS_NODE (root)->parser;
3272 Lisp_Object parent = Fcons (Qnil, Qnil); 3300 Lisp_Object parent = Fcons (Qnil, Qnil);
3273 TSTreeCursor cursor; 3301 /* In this function we never traverse above NODE, so we don't need
3274 if (!treesit_cursor_helper (&cursor, XTS_NODE (root)->node, parser)) 3302 to use treesit_cursor_helper. */
3275 return Qnil; 3303 TSTreeCursor cursor = ts_tree_cursor_new (XTS_NODE (root)->node);
3276 3304
3277 treesit_build_sparse_tree (&cursor, parent, predicate, process_fn, 3305 treesit_build_sparse_tree (&cursor, parent, predicate, process_fn,
3278 the_limit, parser); 3306 the_limit, parser);
diff --git a/src/xterm.c b/src/xterm.c
index 1373045393a..1325d923be9 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -24483,6 +24483,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
24483 } 24483 }
24484 } 24484 }
24485 24485
24486#ifndef HAVE_EXT_TOOL_BAR
24486 /* Now see if the touchpoint was previously on the tool bar. 24487 /* Now see if the touchpoint was previously on the tool bar.
24487 If it was, release the tool bar. */ 24488 If it was, release the tool bar. */
24488 24489
@@ -24507,6 +24508,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
24507 /* Now clear the tool bar device. */ 24508 /* Now clear the tool bar device. */
24508 FRAME_OUTPUT_DATA (f)->tool_bar_touch_device = 0; 24509 FRAME_OUTPUT_DATA (f)->tool_bar_touch_device = 0;
24509 } 24510 }
24511#endif
24510 24512
24511 goto XI_OTHER; 24513 goto XI_OTHER;
24512 } 24514 }