加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – “重新替换区域:匹配由缓冲区修改钩子破坏的数据

发布时间:2020-12-14 06:08:12 所属栏目:百科 来源:网络整理
导读:升级到Aquamacs 3.3版(emacs 25.1.1)后,我在运行re-replace-region(如下定义)时遇到标题中提到的错误,尝试更改区域中的9s字符串(例如“99”) “或”999“)为0.我以前从未遇到过Aquamacs(或者通常是emacs)的早期版本的问题,而且在emacs环境或一般的机器环境(M
升级到Aquamacs 3.3版(emacs 25.1.1)后,我在运行re-replace-region(如下定义)时遇到标题中提到的错误,尝试更改区域中的9s字符串(例如“99”) “或”999“)为0.我以前从未遇到过Aquamacs(或者通常是emacs)的早期版本的问题,而且在emacs环境或一般的机器环境(Mac OS 10.9.5)中我无法想到任何可能与之相关的问题.问题.

事实上,我在同一台机器上有一个emacs可执行文件(版本22.1.1),并且在相同的环境中调用它(例如,相同的?/ .emacs等)后,重新替换区域可以正常工作.

我可以提供的唯一其他线索是,当在一个区域中运行重新替换区域时,如果在其中有三个9(999),尝试将9更改为0,则在引发错误条件之前更改前9个.

这是defun:

;;; 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 "*rnsReplace 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)

所以我首先假设错误中的信息是正确的,并尝试确认它.检查更改前函数和更改后函数变量的值(在相关缓冲区中),并确定列出的其中一个函数是否负责.

据推测其中一个确实破坏了匹配数据,然后应该将其作为相关功能的错误来解决.如果它是自定义的,您很可能只需要围绕相关代码包含对保存匹配数据的调用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读