Subject: Re: bug#78866: [PATCH] (Finsert_file_contents): Refine commit d07af40d8826

From: Eli Zaretskii <[email-masked]>
Date: Thu, 26 Jun 2025 19:51:31 +0300

> From: Stefan Monnier <[email-masked]>
> Cc: [email-masked]
> Date: Thu, 26 Jun 2025 12:39:14 -0400
> 
> >> If VISIT is non-nil, then REPLACE is also non-nil (or irrelevant
> >> because the buffer is empty):
> >> 
> >>     if (!NILP (visit))
> >>       {
> >>         if (!NILP (beg) || !NILP (end))
> >>           error ("Attempt to visit less than an entire file");
> >>         if (BEG < Z && NILP (replace))
> >>           error ("Cannot do file visiting in a non-empty buffer");
> >>       }
> >
> > Sure, but REPLACE replaces only the accessible portion of the buffert,
> > not all of it.
> 
> Then we should tighten the check even further.  Instead of just adding
> 
>     if (!NILP (visit))
> 
> we should additionally check that BEG==BEGV and Z==ZV:
> 
>     if (!NILP (visit) && BEG == BEGV && Z == ZV)

To this I agree: the condition means that the previous buffer contents
is discarded, and likewise its relation to the original file, and the
buffer will from now on visit the new file, originally having the
exact contents of that new file.  In that specific case, indeed
there's no sense in any super-session warnings.

> Tho, maybe the `BEG == BEGV && Z == ZV` check should be performed in the
> above quoted sanity check, because I think using a non-nil VISIT within
> a narrowed buffer goes against the intention of VISIT.

I'd be reluctant to make such a change: who knows which package out
there uses this unintentional feature?