aboutsummaryrefslogtreecommitdiffstats
path: root/src/syntax.c
diff options
context:
space:
mode:
authorStefan Monnier2023-04-12 15:14:39 -0400
committerStefan Monnier2023-04-12 15:20:07 -0400
commit1e6463ad22cd74b1b74b9395dff8c8b1485e202e (patch)
treee327d9f3bd06e99fa211ef17d45d43ae4a68e447 /src/syntax.c
parent8fdd7710ec0448fe9d3908ad073ddd4d69917719 (diff)
downloademacs-1e6463ad22cd74b1b74b9395dff8c8b1485e202e.tar.gz
emacs-1e6463ad22cd74b1b74b9395dff8c8b1485e202e.zip
(struct gl_state_s): Delete `offset` field
`gl_state` had an `offset` field because: For buffers, regex-emacs.c passes arguments to the UPDATE_SYNTAX_TABLE functions which are relative to BEGV but the reality is that these arguments are byte offsets relative to BEGV_BYTE whereas `offset` was counted in chars, so the two didn't cancel each other out. * src/syntax.h (struct gl_state_s): Delete `offset` field. (UPDATE_SYNTAX_TABLE_FORWARD, UPDATE_SYNTAX_TABLE_BACKWARD) (SYNTAX_TABLE_BYTE_TO_CHAR): * src/syntax.c (SETUP_SYNTAX_TABLE, SETUP_SYNTAX_TABLE_FOR_OBJECT) (update_syntax_table, skip_syntaxes): Simplify accordingly.
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/syntax.c b/src/syntax.c
index 79e16f652f3..8ef13eec40a 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -250,7 +250,6 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count)
250 gl_state.b_property = BEGV; 250 gl_state.b_property = BEGV;
251 gl_state.e_property = ZV + 1; 251 gl_state.e_property = ZV + 1;
252 gl_state.object = Qnil; 252 gl_state.object = Qnil;
253 gl_state.offset = 0;
254 if (parse_sexp_lookup_properties) 253 if (parse_sexp_lookup_properties)
255 { 254 {
256 if (count > 0) 255 if (count > 0)
@@ -265,12 +264,7 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count)
265 264
266/* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. 265/* Same as above, but in OBJECT. If OBJECT is nil, use current buffer.
267 If it is t (which is only used in fast_c_string_match_ignore_case), 266 If it is t (which is only used in fast_c_string_match_ignore_case),
268 ignore properties altogether. 267 ignore properties altogether. */
269
270 This is meant for regex-emacs.c to use. For buffers, regex-emacs.c
271 passes arguments to the UPDATE_SYNTAX_TABLE functions which are
272 relative to BEGV. So if it is a buffer, we set the offset field to
273 BEGV. */
274 268
275void 269void
276SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, 270SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object,
@@ -281,30 +275,26 @@ SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object,
281 if (BUFFERP (gl_state.object)) 275 if (BUFFERP (gl_state.object))
282 { 276 {
283 struct buffer *buf = XBUFFER (gl_state.object); 277 struct buffer *buf = XBUFFER (gl_state.object);
284 gl_state.b_property = 1; 278 gl_state.b_property = BEG;
285 gl_state.e_property = BUF_ZV (buf) - BUF_BEGV (buf) + 1; 279 gl_state.e_property = BUF_ZV (buf);
286 gl_state.offset = BUF_BEGV (buf) - 1;
287 } 280 }
288 else if (NILP (gl_state.object)) 281 else if (NILP (gl_state.object))
289 { 282 {
290 gl_state.b_property = 1; 283 gl_state.b_property = BEG;
291 gl_state.e_property = ZV - BEGV + 1; 284 gl_state.e_property = ZV; /* FIXME: Why not +1 like in SETUP_SYNTAX_TABLE? */
292 gl_state.offset = BEGV - 1;
293 } 285 }
294 else if (EQ (gl_state.object, Qt)) 286 else if (EQ (gl_state.object, Qt))
295 { 287 {
296 gl_state.b_property = 0; 288 gl_state.b_property = 0;
297 gl_state.e_property = PTRDIFF_MAX; 289 gl_state.e_property = PTRDIFF_MAX;
298 gl_state.offset = 0;
299 } 290 }
300 else 291 else
301 { 292 {
302 gl_state.b_property = 0; 293 gl_state.b_property = 0;
303 gl_state.e_property = 1 + SCHARS (gl_state.object); 294 gl_state.e_property = 1 + SCHARS (gl_state.object);
304 gl_state.offset = 0;
305 } 295 }
306 if (parse_sexp_lookup_properties) 296 if (parse_sexp_lookup_properties)
307 update_syntax_table (from + gl_state.offset - (count <= 0), 297 update_syntax_table (from - (count <= 0),
308 count, 1, gl_state.object); 298 count, 1, gl_state.object);
309} 299}
310 300
@@ -341,8 +331,8 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
341 if (!i) 331 if (!i)
342 return; 332 return;
343 i = gl_state.forward_i; 333 i = gl_state.forward_i;
344 gl_state.b_property = i->position - gl_state.offset; 334 gl_state.b_property = i->position;
345 gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; 335 gl_state.e_property = INTERVAL_LAST_POS (i);
346 } 336 }
347 else 337 else
348 { 338 {
@@ -362,7 +352,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
362 { 352 {
363 invalidate = false; 353 invalidate = false;
364 gl_state.forward_i = i; 354 gl_state.forward_i = i;
365 gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; 355 gl_state.e_property = INTERVAL_LAST_POS (i);
366 } 356 }
367 } 357 }
368 else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right. */ 358 else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right. */
@@ -375,7 +365,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
375 { 365 {
376 invalidate = false; 366 invalidate = false;
377 gl_state.backward_i = i; 367 gl_state.backward_i = i;
378 gl_state.b_property = i->position - gl_state.offset; 368 gl_state.b_property = i->position;
379 } 369 }
380 } 370 }
381 } 371 }
@@ -391,12 +381,12 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
391 if (count > 0) 381 if (count > 0)
392 { 382 {
393 gl_state.backward_i = i; 383 gl_state.backward_i = i;
394 gl_state.b_property = i->position - gl_state.offset; 384 gl_state.b_property = i->position;
395 } 385 }
396 else 386 else
397 { 387 {
398 gl_state.forward_i = i; 388 gl_state.forward_i = i;
399 gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; 389 gl_state.e_property = INTERVAL_LAST_POS (i);
400 } 390 }
401 } 391 }
402 392
@@ -426,13 +416,13 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
426 { 416 {
427 if (count > 0) 417 if (count > 0)
428 { 418 {
429 gl_state.e_property = i->position - gl_state.offset; 419 gl_state.e_property = i->position;
430 gl_state.forward_i = i; 420 gl_state.forward_i = i;
431 } 421 }
432 else 422 else
433 { 423 {
434 gl_state.b_property 424 gl_state.b_property
435 = i->position + LENGTH (i) - gl_state.offset; 425 = i->position + LENGTH (i);
436 gl_state.backward_i = i; 426 gl_state.backward_i = i;
437 } 427 }
438 return; 428 return;
@@ -442,7 +432,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
442 if (count > 0) 432 if (count > 0)
443 { 433 {
444 gl_state.e_property 434 gl_state.e_property
445 = i->position + LENGTH (i) - gl_state.offset 435 = i->position + LENGTH (i)
446 /* e_property at EOB is not set to ZV but to ZV+1, so that 436 /* e_property at EOB is not set to ZV but to ZV+1, so that
447 we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without 437 we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
448 having to check eob between the two. */ 438 having to check eob between the two. */
@@ -451,7 +441,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init,
451 } 441 }
452 else 442 else
453 { 443 {
454 gl_state.b_property = i->position - gl_state.offset; 444 gl_state.b_property = i->position;
455 gl_state.backward_i = i; 445 gl_state.backward_i = i;
456 } 446 }
457 return; 447 return;
@@ -2201,8 +2191,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim)
2201 while (!parse_sexp_lookup_properties 2191 while (!parse_sexp_lookup_properties
2202 || pos < gl_state.e_property); 2192 || pos < gl_state.e_property);
2203 2193
2204 update_syntax_table_forward (pos + gl_state.offset, 2194 update_syntax_table_forward (pos, false, gl_state.object);
2205 false, gl_state.object);
2206 } 2195 }
2207 } 2196 }
2208 else 2197 else