title: Emacs: how do I replace-regexp with a lisp function in a defun?
body: <p>For example I want to make all text in parenthesis, (), UPCASE. It's trivial to do the following interactively:</p>
  
  <pre><code>M-x query-replace-regexp
  replace: "(\(.+?\))"
  with   : "(\,(upcase \1))"
  </code></pre>
  
  <p>Instead I want to write a <code>defun</code> which will do that:</p>
  
  <pre><code>(defun upcs ()
    (interactive)
    (goto-char 1)
    (while (search-forward "(\\(.+?\\))" nil t) (replace-match "(\\,(upcase \\1))" t nil)))
  </code></pre>
  
  <p>but it doesn't work! While the following works (it appends <code>foo</code> and <code>bar</code> to the parenthesized texts):</p>
  
  <pre><code>(defun HOOK ()
    (interactive)
    (goto-char 1)
    (while (search-forward-regexp "(\\(.+?\\))" nil t) (replace-match "(foo \\1 bar)" t nil)))
  </code></pre>