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.

Full log


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.




This bug report was last modified 4 years and 118 days ago.

Previous Next


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