1

I run into the error Match data clobbered by buffer modification hooks when editing tex files. The way to reproduce is as follows.

In terminal,

cd
mkdir tèst/
cd tèst/
touch test.tex
echo "\input ./universalMacros.tex\n\proof\n% some comment\n\nbye" > test.tex
emacs -Q test.tex

In emacs, use M-: to execute the following

(progn (re-search-forward "proof") (replace-match "prf"))

Then the error appears.

In fact, if the file contains a comment, and is saved, then this error appears, but if the file is modified but not saved, or if the file has no comments, then no error appears when doing replace-match.

Moreover, I tried (setq CHANGE-HOOK nil) where CHANGE-HOOK runs through before-change-functions, after-change-functions and first-change-hook, and the error is still there.

However, if I run

(let ((inhibit-modification-hooks t)) (progn (re-search-forward "proof") (replace-match "prf")))

then there is no error. So I suppose there are some modification hooks that I miss that are related to font-locks. But I am not sure how to resolve the problem.

Note: this error only appears if the path to the file contains strange characters, which makes it even more bizarre.

EDIT: The error message I received is

Debugger entered--Lisp error: (error "Match data clobbered by buffer modification hooks")
  replace-match("prf")
  (progn (re-search-forward "proof") (replace-match "prf"))
  eval((progn (re-search-forward "proof") (replace-match "prf")) nil)
  eval-expression((progn (re-search-forward "proof") (replace-match "prf")) nil nil 127)
  funcall-interactively(eval-expression (progn (re-search-forward "proof") (replace-match "prf")) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

As seen from the error message, this is from replace-match so I don't think this is related to re-search-forward. (I tried to call it like (re-search-forward "proof" nil t) and the error still happens.

If I left out some detail, then please tell me, and I will provide it. Thanks.

Any help or comment is sincerely appreciated; thanks in advance.

awllower
  • 111
  • 5
  • You left out lots of step-by-step details that could help us help you, but the most important is the error message you received. And, if you weren't already aware, `re-search-forward` has an optional argument to not signal any error if a match is not found. – lawlist Aug 01 '18 at 04:55
  • I edited the question. Thanks for your advice. But I think the problem is with `replace-match`. – awllower Aug 01 '18 at 05:36
  • 1
    I can't reproduce this with Emacs 25.2 on Ubuntu 18.04. What version of Emacs are you using? On what OS? What encoding is the directory name in? – Gilles 'SO- stop being evil' Aug 01 '18 at 08:33
  • @Gilles I tested it on windows, and it does not work either. On my machine (mac os High Sierra 10.13.1), `(version)` produces "GNU Emacs 26.1 (build 1, x86_64-apple-darwin17.2.0, NS appkit-1561.10 Version 10.13.1 (Build 17B1003))\n of 2018-06-30". I shall experiment more to find out what is wrong with my setup. – awllower Aug 02 '18 at 08:03
  • 1
    I encountered the same problem. I guessed that it relates to some cache files. I cleaned up my cache using Onyx and the problem has gone. – Shinichi Aug 06 '18 at 17:10
  • @Shinichi Thanks for the information. I shall try that out! But this seems to suggest that either I switch to another machine or I shall not use `replace-match` (or `query-replace` or `replace-regexp`) in a tex file? – awllower Aug 07 '18 at 07:00

0 Answers0