Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query-replace fails with origami #56

Open
cigumo opened this issue Jun 28, 2017 · 3 comments · May be fixed by #93
Open

query-replace fails with origami #56

cigumo opened this issue Jun 28, 2017 · 3 comments · May be fixed by #93

Comments

@cigumo
Copy link

cigumo commented Jun 28, 2017

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.

@gvilanova
Copy link

This issue also happens to me using Emacs 24.5.1 and Origami 20170129.805 for single brackets

@a-hausmann
Copy link

a-hausmann commented May 22, 2019

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 #) nil)
perform-replace("TEXTA" "TEXTB" t nil nil nil nil nil nil nil nil)
query-replace("TEXTA" "TEXTB" nil nil nil nil nil)
funcall-interactively(query-replace "TEXTA" "TEXTB" nil nil nil nil nil)
call-interactively(query-replace nil nil)
command-execute(query-replace)

[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!

@LouisStrous
Copy link

I found a reliable reproduction scenario, and a fix that works 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))

I've created pull request #93 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants