Go to the first, previous, next, last section, table of contents.


Stickiness of Text Properties

Self-inserting characters normally take on the same properties as the preceding character. This is called inheritance of properties.

In a Lisp program, you can do insertion with inheritance or without, depending on your choice of insertion primitive. The ordinary text insertion functions such as insert do not inherit any properties. They insert text with precisely the properties of the string being inserted, and no others. This is correct for programs that copy text from one context to another--for example, into or out of the kill ring. To insert with inheritance, use the special primitives described in this section. Self-inserting characters inherit properties because they work using these primitives.

When you do insertion with inheritance, which properties are inherited depends on two specific properties: front-sticky and rear-nonsticky.

Insertion after a character inherits those of its properties that are rear-sticky. Insertion before a character inherits those of its properties that are front-sticky. By default, a text property is rear-sticky but not front-sticky. Thus, the default is to inherit all the properties of the preceding character, and nothing from the following character. You can request different behavior by specifying the stickiness of certain properties.

If a character's front-sticky property is t, then all its properties are front-sticky. If the front-sticky property is a list, then the sticky properties of the character are those whose names are in the list. For example, if a character has a front-sticky property whose value is (face read-only), then insertion before the character can inherit its face property and its read-only property, but no others.

The rear-nonsticky works the opposite way. Every property is rear-sticky by default, so the rear-nonsticky property says which properties are not rear-sticky. If a character's rear-nonsticky property is t, then none of its properties are rear-sticky. If the rear-nonsticky property is a list, properties are rear-sticky unless their names are in the list.

When you insert text with inheritance, it inherits all the rear-sticky properties of the preceding character, and all the front-sticky properties of the following character. The previous character's properties take precedence when both sides offer different sticky values for the same property.

Here are the functions that insert text with inheritance of properties:

Function: insert-and-inherit &rest strings
Insert the strings strings, just like the function insert, but inherit any sticky properties from the adjoining text.

Function: insert-before-markers-and-inherit &rest strings
Insert the strings strings, just like the function insert-before-markers, but inherit any sticky properties from the adjoining text.

See section Inserting Text, for the ordinary insertion functions which do not inherit.


Go to the first, previous, next, last section, table of contents.