GNU bug report logs - #78777
30.1; insert-file-contents should not set buffer-file-name to nil

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>; dated Thu, 12 Jun 2025 16:59:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 78777 <at> debbugs.gnu.org:


Received: (at 78777) by debbugs.gnu.org; 14 Jun 2025 14:51:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jun 14 10:51:30 2025
Received: from localhost ([127.0.0.1]:40089 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQSEE-0000cL-Bu
	for submit <at> debbugs.gnu.org; Sat, 14 Jun 2025 10:51:30 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:60594)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uQSEC-0000c5-Tf
 for 78777 <at> debbugs.gnu.org; Sat, 14 Jun 2025 10:51:29 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uQSE7-0002TE-Ie; Sat, 14 Jun 2025 10:51:23 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=mFjjssncGHDi6l267jF9IeEvGVmPooNk7yZhp80GkX0=; b=iuGDo98JbDFdtaXjWhwl
 h47DCIMGvRGq9mVX3bgjkt6qBNhE26XXrlDx8rSYpO+4a3Tba2YRwfRKNmhLmNtsHNoSU4cdbuEzc
 PINKGGmMaz5o42uXF/qLIa0i1/gncrZZvjOUuBkKSowNL2YOmx3Zg4jqt3xwoy6tbL9F5a+sgGse2
 4SGlOsJimidnu0XCXqV7mY5qaOIuuzo0drvVqJB2pEGjAaDq0WrgLV0vnISPRvyMIYxJoLKhZ0ljr
 lr6iZTJN+n6nKMSCkVnCUqZf2/oBBEM2ErRc5MO1jtIUoPQ5eaLSOsFoIFfutD3S3r//IMRHB0n/t
 YE/Rc7Eh84fEig==;
Date: Sat, 14 Jun 2025 17:51:22 +0300
Message-Id: <86y0tuqsut.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
In-Reply-To: <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
 (message from Jimmy Yuen Ho Wong on Thu, 12 Jun 2025 20:34:30 +0100)
Subject: Re: bug#78777: 30.1; insert-file-contents should not set
 buffer-file-name to nil
References: <m28qlwyk05.fsf@HIDDEN> <8634c4g6v0.fsf@HIDDEN>
 <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78777
Cc: 78777 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
> Date: Thu, 12 Jun 2025 20:34:30 +0100
> Cc: 78777 <at> debbugs.gnu.org
> 
> On Thu, Jun 12, 2025 at 7:19 PM Eli Zaretskii <eliz@HIDDEN> wrote:
> 
>  > From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
>  > Date: Thu, 12 Jun 2025 17:58:34 +0100
>  > 
>  > 
>  > When investigating https://github.com/emacs-lsp/lsp-mode/issues/4782 and
>  > https://github.com/purcell/emacs-reformatter/issues/63, I've discovered
>  > the following bug in insert-file-contents.
>  > 
>  > Reproduction:
>  > 
>  > 1. echo "hello world" > ~/test.txt
>  > 2. emacs -q ~/test.txt
>  > 3. M-x eval-expression RET (add-hook 'after-change-functions (lambda (&rest _) (message
>  "buffer-file-name: %s, current-buffer: %s" (buffer-file-name) (current-buffer))) nil t) RET
>  > 4. Type something into the buffer
>  > 5. M-x eval-expression RET (insert-file-contents (buffer-file-name) nil nil nil t) RET
>  > 6. Switch to the *Messages* buffer and observe the buffer file name is nil.
>  > 
>  > Expectation:
>  > 
>  > insert-file-contents should not set buffer-file-name to nil
> 
>  I don't think it does.  (buffer-file-name) returns nil when the call
>  is evaluated in the minibuffer, and I thin that's what you see.  After
>  performing the above recipe the buffer-filename of the buffer that
>  visits test.txt remains to be "test.txt", at least in my testing.  So
>  the only evidence that it's set to nil are the messages logged in
>  *Messages*, and they are about a different buffer.
> 
> When a lisp expression is evaluated in the minibuffer, the current buffer is the file buffer, not the minibuffer.
> You can easily verify this with M-x eval-expression RET (current-buffer)  RET.
> 
> The crux of the matter is the lambda added to after-change-function. `insert-file-contents` calls
> `signals_after_change` (fileio.c line 5007 on master), which will run the after-change-functions. It is at this
> moment the buffer-file-name is nil.
> 
> In addition, the following will NOT result in insert-file-contents temporarily setting the buffer-file-name of the
> current buffer to nil:
> 
> (let ((coding-system-for-read 'no-conversion)
>       (coding-system-for-write 'no-conversion))
>   (insert-file-contents (buffer-file-name) nil nil nil t))
> 
> Which suggests some of the code conversion logic in the C function is erroneously setting the current
> buffer's file-name to nil, and then running the after-change-functions before resetting it.

I think your after-change-function is called not due to
insert-file-contents inserting the text from the file, but from the
functions that decode the file's text.  To see if this is true, make
your after-change-function show the name of the current buffer.  If
I'm right, you will see something like " *code conversion works" as
the name of the buffer, in which case indeed buffer-filename is
expected to be nil, and I don't see a bug here.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78777; Package emacs. Full text available.

Message received at 78777 <at> debbugs.gnu.org:


Received: (at 78777) by debbugs.gnu.org; 12 Jun 2025 19:35:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jun 12 15:35:18 2025
Received: from localhost ([127.0.0.1]:60692 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uPnhl-00011z-B2
	for submit <at> debbugs.gnu.org; Thu, 12 Jun 2025 15:35:17 -0400
Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:45498)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <wyuenho@HIDDEN>) id 1uPnhg-0000x4-Vz
 for 78777 <at> debbugs.gnu.org; Thu, 12 Jun 2025 15:35:14 -0400
Received: by mail-pl1-x634.google.com with SMTP id
 d9443c01a7336-2360ff7ac1bso10865565ad.3
 for <78777 <at> debbugs.gnu.org>; Thu, 12 Jun 2025 12:35:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1749756907; x=1750361707; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=eJZ8DvYdi4/ZROHPVN/gBS1tZmA8V2q9ViGvwxJJMj4=;
 b=bMT+GJqJcrCdNDr+v7tUp8yBFNX3ZFvUogeVU0Op9HOYxs5LERBEJX4GzByTAEmPgJ
 JHESqiZe1TYx6hpmQZLNfOsmlsHICWNM69kylnZn8TTEssyDsooYTqHJdfRoXo5nMDJM
 ssqYxmzli0QLZzuMRRHYz1o6RqBtrPUQ64GsJObL2ICO6poY+Ar2cDxhStcHvksdyooJ
 rIhpHKvuD2GPQ6gnYTjqTYOjBXw3nKrJbIvvhpdQMLT5BQeavWcSGwrLCDA/hZurYTom
 wwk4XaKRVyxJQdyF1pDsIqznSbbNglYmwJ7+y0ELn06Pfkid5zUdHwK6PEdv/ve1K+1z
 4q4w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1749756907; x=1750361707;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=eJZ8DvYdi4/ZROHPVN/gBS1tZmA8V2q9ViGvwxJJMj4=;
 b=kVVVk6fEWlqF/fydb7GS2yEBVk1Jh81a2v2/LHDtY8zUAqWSn16NMROsX1ZSYTffe9
 OB4CWJpAtR/2ioJloIgvPzPF+QZg/gwCi8OdwTz9gQcw41FDOtyN8+WoilIacObSQ/cy
 A6/JvGItNKmyjL/Ud20gFlEjoVEXQKiRunJVIiWYkiCc4bkkmkf1GSVBJ2mb1xXkBMpq
 Ov89lk9sanV+sI+VbdWRGy5YIZ62tjF68T71rgycjEfCt6LJcf3F+YLgW26tCnwfj7Hb
 yWS919iwPuPZZp6YrE4rF7eAZTAbXdWepq53+CRuIYrySHGD3BfVUnzaGEO5TUAEFFvI
 pVbQ==
X-Gm-Message-State: AOJu0Yw4fuhfg7tTRBdRYMzCDakCcNW0PpVmlWWdpl0qj564eg72ru8Z
 Rm99PgAT5U4SmdRFx42u61LnqY8efJsYbeqRQOIyp0DdHjFBGjbJVhBxBO1haWPrXY0y05kPJMf
 JI/+7SQMoKlEiGMTpekeoT1gdVM9OCy4=
X-Gm-Gg: ASbGnctHpaTLtOit8woH6NmI8QmTcMqixCFV5/q+FH4U+keb9EOaHRtYyJ3xW6omdHo
 6PmXRIKXmhSE8kTzX+pfmrP9/5XNLmh3Wx/dM4OyTg9egDRchUaeHsviFlFolmLLtk9z1cbRF4Z
 QITo9iy3eIm8Vkx/qgMkYm9LAvNEIDRxUuvceaVUsTG2L0qDaCBG57o8ozr3V5wVr8yHrWNxSpv
 eDyHw==
X-Google-Smtp-Source: AGHT+IGixn3SGRLAAD1etB/HHVkTQ/NpW48V1+CFUAxyNfjCXstAzb2fMKQECgmPIbylQucUUIGbsXLo0hdB+6mbvgA=
X-Received: by 2002:a17:90b:544f:b0:313:27e5:7ff1 with SMTP id
 98e67ed59e1d1-313d9c60fa0mr512740a91.1.1749756906571; Thu, 12 Jun 2025
 12:35:06 -0700 (PDT)
MIME-Version: 1.0
References: <m28qlwyk05.fsf@HIDDEN> <8634c4g6v0.fsf@HIDDEN>
In-Reply-To: <8634c4g6v0.fsf@HIDDEN>
From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
Date: Thu, 12 Jun 2025 20:34:30 +0100
X-Gm-Features: AX0GCFsnGnSPG7EZdBifCzkM8VbRoTGM-a_bMjFUXKPtCeJzKSnOoUE6NdYeMMY
Message-ID: <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
Subject: Re: bug#78777: 30.1; insert-file-contents should not set
 buffer-file-name to nil
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: multipart/alternative; boundary="000000000000dc0dbc06376506be"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 78777
Cc: 78777 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--000000000000dc0dbc06376506be
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, Jun 12, 2025 at 7:19=E2=80=AFPM Eli Zaretskii <eliz@HIDDEN> wrote:

> > From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
> > Date: Thu, 12 Jun 2025 17:58:34 +0100
> >
> >
> > When investigating https://github.com/emacs-lsp/lsp-mode/issues/4782 an=
d
> > https://github.com/purcell/emacs-reformatter/issues/63, I've discovered
> > the following bug in insert-file-contents.
> >
> > Reproduction:
> >
> > 1. echo "hello world" > ~/test.txt
> > 2. emacs -q ~/test.txt
> > 3. M-x eval-expression RET (add-hook 'after-change-functions (lambda
> (&rest _) (message "buffer-file-name: %s, current-buffer: %s"
> (buffer-file-name) (current-buffer))) nil t) RET
> > 4. Type something into the buffer
> > 5. M-x eval-expression RET (insert-file-contents (buffer-file-name) nil
> nil nil t) RET
> > 6. Switch to the *Messages* buffer and observe the buffer file name is
> nil.
> >
> > Expectation:
> >
> > insert-file-contents should not set buffer-file-name to nil
>
> I don't think it does.  (buffer-file-name) returns nil when the call
> is evaluated in the minibuffer, and I thin that's what you see.  After
> performing the above recipe the buffer-filename of the buffer that
> visits test.txt remains to be "test.txt", at least in my testing.  So
> the only evidence that it's set to nil are the messages logged in
> *Messages*, and they are about a different buffer.
>

When a lisp expression is evaluated in the minibuffer, the current buffer
is the file buffer, not the minibuffer. You can easily verify this with M-x
eval-expression RET (current-buffer)  RET.

The crux of the matter is the lambda added to after-change-function.
`insert-file-contents` calls `signals_after_change` (fileio.c line 5007 on
master), which will run the after-change-functions. It is at this moment
the buffer-file-name is nil.

In addition, the following will NOT result in insert-file-contents
temporarily setting the buffer-file-name of the current buffer to nil:

(let ((coding-system-for-read 'no-conversion)
      (coding-system-for-write 'no-conversion))
  (insert-file-contents (buffer-file-name) nil nil nil t))

Which suggests some of the code conversion logic in the C function is
erroneously setting the current buffer's file-name to nil, and then running
the after-change-functions before resetting it.

--000000000000dc0dbc06376506be
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div><br clear=3D"all"></div><div><div di=
r=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr">On Thu, Jun 12, 2025 a=
t 7:19=E2=80=AFPM Eli Zaretskii &lt;<a href=3D"mailto:eliz@HIDDEN">eliz@gn=
u.org</a>&gt; wrote:</div></div></div></div><div class=3D"gmail_quote gmail=
_quote_container"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">&gt; Fr=
om: Jimmy Yuen Ho Wong &lt;<a href=3D"mailto:wyuenho@HIDDEN" target=3D"_=
blank">wyuenho@HIDDEN</a>&gt;<br>
&gt; Date: Thu, 12 Jun 2025 17:58:34 +0100<br>
&gt; <br>
&gt; <br>
&gt; When investigating <a href=3D"https://github.com/emacs-lsp/lsp-mode/is=
sues/4782" rel=3D"noreferrer" target=3D"_blank">https://github.com/emacs-ls=
p/lsp-mode/issues/4782</a> and<br>
&gt; <a href=3D"https://github.com/purcell/emacs-reformatter/issues/63" rel=
=3D"noreferrer" target=3D"_blank">https://github.com/purcell/emacs-reformat=
ter/issues/63</a>, I&#39;ve discovered<br>
&gt; the following bug in insert-file-contents.<br>
&gt; <br>
&gt; Reproduction:<br>
&gt; <br>
&gt; 1. echo &quot;hello world&quot; &gt; ~/test.txt<br>
&gt; 2. emacs -q ~/test.txt<br>
&gt; 3. M-x eval-expression RET (add-hook &#39;after-change-functions (lamb=
da (&amp;rest _) (message &quot;buffer-file-name: %s, current-buffer: %s&qu=
ot; (buffer-file-name) (current-buffer))) nil t) RET<br>
&gt; 4. Type something into the buffer<br>
&gt; 5. M-x eval-expression RET (insert-file-contents (buffer-file-name) ni=
l nil nil t) RET<br>
&gt; 6. Switch to the *Messages* buffer and observe the buffer file name is=
 nil.<br>
&gt; <br>
&gt; Expectation:<br>
&gt; <br>
&gt; insert-file-contents should not set buffer-file-name to nil<br>
<br>
I don&#39;t think it does.=C2=A0 (buffer-file-name) returns nil when the ca=
ll<br>
is evaluated in the minibuffer, and I thin that&#39;s what you see.=C2=A0 A=
fter<br>
performing the above recipe the buffer-filename of the buffer that<br>
visits test.txt remains to be &quot;test.txt&quot;, at least in my testing.=
=C2=A0 So<br>
the only evidence that it&#39;s set to nil are the messages logged in<br>
*Messages*, and they are about a different buffer.<br></blockquote><div><br=
></div><div>When a lisp expression is evaluated in the minibuffer, the curr=
ent buffer is the file buffer, not the minibuffer. You can easily verify th=
is with M-x eval-expression RET (current-buffer)=C2=A0 RET.<br><br>The crux=
 of the matter is the lambda added to after-change-function. `insert-file-c=
ontents` calls `signals_after_change` (fileio.c line 5007 on master), which=
 will run the after-change-functions. It is at this moment the buffer-file-=
name is nil.<br><br>In addition, the following will NOT result in insert-fi=
le-contents temporarily setting the buffer-file-name of the current buffer =
to nil:<br><br>(let ((coding-system-for-read &#39;no-conversion)</div><div>=
=C2=A0 =C2=A0 =C2=A0 (coding-system-for-write &#39;no-conversion))<br>=C2=
=A0 (insert-file-contents (buffer-file-name) nil nil nil t))<br><br>Which s=
uggests some of the code conversion logic in the C function is erroneously=
=C2=A0setting the current buffer&#39;s file-name to nil, and then running t=
he after-change-functions before resetting it.</div></div></div>

--000000000000dc0dbc06376506be--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78777; Package emacs. Full text available.

Message received at 78777 <at> debbugs.gnu.org:


Received: (at 78777) by debbugs.gnu.org; 12 Jun 2025 18:19:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jun 12 14:19:58 2025
Received: from localhost ([127.0.0.1]:60279 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uPmWr-0004KL-ME
	for submit <at> debbugs.gnu.org; Thu, 12 Jun 2025 14:19:57 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:42324)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uPmWp-0004Jv-9y
 for 78777 <at> debbugs.gnu.org; Thu, 12 Jun 2025 14:19:55 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uPmWj-0005G1-Sz; Thu, 12 Jun 2025 14:19:49 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=yc9+F9R5/8aftnRN8R/TqpGVFWYSLhhQJLu/etM60Z8=; b=khBi3OHQlpr/
 YP+Vmm5sQGtDc1q5u2yYQ2i9lHLqwcq5PtShaxvaOW8eYB9iAyWqv4VDOOMowXvCdI/u2MYcN7nJx
 RH8Z4RdGvIUtTSviyblLfX1zDJoXF5joTr59H2JT1wQJafPKiQ97gZAnQEy08e5p8RvCKw61SQ98j
 MXT1J05COx3S60YmT1Wd+KSs4Q75mZ7Z5u1Zqio09bS5NB2OvmFxOnGOJP7AXu43hfRjL575iHits
 guSZu4JKtRwfj0KJsReIawzRR7f+Bfa5XrrilwwrZgSVMG86BTf1qjmgy0kBdL3TGLlKiZL4GoUSs
 YVu+R8Zi7pNn0Oz7f8IBew==;
Date: Thu, 12 Jun 2025 21:19:47 +0300
Message-Id: <8634c4g6v0.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
In-Reply-To: <m28qlwyk05.fsf@HIDDEN> (message from Jimmy Yuen
 Ho Wong on Thu, 12 Jun 2025 17:58:34 +0100)
Subject: Re: bug#78777: 30.1;
 insert-file-contents should not set buffer-file-name to nil
References: <m28qlwyk05.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78777
Cc: 78777 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
> Date: Thu, 12 Jun 2025 17:58:34 +0100
> 
> 
> When investigating https://github.com/emacs-lsp/lsp-mode/issues/4782 and
> https://github.com/purcell/emacs-reformatter/issues/63, I've discovered
> the following bug in insert-file-contents.
> 
> Reproduction:
> 
> 1. echo "hello world" > ~/test.txt
> 2. emacs -q ~/test.txt
> 3. M-x eval-expression RET (add-hook 'after-change-functions (lambda (&rest _) (message "buffer-file-name: %s, current-buffer: %s" (buffer-file-name) (current-buffer))) nil t) RET
> 4. Type something into the buffer
> 5. M-x eval-expression RET (insert-file-contents (buffer-file-name) nil nil nil t) RET
> 6. Switch to the *Messages* buffer and observe the buffer file name is nil.
> 
> Expectation:
> 
> insert-file-contents should not set buffer-file-name to nil

I don't think it does.  (buffer-file-name) returns nil when the call
is evaluated in the minibuffer, and I thin that's what you see.  After
performing the above recipe the buffer-filename of the buffer that
visits test.txt remains to be "test.txt", at least in my testing.  So
the only evidence that it's set to nil are the messages logged in
*Messages*, and they are about a different buffer.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78777; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Jun 2025 16:58:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jun 12 12:58:56 2025
Received: from localhost ([127.0.0.1]:59919 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uPlGR-0007Ds-RR
	for submit <at> debbugs.gnu.org; Thu, 12 Jun 2025 12:58:56 -0400
Received: from lists.gnu.org ([2001:470:142::17]:34988)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <wyuenho@HIDDEN>) id 1uPlGP-0007DY-Iy
 for submit <at> debbugs.gnu.org; Thu, 12 Jun 2025 12:58:54 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <wyuenho@HIDDEN>) id 1uPlGF-00062c-AN
 for bug-gnu-emacs@HIDDEN; Thu, 12 Jun 2025 12:58:43 -0400
Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <wyuenho@HIDDEN>) id 1uPlGD-00037N-0E
 for bug-gnu-emacs@HIDDEN; Thu, 12 Jun 2025 12:58:42 -0400
Received: by mail-wm1-x335.google.com with SMTP id
 5b1f17b1804b1-450cb2ddd46so6868635e9.2
 for <bug-gnu-emacs@HIDDEN>; Thu, 12 Jun 2025 09:58:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1749747516; x=1750352316; darn=gnu.org;
 h=mime-version:message-id:date:subject:to:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=6oO3Uh1wtDh+2brdY2BS9gstlMcLv3xMmA3EYi/zvJs=;
 b=JqDk1nZmPInquTZ+DsDKETgwVau/K5Fm91ItdAJszrx3sjN3s2pztoMcyC+amgwFfc
 LPgSJztDZBH5bslF1c6ZLJmZbx/4rOFUofbAv1D5Ov8POB8KIb04wczYKNc/Jjh0rTH4
 hAz1kp32dv8KQcqjHJehKDuDy/rgkaiJYMxupNhrIceWtUdjQT/sAg5JQlZi9zbFje3L
 kQfSj4ed3BtDupxmG50knIOYhxBr0K9sKAJZaGuNtc5ucUBTLrTNb8GCQ+EnK9OjLm83
 Z4LoUU5566z7mU3kapaJ6sIJeJ0NgVbX2aQzk1E/VrLVj8Imzu8iRqZx1OE+roQq0KYz
 PC4g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1749747516; x=1750352316;
 h=mime-version:message-id:date:subject:to:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=6oO3Uh1wtDh+2brdY2BS9gstlMcLv3xMmA3EYi/zvJs=;
 b=GssH75/irPs+883cq9178M8gLtjjrOizpT39+m8dhguwPfMzICbHIJ8bgjx+gb0vz1
 cT8XfrqZLFd0uOQM3ax0Wai/OEzGILAsQrYCCCzkg9qHkOk3CRhpJViR+cpO5AVkYLp1
 ryNi7H7A1T+UICTt/fiLQoLnpKXHXA8q9BgvHHTU81UtO0T5OMrEIEIv2zc59xeQzLMX
 qLlJ29b8U813YXAnSSj3qjzTlmmaZxl/KhSdxOiOwanS53ekbItdOLw3VaCSqTyf+Jf8
 AOQPyQuOamWnzzU/j9D/1OSTz3ihAdvKSMWvmf55xeEBZ1HFWQc5voCgf+jFngMn/CkX
 EBKQ==
X-Gm-Message-State: AOJu0Yxe2pGgv8Y0kJOkGWyxvFA5afSI1HTn7mtBy9y3VyQIdddtiMbr
 NSI3Tioh6K579iIbGrQyClL6AxT3JApKU8BqvuGnjQWfIZv8qZqfjhMoVOYSeWJk
X-Gm-Gg: ASbGncvpyA+qRjG7d/WYWszkvmmnyIHt2yUWxPID4WP2resunHO0SFQ5+PMUy2XWym6
 pme4Rzl1K+QmiRmv+38L029Q1DojQoTwyEw/wJLlOQB7LRy3OizPZeRaU30ePrL0VG3ObkUDtLI
 Gb0OqLum37sgb9rKgwix8LvLR7dqJktaSMQAPLMJqrOOEEQ2l5iE8dLZxcSrN4Rlbt4ikLBT0U7
 RkZdQrVdYSlNRL+R5IzbWzShT2BpqLZjlYtAjHz6UunFXbDSNT1B2+IrGOBQ+0lb7jiV9tuEBMX
 XdTZmK6IciY70u9aU9iw/2fm3S3dEgUB3Riob04zij3JTY1r1XcA5o5c54mVA3viAfQ5h7Jf7Fh
 v6Sod7QdH5piVhU2tpMJGR6Nc
X-Google-Smtp-Source: AGHT+IFNszOt55Jl3ZLLE+bpO9FfISWn6XgAf6k3Kq62iISHXDZNS0V91RXIuOMj3Y+I+D19ONkfXw==
X-Received: by 2002:a05:600c:1d07:b0:442:c993:6f94 with SMTP id
 5b1f17b1804b1-4532487a5dcmr84119715e9.12.1749747516286; 
 Thu, 12 Jun 2025 09:58:36 -0700 (PDT)
Received: from MacBookPro.localdomain
 ([2a01:4b00:89a0:2400:3954:b164:2078:f5f8])
 by smtp.gmail.com with ESMTPSA id
 5b1f17b1804b1-4532e22460bsm27312955e9.6.2025.06.12.09.58.35
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
 Thu, 12 Jun 2025 09:58:35 -0700 (PDT)
From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.1; insert-file-contents should not set buffer-file-name to nil
X-Debbugs-Cc: 
Date: Thu, 12 Jun 2025 17:58:34 +0100
Message-ID: <m28qlwyk05.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: pass client-ip=2a00:1450:4864:20::335;
 envelope-from=wyuenho@HIDDEN; helo=mail-wm1-x335.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)


When investigating https://github.com/emacs-lsp/lsp-mode/issues/4782 and
https://github.com/purcell/emacs-reformatter/issues/63, I've discovered
the following bug in insert-file-contents.

Reproduction:

1. echo "hello world" > ~/test.txt
2. emacs -q ~/test.txt
3. M-x eval-expression RET (add-hook 'after-change-functions (lambda (&rest _) (message "buffer-file-name: %s, current-buffer: %s" (buffer-file-name) (current-buffer))) nil t) RET
4. Type something into the buffer
5. M-x eval-expression RET (insert-file-contents (buffer-file-name) nil nil nil t) RET
6. Switch to the *Messages* buffer and observe the buffer file name is nil.

Expectation:

insert-file-contents should not set buffer-file-name to nil




Acknowledgement sent to Jimmy Yuen Ho Wong <wyuenho@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#78777; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 14 Jun 2025 15:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.