I would like to change all occurrences of a string (say string1) with another string (say string2) and vice-versa. To be precise I have a long document and these strings occur many times. What I currently do, is to replace string1-->string3, then string2-->string1 and finally string3-->string2.
I am wondering if there is already a function in emacs which does this. Other solutions are welcomed.
Edit: This is actually a duplicate of the question linked in the comment. But the problem is that the accepted answer of that question does not always work (see the comment below). I think it is better to wait until the author of that accepted answer corrects his/her answer or some other solution comes out. Secondly before posting my question, I googled the question and that question did not show up. I think having two duplicate questions is sometimes useful since they use different wording and if a user find the duplicate one, he/she can find the right one.
Edit 2: The accepted answer of Search/replace-like feature for swapping text seems to be fine now.
region-noncontiguous-p) in the call of
perform-replacemakes it work here (emacs 24.3). I'll test it on emacs 25 when I get an occasion before editing the other answer.