I have an ancient function I've been using for decades which performs a regexp replacement in a region:
(defun re-replace-region (begin end old new) "Replace occurrences of REGEXP with TO-STRING in region." (interactive "*r\nsReplace string: \nswith: ") (save-excursion (save-restriction (narrow-to-region begin end) (goto-char (point-min)) (while (re-search-forward old (point-max) t) (replace-match new (not case-replace) nil)))))
However, in recent emacs versions this function has started to fail with the message "Match data clobbered by buffer modification hooks".
I believe this can be fixed with judicious use of (save-match-data ...), but that doesn't seem to work for me.
How can this function be fixed?