unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#45973: replace-regexp lisp replacement bug
@ 2021-01-19  0:15 Nicholas Drozd
  2021-01-19  3:44 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas Drozd @ 2021-01-19  0:15 UTC (permalink / raw)
  To: 45973

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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-20  1:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-19  0:15 bug#45973: replace-regexp lisp replacement bug Nicholas Drozd
2021-01-19  3:44 ` Lars Ingebrigtsen
2021-01-19 18:14   ` Juri Linkov
2021-01-19 22:36     ` Nicholas Drozd
2021-01-20  1:46       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).