Subject: Re: bug#76371: 31.0.50; M-% -> void variable

From: Po Lu <[email-masked]>
Date: Tue, 18 Feb 2025 09:04:42 +0800

Stefan Kangas <[email-masked]> writes:

> Gerd Möllmann <[email-masked]> writes:
>
>> In a build --without-ns,
>>
>> - emacs -Q
>> - M-% search RET 1 RET
>>
>> =>
>>
>> Debugger entered--Lisp error: (void-variable overriding-text-conversion-style)
>>   perform-replace("search" "1" t nil nil nil nil nil nil nil nil)
>>   query-replace("search" "1" nil nil nil nil nil)
>>   funcall-interactively(query-replace "search" "1" nil nil nil nil nil)
>>   call-interactively(query-replace nil nil)
>>   command-execute(query-replace)
>
> Could it be related to b236a2529dd?  Copying in Po Lu.
>
> I'm also seeing these several test failures, e.g.:
>
> Test query-replace-undo-bug31073 backtrace:
>   perform-replace("a" "B" t t nil)
>   #f(compiled-function () #<bytecode 0x6d983bb021e82be>)()
>   #f(compiled-function () #<bytecode 0x1afcd6ec31a49766>)()
>   handler-bind-1(#f(compiled-function () #<bytecode 0x1afcd6ec31a49766
>   ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
>   ert-run-test(#s(ert-test :name query-replace-undo-bug31073 :document
>   ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
>   ert-run-tests((not (or (tag :expensive-test) (tag :unstable) (tag :n
>   ert-run-tests-batch((not (or (tag :expensive-test) (tag :unstable) (
>   ert-run-tests-batch-and-exit((not (or (tag :expensive-test) (tag :un
>   eval((ert-run-tests-batch-and-exit '(not (or (tag :expensive-test) (
>   command-line-1(("-L" ":." "-l" "ert" "--eval" "(setq treesit-extra-l
>   command-line()
>   normal-top-level()
> Test query-replace-undo-bug31073 condition:
>     (void-variable overriding-text-conversion-style)
>    FAILED  21/29  query-replace-undo-bug31073 (0.000058 sec) at
> lisp/replace-tests.el:587

Please test:

diff --git a/lisp/replace.el b/lisp/replace.el
index b1b417b226f..8c7b3095219 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2880,7 +2880,9 @@ perform-replace
          (region-filter nil)
 
          ;; Disable text conversion during the replacement operation.
-         (old-text-conversion-style overriding-text-conversion-style)
+         (old-text-conversion-style
+          (and (boundp 'overriding-text-conversion-style)
+               overriding-text-conversion-style))
          overriding-text-conversion-style
 
          ;; Data for the next match.  If a cons, it has the same format as