origami.el
origami.el copied to clipboard
query-replace fails with origami
when using query-replace in a buffer that's partially folded with origami.el, I get the following error after the first successful replace:
replace-match-maybe-edit: Match data clobbered by buffer modification hooks
I'm using Emacs 25.1 and Origami 20170129.805 from elpa. The problem happened using (origami-markers-parser "{{{" "}}}") as my parser.
Thanks for your help.
This issue also happens to me using Emacs 24.5.1 and Origami 20170129.805 for single brackets
Happens to me too using Emacs 26.1 (build 1, x86_64-w64-mingw32). Interesting, when changing text throughout the buffer, text BEFORE the fold marker "{{{" is changed, but not after; so, with 10 occurrences of 'TEXTA' total and 2 before "{{{", the first two are changed and then the match is clobbered. I note that if I narrow the buffer to text between the fold markers, there is no error, but as long as the "{{{" exists in the buffer to be parsed, the error occurs.
Hopefully the debugger text will assist.
Debugger entered--Lisp error: (error "Match data clobbered by buffer modification hooks")
replace-match("TEXTB" t t)
replace-match-maybe-edit("TEXTB" t t nil (520 527 #
[EDIT] I have found that upon visiting a file, if I toggle origami-mode off then back on, query-replace works again. Weird...and I cannot explain it. Of course, if I forget to toggle first, I will get the error, but then can toggle off and resubmit the query-replace to successful completion. Simple matter to create a Hydra for this. It's a kludgy work-around--but it works!
I found a reliable reproduction scenario, and a fix that works for me.
Reproduction scenario:
- Visit a C++ file that contains a syntax error. (Presumably the programming language is not important.)
- Do
revert-buffer
. This is a workaround for the issue, so we get to a state where query-replace works. - Do a
query-replace
that replaces multiple occurrences. This succeeds. - Undo the replacement.
- Do
compile
. The syntax error is reported. - Do
next-error
to move to the (first) syntax error. - Do a
query-replace
that replaces multiple occurrences. Only the first occurrence is replaced, and the error message "Match data clobbered by buffer modification hooks" is generated. This reproduces the problem.
The fix that works for me is to edit function origami-header-overlay-range
in origami.el by wrapping the body of the save-excursion
call in a save-match-data
call, yielding
(save-excursion
(save-match-data
(goto-char (overlay-end fold-overlay))
(when (looking-at ".")
(forward-char 1)
(when (looking-at "\n")
(forward-char 1)))
(point))
I've created pull request #93 for this.