I need to add a text-property to the entire buffer. However, parts of the buffer might already have that property with a different value.

Q: What's the easiest way to apply a text property only to regions that don't already have it?

So far, I've been adding the properties to the content of the buffer, but I'd be willing to switch to overlays if it's way easier with overlays.

For instance, take the following buffer contents, and imagine the text in each line is saying the truth.

This text has no face.
This text has a blue-colored face.
This also has no face.

I would like to call a function like

 (point-min) (point-max) 'face 'some-red-face)

and have everything but the second line become red. (the face is just an example, I actually need this for other properties).

  • Side note : if were the only user of that property and able to switch to using only overlays, then you could use overlays with different priority values. (See (info "(elisp) Overlay Properties").) Unfortunately, overlays always have higher priority than text properties, so it wouldn't work in the case you describe.
    – YoungFrog
    Nov 30, 2014 at 11:20
  • @YoungFrog Ignore the example. :-) I am the only user of this property.
    – Malabarba
    Nov 30, 2014 at 11:27
  • Then you can use overlays with "normal" priority for the smaller regions, and an overlay with a small priority for the entire buffer. Does that fit ?
    – YoungFrog
    Nov 30, 2014 at 12:11

1 Answer 1


Use next-single-property-change in a loop, to scan forward for the particular property. Examine the property value each time there is a change in it, and DTRT at that location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.