* 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
* bug#45973: replace-regexp lisp replacement bug
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
0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-01-19 3:44 UTC (permalink / raw)
To: Nicholas Drozd; +Cc: 45973
Nicholas Drozd <nicholasdrozd@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
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#45973: replace-regexp lisp replacement bug
2021-01-19 3:44 ` Lars Ingebrigtsen
@ 2021-01-19 18:14 ` Juri Linkov
2021-01-19 22:36 ` Nicholas Drozd
0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2021-01-19 18:14 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Nicholas Drozd, 45973
tags 45973 fixed
close 45973 28.0.50
thanks
> Nicholas Drozd <nicholasdrozd@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.
^ 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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.