gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:07:54 24 4
gpt4 key购买 nike

升级到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com