Subject: Re: bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.

From: "Andrew L. Moore" <[email-masked]>
Date: Thu, 3 Mar 2022 14:57:06 -0500

On 3/3/22 09:42, Lars Ingebrigtsen wrote:
> "Andrew L. Moore" <[email-masked]> writes:
> 
>> Repeat magic number search to work around match-data loss
>> when `save-window-excursion' is called.
> 
> I think it would perhaps make more sense to just save the match data
> instead of repeating the match, so I've now done so in Emacs 29

Yes, this resolves the issues that I was seeing.

For the record, I'm not able to reproduce the data loss with
vanilla Emacs by calling `executable-set-magic' manually.  It
occurs (for me) when `executable-set-magic' is called automatically
from a minor mode.  In any case, your patch fixes my minor mode
and does no harm.

The other issue that I attributed to the regexp matching beyond
EOL was caused by `replace-match' being called by incorrect or
uninitialized match data.  Your patch resolves this as well.
Thank you!