origami.el icon indicating copy to clipboard operation
origami.el copied to clipboard

Avoid "Match data clobbered by buffer modification hooks" error

Open LouisStrous opened this issue 4 years ago • 1 comments

I found a reliable reproduction scenario and a code change that fixes #56 for me.

Reproduction scenario:

  1. Visit a C++ file that contains a syntax error. (Presumably the programming language is not important.)
  2. Do revert-buffer. This is a workaround for the issue, so we get to a state where query-replace works.
  3. Do a query-replace that replaces multiple occurrences. This succeeds.
  4. Undo the replacement.
  5. Do compile. The syntax error is reported.
  6. Do next-error to move to the (first) syntax error.
  7. 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))

LouisStrous avatar Apr 17 '20 06:04 LouisStrous

Hi, just want inform people here that have started a new branch here.

If you don't mind using celpa, you can open the PR there instead! Thanks!

For reason why? See https://github.com/jcs-elpa/origami.el/issues/1.

jcs090218 avatar Aug 20 '20 13:08 jcs090218