I'm trying to use query-replace
in Emacs to replace a string with another string that has specific text properties. Specifically, in this example, I want to replace occurrences of "foo" with "bar" and apply a face property to "bar" so it is highlighted.
Here's what I'm trying to achieve:
(query-replace "foo"
(propertize "bar" 'face 'hi-yellow)
nil (point-min) (point-max))
Unfortunately, query-replace
does not support directly using propertize
to apply text properties to the replacement string. This means that while the text replacement works, the text properties are not applied.
Questions:
- Is there a way in Emacs Lisp to replace text with text properties using
query-replace
or a similar function? - Are there built-in functions or packages that can help achieve this without writing a custom function?
Any help or suggestions would be greatly appreciated.