comparison src/editfns.c @ 40046:5858ea32e564

(text_property_stickiness): Really fix it this time.
author Miles Bader <miles@gnu.org>
date Fri, 19 Oct 2001 07:45:58 +0000
parents 7a0668d72687
children de086e415fa2
comparison
equal deleted inserted replaced
40045:887dd5ab45c3 40046:5858ea32e564
350 static int 350 static int
351 text_property_stickiness (prop, pos) 351 text_property_stickiness (prop, pos)
352 Lisp_Object prop; 352 Lisp_Object prop;
353 Lisp_Object pos; 353 Lisp_Object pos;
354 { 354 {
355 Lisp_Object front_sticky; 355 Lisp_Object prev_pos, front_sticky;
356 int is_rear_sticky = 1, is_front_sticky = 0; /* defaults */
356 357
357 if (XINT (pos) > BEGV) 358 if (XINT (pos) > BEGV)
358 /* Consider previous character. */ 359 /* Consider previous character. */
359 { 360 {
360 Lisp_Object prev_pos = make_number (XINT (pos) - 1); 361 Lisp_Object rear_non_sticky;
361 362
362 if (! NILP (Fget_text_property (prev_pos, prop, Qnil))) 363 prev_pos = make_number (XINT (pos) - 1);
363 /* Non-rear-non-stickiness only takes precedence if the 364 rear_non_sticky = Fget_text_property (prev_pos, Qrear_nonsticky, Qnil);
364 preceding property value is non-nil. */ 365
365 { 366 if (CONSP (rear_non_sticky)
366 Lisp_Object rear_non_sticky 367 ? Fmemq (prop, rear_non_sticky)
367 = Fget_text_property (prev_pos, Qrear_nonsticky, Qnil); 368 : !NILP (rear_non_sticky))
368 369 /* PROP is rear-non-sticky. */
369 if (EQ (rear_non_sticky, Qnil) 370 is_rear_sticky = 0;
370 || (CONSP (rear_non_sticky)
371 && NILP (Fmemq (prop, rear_non_sticky))))
372 /* PROP is not rear-non-sticky, and since this takes
373 precedence over any front-stickiness, PROP is inherited
374 from before. */
375 return -1;
376 }
377 } 371 }
378 372
379 /* Consider following character. */ 373 /* Consider following character. */
380 front_sticky = Fget_text_property (pos, Qfront_sticky, Qnil); 374 front_sticky = Fget_text_property (pos, Qfront_sticky, Qnil);
381 375
382 if (EQ (front_sticky, Qt) 376 if (EQ (front_sticky, Qt)
383 || (CONSP (front_sticky) 377 || (CONSP (front_sticky)
384 && !NILP (Fmemq (prop, front_sticky)))) 378 && !NILP (Fmemq (prop, front_sticky))))
385 /* PROP is inherited from after. */ 379 /* PROP is inherited from after. */
380 is_front_sticky = 1;
381
382 /* Simple cases, where the properties are consistent. */
383 if (is_rear_sticky && !is_front_sticky)
384 return -1;
385 else if (!is_rear_sticky && is_front_sticky)
386 return 1; 386 return 1;
387 387 else if (!is_rear_sticky && !is_front_sticky)
388 /* PROP is not inherited from either side. */ 388 return 0;
389 return 0; 389
390 /* The stickiness properties are inconsistent, so we have to
391 disambiguate. Basically, rear-sticky wins, _except_ if the
392 property that would be inherited has a value of nil, in which case
393 front-sticky wins. */
394 if (XINT (pos) == BEGV || NILP (Fget_text_property (prev_pos, prop, Qnil)))
395 return 1;
396 else
397 return -1;
390 } 398 }
391 399
392 400
393 /* Find the field surrounding POS in *BEG and *END. If POS is nil, 401 /* Find the field surrounding POS in *BEG and *END. If POS is nil,
394 the value of point is used instead. If BEG or END null, 402 the value of point is used instead. If BEG or END null,