For example I want to make all text in parenthesis, (), UPCASE. It’s trivial to do the following interactively:
M-x query-replace-regexp
replace: "(\(.+?\))"
with : "(\,(upcase \1))"
Instead I want to write a defun which will do that:
(defun upcs ()
(interactive)
(goto-char 1)
(while (search-forward "(\\(.+?\\))" nil t) (replace-match "(\\,(upcase \\1))" t nil)))
but it doesn’t work! While the following works (it appends foo and bar to the parenthesized texts):
(defun HOOK ()
(interactive)
(goto-char 1)
(while (search-forward-regexp "(\\(.+?\\))" nil t) (replace-match "(foo \\1 bar)" t nil)))
So this solves the problem.
Thanks to BillC and Luke Girvin for help.