Q: how do I change text properties conditional on other properties?

I have text between region beg and end. Each character has text properties. I know I can change those text properties in an unconditional way with something like:

(add-text-properties beg end '(some-property t))

How can I change the text properties of characters conditional on their existing properties?

Here's an example. Each character in the region has two text properties, prop1 and prop2, that take on t or nil values. I want to set the value of prop1 to t for only those characters whose prop2 value is t. How do I do that?

1 Answer 1


You can iterate over the text using next-property-change. At each position, you can check the if prop2 is set, and if it has the value t. If so, set prop1 to t.

Of course, the problem is when to do this. If it's fine to do this once, you can simply do this once when your application is started. However, if you want to do this whenever the text is updated (and font-lock is used), you can do this as a side effect in a font-lock rule. In this case, prop1 must be included in font-lock-extra-managed-props.

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.