diff options
| author | Stefan Kangas | 2023-01-19 06:30:25 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2023-01-19 06:30:25 +0100 |
| commit | 9161a302c9f9fbfa1a8f33181bb332d2c5df3aa7 (patch) | |
| tree | 21de62aa23f4ad770ff8afe322c0223ea7e0af76 /src | |
| parent | efb9ec11bbee3871d77dc4e9217bd9293d525d5d (diff) | |
| parent | db727873803a974ba210c4942ae7cbcc3d6268ab (diff) | |
| download | emacs-9161a302c9f9fbfa1a8f33181bb332d2c5df3aa7.tar.gz emacs-9161a302c9f9fbfa1a8f33181bb332d2c5df3aa7.zip | |
Merge from origin/emacs-29
db727873803 ruby-ts-mode: Use font-lock-constant-face for true/false/nil
819719330ad (ruby-ts--indent-rules): Add a rule for continuation of a...
94b9cbf96fb (ruby-ts--parent-call-or-bol): Handle more cases with nes...
ba33b83ce4b (ruby-ts--statement-container-regexp): Remove "parenthesi...
f2bedf695c1 ruby-ts-mode: Handle indent in parenless calls much close...
758ac5eabbe Fix split-window-below for the case when split-window-kee...
8e9783b4ce4 Rebind in read-regexp-map ‘M-c’ to ‘M-s c’ compatible wit...
78f93d92b28 * lisp/vc/vc-dir.el: Make keys ‘% m’ and ‘* %’ compatible...
dc3f85fd4b0 Use proper types for Eshell warnings
6a8338a8bc8 ; Avoid byte-compiler warning in cc-fonts.el.
9186be20aeb ; Clarify doc strings of some functions in files.el
bd5ef3ef95e Improve the documentation of 'auto-mode-alist' search
1798ff5a663 ; Fix minor mistakes in documentation
faee7e1f1bd ; * lisp/treesit.el (treesit-font-lock-fontify-region): M...
24f0dfd3731 Revert "Revert "Add c-or-c++-ts-mode (bug#59613)""
ac3bc775b6f Make it harder to misactivate tree-sitter font-lock fast ...
bdd82fa7977 ; * src/treesit.c: Remove unused boilerplate.
343b9b3dfe3 ruby-ts-mode: Obey the option ruby-method-call-indent
045404d1aac ruby-ts-mode: Obey the option ruby-after-operator-indent
300ca6ac372 ruby-ts-mode: Fix indent after operator or conditional
ac5516bd7d5 ruby-ts-mode: Fix/change indentation of a continuation me...
5e2e68a0c2d ruby-ts-mode: Fix indent inside parenthesized_expr and el...
9ed9ff4690a ruby-ts-mode: Fix the rules for hanging arrays and hashes
c4f0b6ccea1 Add more detail about how to invoke Eshell commands
dbac923b9df CC Mode: On removal of "typedef", remove pertinent types ...
56d69c2fc47 ; Relax timeouts for failing ERC test
183e7492702 Don't preserve non-module minor modes in erc-open
7b8322f6285 Use correct buffer for local-module vars in erc-open
7b13422298a ; Avoid plist-get as generalized var in erc-compat
09e9d7c7496 Fix display of warnings on w32 console
bd094207c76 Fix buffer-list-update-hook for indirect buffers
9e7a5d58eea ; Fix tree-sitter indent anchor preset
7c61a304104 Fix treesit-node-first-child-for-pos (bug#60127)
b36cc7e7bbb ; * src/treesit.c (Ftreesit_induce_sparse_tree): Minor ch...
# Conflicts:
# etc/NEWS
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.c | 10 | ||||
| -rw-r--r-- | src/treesit.c | 66 |
2 files changed, 52 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 | ||
| 532 | static void | 531 | static void |
| 533 | run_buffer_list_update_hook (struct buffer *buf) | 532 | run_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, | |||
| 99 | DEF_DLL_FN (uint32_t, ts_node_end_byte, (TSNode)); | 97 | DEF_DLL_FN (uint32_t, ts_node_end_byte, (TSNode)); |
| 100 | DEF_DLL_FN (bool, ts_node_eq, (TSNode, TSNode)); | 98 | DEF_DLL_FN (bool, ts_node_eq, (TSNode, TSNode)); |
| 101 | DEF_DLL_FN (const char *, ts_node_field_name_for_child, (TSNode, uint32_t)); | 99 | DEF_DLL_FN (const char *, ts_node_field_name_for_child, (TSNode, uint32_t)); |
| 102 | DEF_DLL_FN (TSNode, ts_node_first_child_for_byte, (TSNode, uint32_t)); | ||
| 103 | DEF_DLL_FN (TSNode, ts_node_first_named_child_for_byte, (TSNode, uint32_t)); | ||
| 104 | DEF_DLL_FN (bool, ts_node_has_error, (TSNode)); | 100 | DEF_DLL_FN (bool, ts_node_has_error, (TSNode)); |
| 105 | DEF_DLL_FN (bool, ts_node_is_extra, (TSNode)); | 101 | DEF_DLL_FN (bool, ts_node_is_extra, (TSNode)); |
| 106 | DEF_DLL_FN (bool, ts_node_is_missing, (TSNode)); | 102 | DEF_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. */ | ||
| 2099 | static 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 | |||
| 2098 | DEFUN ("treesit-node-first-child-for-pos", | 2125 | DEFUN ("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); |