Version: 27.0.50 26.2 25.3 X-Debbugs-CC: Stefan Monnier emacs -Q -l bug-xxxx-match-data-marker-clobber.el Hit , gives Debugger entered--Lisp error: (error "Match data clobbered by buffer modification hooks") replace-match("ABCDEF" t t) (let* ((after-change-functions (list (function (lambda (&rest _) (let (... ...) (save-excursion ...))))))) (search-backward "abcdef") (replace-match "ABCDEF" t t)) (save-current-buffer (set-buffer (get-buffer-create "*test*")) (display-buffer (current-buffer)) (erase-buffer) (insert "1234567890\n") (insert "abcdefghilk\n") (make-local-variable (quote after-change-functions)) (let* ((after-change-functions (list (function (lambda (&rest _) (let ... ...)))))) (search-backward "abcdef") (replace-match "ABCDEF" t t))) bug-match-data-marker-clobber() funcall-interactively(bug-match-data-marker-clobber) call-interactively(bug-match-data-marker-clobber nil nil) command-execute(bug-match-data-marker-clobber) But the modification hook in question did call save-match-data. As far as I can tell, the problem is that the match-data consists of markers, whose position gets shifted by deletion of characters. The check for this error uses simple integers, so there's no way it can account for this. I think this is a variant of Bug#23917, there was some talk there about removing the check, perhaps that is the right solution. DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0, [...] /* The functions below modify the buffer, so they could trigger various modification hooks (see signal_before_change and signal_after_change). If these hooks clobber the match data we error out since otherwise this will result in confusing bugs. */ ptrdiff_t sub_start = search_regs.start[sub]; ptrdiff_t sub_end = search_regs.end[sub]; unsigned num_regs = search_regs.num_regs; newpoint = search_regs.start[sub] + SCHARS (newtext); /* Replace the old text with the new in the cleanest possible way. */ replace_range (search_regs.start[sub], search_regs.end[sub], newtext, 1, 0, 1, 1); [...] if (search_regs.start[sub] != sub_start || search_regs.end[sub] != sub_end || search_regs.num_regs != num_regs) error ("Match data clobbered by buffer modification hooks"); bug-xxxx-match-data-marker-clobber.el: