How to replace "(" with "\(" in the regexp, Emacs/elisp flavor?
- by polyglot
Question as title.
More specifically, I'm rather tired of having to type \(, etc. every time I want a parenthesis in Emacs's (interactive) regexp functions (not to mention the \\( in code). So I wrote something like
(defadvice query-replace-regexp (before my-query-replace-regexp activate)
(ad-set-arg 0 (replace-regexp-in-string "(" "\\\\(" (ad-get-arg 0)))
(ad-set-arg 0 (replace-regexp-in-string ")" "\\\\)" (ad-get-arg 0)))))
in hope that I can conveniently forget about emacs's idiosyncrasy in regexp during "interaction mode". Except I cannot get the regexp right...
(replace-regexp-in-string "(" "\\\\(" "(abc")
gives \\(abc instead of the wanted \(abc. Other variations on the number of slashes just gives errors. Thoughts?
Since I started questioning, might as well ask another one: since lisp code is not supposed to use interactive functions, advicing query-replace-regexp should be okay, am I correct?