diff options
| author | Miles Bader | 2002-03-14 08:10:35 +0000 |
|---|---|---|
| committer | Miles Bader | 2002-03-14 08:10:35 +0000 |
| commit | e138dfdc9d4f796c02b0c8762f19b05320770204 (patch) | |
| tree | f976eb35151987edac9789cfbd3a341df21eb907 /src/textprop.c | |
| parent | b210a64a6a3097f4ac3bac44734d869bdac9cb85 (diff) | |
| download | emacs-e138dfdc9d4f796c02b0c8762f19b05320770204.tar.gz emacs-e138dfdc9d4f796c02b0c8762f19b05320770204.zip | |
(text_property_stickiness): Function moved here from `editfns.c'.
Diffstat (limited to 'src/textprop.c')
| -rw-r--r-- | src/textprop.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/textprop.c b/src/textprop.c index 14fce396a21..48791c68843 100644 --- a/src/textprop.c +++ b/src/textprop.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Interface code for dealing with text properties. | 1 | /* Interface code for dealing with text properties. |
| 2 | Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001 | 2 | Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002 |
| 3 | Free Software Foundation, Inc. | 3 | Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| @@ -1554,6 +1554,63 @@ containing the text. */) | |||
| 1554 | } | 1554 | } |
| 1555 | return Qnil; | 1555 | return Qnil; |
| 1556 | } | 1556 | } |
| 1557 | |||
| 1558 | |||
| 1559 | /* Return the direction from which the text-property PROP would be | ||
| 1560 | inherited by any new text inserted at POS: 1 if it would be | ||
| 1561 | inherited from the char after POS, -1 if it would be inherited from | ||
| 1562 | the char before POS, and 0 if from neither. */ | ||
| 1563 | |||
| 1564 | int | ||
| 1565 | text_property_stickiness (prop, pos) | ||
| 1566 | Lisp_Object prop; | ||
| 1567 | Lisp_Object pos; | ||
| 1568 | { | ||
| 1569 | Lisp_Object prev_pos, front_sticky; | ||
| 1570 | int is_rear_sticky = 1, is_front_sticky = 0; /* defaults */ | ||
| 1571 | |||
| 1572 | if (XINT (pos) > BEGV) | ||
| 1573 | /* Consider previous character. */ | ||
| 1574 | { | ||
| 1575 | Lisp_Object rear_non_sticky; | ||
| 1576 | |||
| 1577 | prev_pos = make_number (XINT (pos) - 1); | ||
| 1578 | rear_non_sticky = Fget_text_property (prev_pos, Qrear_nonsticky, Qnil); | ||
| 1579 | |||
| 1580 | if (!NILP (CONSP (rear_non_sticky) | ||
| 1581 | ? Fmemq (prop, rear_non_sticky) | ||
| 1582 | : rear_non_sticky)) | ||
| 1583 | /* PROP is rear-non-sticky. */ | ||
| 1584 | is_rear_sticky = 0; | ||
| 1585 | } | ||
| 1586 | |||
| 1587 | /* Consider following character. */ | ||
| 1588 | front_sticky = Fget_text_property (pos, Qfront_sticky, Qnil); | ||
| 1589 | |||
| 1590 | if (EQ (front_sticky, Qt) | ||
| 1591 | || (CONSP (front_sticky) | ||
| 1592 | && !NILP (Fmemq (prop, front_sticky)))) | ||
| 1593 | /* PROP is inherited from after. */ | ||
| 1594 | is_front_sticky = 1; | ||
| 1595 | |||
| 1596 | /* Simple cases, where the properties are consistent. */ | ||
| 1597 | if (is_rear_sticky && !is_front_sticky) | ||
| 1598 | return -1; | ||
| 1599 | else if (!is_rear_sticky && is_front_sticky) | ||
| 1600 | return 1; | ||
| 1601 | else if (!is_rear_sticky && !is_front_sticky) | ||
| 1602 | return 0; | ||
| 1603 | |||
| 1604 | /* The stickiness properties are inconsistent, so we have to | ||
| 1605 | disambiguate. Basically, rear-sticky wins, _except_ if the | ||
| 1606 | property that would be inherited has a value of nil, in which case | ||
| 1607 | front-sticky wins. */ | ||
| 1608 | if (XINT (pos) == BEGV || NILP (Fget_text_property (prev_pos, prop, Qnil))) | ||
| 1609 | return 1; | ||
| 1610 | else | ||
| 1611 | return -1; | ||
| 1612 | } | ||
| 1613 | |||
| 1557 | 1614 | ||
| 1558 | /* I don't think this is the right interface to export; how often do you | 1615 | /* I don't think this is the right interface to export; how often do you |
| 1559 | want to do something like this, other than when you're copying objects | 1616 | want to do something like this, other than when you're copying objects |