I need to change the "OBJECT" string foreground color (let's say "red") in all the occurrences of the string "\command{OBJECT}" in my buffer and I need to restore the original foreground color at the end of the job.
I figured out to do something like (it's a simplified MWE):
(defun propertize-command-arg ()
(interactive)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp "\\\\command{\\([a-z]+\\)}" nil t)
(save-excursion
(let ((b (match-beginning 1))
(e (match-end 1)))
(put-text-property b e SOMETHING))))))
(defun propertize-command-arg ()
(interactive)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp "\\\\command{\\([a-z]+\\)}" nil t)
(save-excursion
(let ((b (match-beginning 1))
(e (match-end 1)))
(put-text-property b e SOMETHING))))))
SOMETHING
is what I've not be able to understand/find. I tried also add-text-properties
and add-face-text-property
.
Please keep in mind I need to do it temporarily. I'll restore the original appearance of the text at the end of my job (script).