aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-04-26 08:48:12 +0800
committerPo Lu2023-04-26 08:48:12 +0800
commit5f389f4b634c0dff4a3684e132280775f0ad3752 (patch)
tree581b3885ed626ecff53908a99f629860d257cc7e /src
parent9043bef65f9922438a33aee0c90af8ffb266eb91 (diff)
parentd07815a7cc3540201afa06e3c80c061e9f497815 (diff)
downloademacs-5f389f4b634c0dff4a3684e132280775f0ad3752.tar.gz
emacs-5f389f4b634c0dff4a3684e132280775f0ad3752.zip
Merge remote-tracking branch 'origin/master' into feature/android
Diffstat (limited to 'src')
-rw-r--r--src/fns.c35
-rw-r--r--src/treesit.c24
2 files changed, 45 insertions, 14 deletions
diff --git a/src/fns.c b/src/fns.c
index a8ab494eb13..8891d381993 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -6145,29 +6145,40 @@ second optional argument ABSOLUTE is non-nil, the value counts the lines
6145from the absolute start of the buffer, disregarding the narrowing. */) 6145from the absolute start of the buffer, disregarding the narrowing. */)
6146 (register Lisp_Object position, Lisp_Object absolute) 6146 (register Lisp_Object position, Lisp_Object absolute)
6147{ 6147{
6148 ptrdiff_t pos, start = BEGV_BYTE; 6148 ptrdiff_t pos_byte, start_byte = BEGV_BYTE;
6149 6149
6150 if (MARKERP (position)) 6150 if (MARKERP (position))
6151 pos = marker_position (position); 6151 {
6152 /* We don't trust the byte position if the marker's buffer is
6153 not the current buffer. */
6154 if (XMARKER (position)->buffer != current_buffer)
6155 pos_byte = CHAR_TO_BYTE (marker_position (position));
6156 else
6157 pos_byte = marker_byte_position (position);
6158 }
6152 else if (NILP (position)) 6159 else if (NILP (position))
6153 pos = PT; 6160 pos_byte = PT_BYTE;
6154 else 6161 else
6155 { 6162 {
6156 CHECK_FIXNUM (position); 6163 CHECK_FIXNUM (position);
6157 pos = XFIXNUM (position); 6164 ptrdiff_t pos = XFIXNUM (position);
6165 /* Check that POSITION is valid. */
6166 if (pos < BEG || pos > Z)
6167 args_out_of_range_3 (position, make_int (BEG), make_int (Z));
6168 pos_byte = CHAR_TO_BYTE (pos);
6158 } 6169 }
6159 6170
6160 if (!NILP (absolute)) 6171 if (!NILP (absolute))
6161 start = BEG_BYTE; 6172 start_byte = BEG_BYTE;
6173 else if (NILP (absolute))
6174 pos_byte = clip_to_bounds (BEGV_BYTE, pos_byte, ZV_BYTE);
6162 6175
6163 /* Check that POSITION is in the accessible range of the buffer, or, 6176 /* Check that POSITION is valid. */
6164 if we're reporting absolute positions, in the buffer. */ 6177 if (pos_byte < BEG_BYTE || pos_byte > Z_BYTE)
6165 if (NILP (absolute) && (pos < BEGV || pos > ZV)) 6178 args_out_of_range_3 (make_int (BYTE_TO_CHAR (pos_byte)),
6166 args_out_of_range_3 (make_int (pos), make_int (BEGV), make_int (ZV)); 6179 make_int (BEG), make_int (Z));
6167 else if (!NILP (absolute) && (pos < 1 || pos > Z))
6168 args_out_of_range_3 (make_int (pos), make_int (1), make_int (Z));
6169 6180
6170 return make_int (count_lines (start, CHAR_TO_BYTE (pos)) + 1); 6181 return make_int (count_lines (start_byte, pos_byte) + 1);
6171} 6182}
6172 6183
6173 6184
diff --git a/src/treesit.c b/src/treesit.c
index cbcc688571b..ef272fb8871 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -404,6 +404,9 @@ init_treesit_functions (void)
404 404
405static Lisp_Object Vtreesit_str_libtree_sitter; 405static Lisp_Object Vtreesit_str_libtree_sitter;
406static Lisp_Object Vtreesit_str_tree_sitter; 406static Lisp_Object Vtreesit_str_tree_sitter;
407#ifndef WINDOWSNT
408static Lisp_Object Vtreesit_str_dot_0;
409#endif
407static Lisp_Object Vtreesit_str_dot; 410static Lisp_Object Vtreesit_str_dot;
408static Lisp_Object Vtreesit_str_question_mark; 411static Lisp_Object Vtreesit_str_question_mark;
409static Lisp_Object Vtreesit_str_star; 412static Lisp_Object Vtreesit_str_star;
@@ -543,8 +546,21 @@ treesit_load_language_push_for_each_suffix (Lisp_Object lib_base_name,
543 suffixes = Vdynamic_library_suffixes; 546 suffixes = Vdynamic_library_suffixes;
544 547
545 FOR_EACH_TAIL (suffixes) 548 FOR_EACH_TAIL (suffixes)
546 *path_candidates = Fcons (concat2 (lib_base_name, XCAR (suffixes)), 549 {
547 *path_candidates); 550 Lisp_Object candidate1 = concat2 (lib_base_name, XCAR (suffixes));
551#ifndef WINDOWSNT
552 /* On Posix hosts, support libraries named with ABI version
553 numbers. In the foreseeable future we only need to support
554 version 0.0. For more details, see
555 https://lists.gnu.org/archive/html/emacs-devel/2023-04/msg00386.html. */
556 Lisp_Object candidate2 = concat2 (candidate1, Vtreesit_str_dot_0);
557 Lisp_Object candidate3 = concat2 (candidate2, Vtreesit_str_dot_0);
558
559 *path_candidates = Fcons (candidate3, *path_candidates);
560 *path_candidates = Fcons (candidate2, *path_candidates);
561#endif
562 *path_candidates = Fcons (candidate1, *path_candidates);
563 }
548} 564}
549 565
550/* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer 566/* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer
@@ -3948,6 +3964,10 @@ the symbol of that THING. For example, (or block sexp). */);
3948 Vtreesit_str_libtree_sitter = build_pure_c_string ("libtree-sitter-"); 3964 Vtreesit_str_libtree_sitter = build_pure_c_string ("libtree-sitter-");
3949 staticpro (&Vtreesit_str_tree_sitter); 3965 staticpro (&Vtreesit_str_tree_sitter);
3950 Vtreesit_str_tree_sitter = build_pure_c_string ("tree-sitter-"); 3966 Vtreesit_str_tree_sitter = build_pure_c_string ("tree-sitter-");
3967#ifndef WINDOWSNT
3968 staticpro (&Vtreesit_str_dot_0);
3969 Vtreesit_str_dot_0 = build_pure_c_string (".0");
3970#endif
3951 staticpro (&Vtreesit_str_dot); 3971 staticpro (&Vtreesit_str_dot);
3952 Vtreesit_str_dot = build_pure_c_string ("."); 3972 Vtreesit_str_dot = build_pure_c_string (".");
3953 staticpro (&Vtreesit_str_question_mark); 3973 staticpro (&Vtreesit_str_question_mark);