regex - "re-replace-region: Match data clobbered by buffer modification hooks"

标签 regex emacs region aquamacs

升级到 Aquamacs 3.3 版 (emacs 25.1.1) 后,运行 re-replace-region 时出现标题中提到的错误(定义如下),尝试将区域(例如“99”或“999”)中的一串 9 更改为 0。我在以前版本的 Aquamacs(或一般的 emacs)中从来没有遇到过这个问题,我想不出任何可能与 emacs 环境或一般机器环境(Mac OS 10.9.5)相关的问题问题。

事实上,我在同一台机器上有一个 emacs 可执行文件(版本 22.1.1),在同一环境(例如,相同的 ~/.emacs 等)中调用它后,re-replace-region正常工作。

我可以提供的唯一其他线索是,在包含三个 9 (999) 的区域上运行 re-replace-region 时,尝试将 9 更改为 0,在引发错误条件之前更改了第一个 9。

这是定义:

;;; RE-REPLACE-REGION replaces OLD (a regular expression) with NEW
;;; throughout the region indicated by BEGIN and END.
;;; For example, to insert a prefix ">" at the beginning of each line
;;; in the region:
;;;   M-x re-replace-regionRET^RET>RET
;;; I don't know who wrote this function!
(defun re-replace-region (begin end old new)
"Replace occurrences of REGEXP with TO-STRING in region."
  (interactive "*r\nsReplace string: \nswith: ")
  (save-excursion
    (save-restriction
      (narrow-to-region begin end)
      (goto-char (point-min))
      (while (re-search-forward old (point-max) t)
        (replace-match new nil nil)))))

最佳答案

我可以告诉你,这个错误信息是在 2016 年 7 月引入的,这就解释了为什么旧版本的 Emacs 没有提出它:

commit 3a9d6296b35e5317c497674d5725eb52699bd3b8
Author: Eli Zaretskii
Date:   Mon Jul 4 18:34:40 2016 +0300

Avoid crashes when buffer modification hooks clobber match data

* src/search.c (Freplace_match): Error out if buffer modification
hooks triggered by buffer changes in replace_range, upcase-region,
and upcase-initials-region clobber the match data needed to be
adjusted for the replacement.  (Bug#23869)

所以我会首先假设错误中的信息是正确的,并尝试确认它。检查 before-change-functions 的值和 after-change-functions变量(在有问题的缓冲区中),并确定列出的函数之一是否负责。

据推测,其中一个确实破坏了匹配数据,然后应该将其作为相关函数的错误解决。如果是自定义的,您很可能只需要调用 save-match-data围绕相关代码。

关于regex - "re-replace-region: Match data clobbered by buffer modification hooks",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41402028/

相关文章:

Emacs 组织模式 : How to include properties in diary anniversaries?

emacs - 在 Emacs : Only change the background color 中自定义高亮面

android - 是否可以根据国家/地区设置应用在 google play store 上的描述?

php - 2 列中的记录集重复区域

regex - Notepad++ Regex 查找包含单词且不包含单词的行

python - 提取前缀和多个后续匹配项

javascript - JavaScript 中第一个字符的正则表达式不能是空格

Ruby 模式匹配 - 查找所有可能匹配项的数量

r - emacs org R 源代码块中 cat() 的输出结果

javascript - 在区域四叉树中实现插入/删除/查询范围?