Subject: bug#78777: 30.1; insert-file-contents should not set buffer-file-name to nil

From: "K. Handa" <[email-masked]>
Date: Wed, 18 Jun 2025 23:23:16 +0900

Hi,

In article <[email-masked]>, Stefan Monnier <[email-masked]> writes:
[...]
>     (Finsert_file_contents): On replacing, temporarily bind
>     buffer-file-name to Qnil before calling insert_from_buffer.

> diff --git a/src/fileio.c b/src/fileio.c
> --- a/src/fileio.c
> +++ b/src/fileio.c
> @@ -4359,8 +4359,12 @@
>        inserted_chars
>  	= (buf_bytepos_to_charpos (XBUFFER (conversion_buffer),
>  				   same_at_start + inserted)
>  	   - same_at_start_charpos);
> +      /* This binding is to avoid ask-user-about-supersession-threat
> +	 being called in insert_from_buffer (via in
> +	 prepare_to_modify_buffer).  */
> +      specbind (intern ("buffer-file-name"), Qnil);
>        insert_from_buffer (XBUFFER (conversion_buffer),
>  			  same_at_start_charpos, inserted_chars, 0);
>        /* Set `inserted' to the number of inserted characters.  */
>        inserted = PT - temp;
> ```

> I'm not sure exactly what was the motivation for the change.
> I mean, the comment explains that the purpose is to silence a potential
> `ask-user-about-supersession-threat`, but I don't know why we should
> care about such a possibility and why it would be right to silence
> it here.

I don't remember, sorry.

> Nor do I understand why it was added to the code path where coding
> conversion was needed but not to the other one.

??? It seems that the code above is where coding conversion is not
needed.

---
K. Handa
[email-masked]