Running spacemacs 0.200.13 on emacs 25.2.2 on Kubuntu 18.04.
I need to search and replace only on lines containing a specific string.
Interactively, I use
occur, move to the
occur buffer, and do all search and replacement there.
I would, now, like to do the same in Elisp code. So, I wrote the following code:
(defun xx-things () (interactive) (save-excursion (goto-char (point-min)) (while (search-forward "A" nil t) (while (search-forward "B" nil t) (replace-match "C" 1)))))
And used it on a buffer with:
AB BB CB
But it replaces all Bs with Cs whereas it should only replace AB with AC.
What is wrong here? How do I set it right?