Instead of computing text properties for all the text in the buffer, you can arrange to compute the text properties for parts of the text when and if something depends on them.
The primitive that extracts text from the buffer along with its
buffer-substring. Before examining the properties,
this function runs the abnormal hook
This variable holds a list of functions for computing text properties. Before
buffer-substringcopies the text and text properties for a portion of the buffer, it calls all the functions in this list. Each of the functions receives two arguments that specify the range of the buffer being accessed. (The buffer itself is always the current buffer.)
buffer-substring-no-properties does not call these
functions, since it ignores text properties anyway.
In order to prevent the hook functions from being called more than
once for the same part of the buffer, you can use the variable
If this variable's value is non-
nil, it is a symbol which is used as a text property name. A non-
nilvalue for that text property means the other text properties for this character have already been computed.
If all the characters in the range specified for
buffer-substringhave a non-
nilvalue for this property,
buffer-substringdoes not call the
buffer-access-fontify-functionsfunctions. It assumes these characters already have the right text properties, and just copies the properties they already have.
The normal way to use this feature is that the
buffer-access-fontify-functionsfunctions add this property, as well as others, to the characters they operate on. That way, they avoid being called over and over for the same text.