GNU bug report logs - #45973
replace-regexp lisp replacement bug

Previous Next

Package: emacs;

Reported by: Nicholas Drozd <nicholasdrozd <at> gmail.com>

Date: Tue, 19 Jan 2021 00:16:01 UTC

Severity: normal

Tags: confirmed, fixed

Fixed in version 28.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45973 in the body.
You can then email your comments to 45973 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#45973; Package emacs. (Tue, 19 Jan 2021 00:16:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Nicholas Drozd <nicholasdrozd <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 19 Jan 2021 00:16:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Nicholas Drozd <nicholasdrozd <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: replace-regexp lisp replacement bug
Date: Mon, 18 Jan 2021 18:15:09 -0600
Here is a string representing a Turing machine program:

  1RB 1LC 1RC 1RB 1RD 0LE 1LA 1LD 1RH 0LA

Say I have a file full of lines like this, and I want to swap all the
Ls for Rs and vice versa. `replace-regexp` is a good way to do it. For
the regexp, I use `\(\(L\)\|\(R\)\)`, a matching group with two nested
matching alternatives; for the replacement, I use a Lisp expression:
`\,(if \2 "R" "L")`. This expression says: if the second match is
found (the `L`), replace it with "R", else replace it with "L".

In Emacs 27 (b58fd1eab9), this gives the expected result:

  1LB 1RC 1LC 1LB 1LD 0RE 1RA 1RD 1LH 0RA

But in Emacs 28 (20add1cd22), it gives an error:

  replace-highlight: Wrong type argument: integer-or-marker-p, nil

A simpler replacement does work: `\(L\)\|R` and `\,(if \1 "R" "L")`.
But the longer one should work too.

I tried to make a Lisp test to reproduce this, but the `\,`
replacement feature is interactive-only, and I don't know how to test
it non-interactively.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45973; Package emacs. (Tue, 19 Jan 2021 03:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 45973 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Nicholas Drozd <nicholasdrozd <at> gmail.com>
Cc: 45973 <at> debbugs.gnu.org
Subject: Re: bug#45973: replace-regexp lisp replacement bug
Date: Tue, 19 Jan 2021 04:44:52 +0100
Nicholas Drozd <nicholasdrozd <at> gmail.com> writes:

> I tried to make a Lisp test to reproduce this, but the `\,`
> replacement feature is interactive-only, and I don't know how to test
> it non-interactively.

The reproducer is:

(replace-regexp "\\(\\(L\\)\\|\\(R\\)\\)" '(replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil nil nil nil nil)

And this leads to the following backtrace:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  make-overlay(nil nil)
  replace-highlight(2 3 nil nil "\\(\\(L\\)\\|\\(R\\)\\)" t nil nil nil)
  perform-replace("\\(\\(L\\)\\|\\(R\\)\\)" (replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil t nil nil nil nil nil nil nil)
  replace-regexp("\\(\\(L\\)\\|\\(R\\)\\)" (replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil nil nil nil nil)
  eval((replace-regexp "\\(\\(L\\)\\|\\(R\\)\\)" '(replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil nil nil nil nil) t)
  eval-expression((replace-regexp "\\(\\(L\\)\\|\\(R\\)\\)" '(replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil nil nil nil nil) nil nil 127)
  funcall-interactively(eval-expression (replace-regexp "\\(\\(L\\)\\|\\(R\\)\\)" '(replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil nil nil nil nil) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

So this is a problem with the new code that highlights the matches, I
think?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) confirmed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 19 Jan 2021 03:46:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45973; Package emacs. (Tue, 19 Jan 2021 18:17:01 GMT) Full text and rfc822 format available.

Message #13 received at 45973 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Nicholas Drozd <nicholasdrozd <at> gmail.com>, 45973 <at> debbugs.gnu.org
Subject: Re: bug#45973: replace-regexp lisp replacement bug
Date: Tue, 19 Jan 2021 20:14:58 +0200
tags 45973 fixed
close 45973 28.0.50
thanks

> Nicholas Drozd <nicholasdrozd <at> gmail.com> writes:
>> I tried to make a Lisp test to reproduce this, but the `\,`
>> replacement feature is interactive-only, and I don't know how to test
>> it non-interactively.

Thanks for the reproducible test case.

> The reproducer is:
>
> (replace-regexp "\\(\\(L\\)\\|\\(R\\)\\)" '(replace-eval-replacement replace-quote (if (match-string 2) "R" "L")) nil nil nil nil nil)
>
> So this is a problem with the new code that highlights the matches, I
> think?

Yep.  Now fixed on master.




Added tag(s) fixed. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 19 Jan 2021 18:17:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.0.50, send any further explanations to 45973 <at> debbugs.gnu.org and Nicholas Drozd <nicholasdrozd <at> gmail.com> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 19 Jan 2021 18:17:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45973; Package emacs. (Tue, 19 Jan 2021 22:37:02 GMT) Full text and rfc822 format available.

Message #20 received at 45973 <at> debbugs.gnu.org (full text, mbox):

From: Nicholas Drozd <nicholasdrozd <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 45973 <at> debbugs.gnu.org
Subject: Re: bug#45973: replace-regexp lisp replacement bug
Date: Tue, 19 Jan 2021 16:36:20 -0600
[Message part 1 (text/plain, inline)]
Thanks for the quick turnaround. I've included a patch to add a test for this.
[0001-test-lisp-replace-tests.el-Add-nested-match-group-te.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45973; Package emacs. (Wed, 20 Jan 2021 01:47:02 GMT) Full text and rfc822 format available.

Message #23 received at 45973 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Nicholas Drozd <nicholasdrozd <at> gmail.com>
Cc: 45973 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#45973: replace-regexp lisp replacement bug
Date: Wed, 20 Jan 2021 02:46:37 +0100
Nicholas Drozd <nicholasdrozd <at> gmail.com> writes:

> Thanks for the quick turnaround. I've included a patch to add a test for this.

Thanks; added to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 17 Feb 2021 12:24:14 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 40 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.