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?
before-change-functions
andafter-change-functions
to nil in your function. That way, the faulty hook isn't runed. (Of course, if could be a good idea to fid the culprit, which should be relative straight-forward once you found which hook variable it has attached itself to.)