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; 16 Jun 2025 09:09:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 16 05:09:26 2025
Received: from localhost ([127.0.0.1]:41973 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uR5qI-0007Uo-0T
	for submit <at> debbugs.gnu.org; Mon, 16 Jun 2025 05:09:26 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:36770)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uR5qF-0007TL-Hz
 for 78777 <at> debbugs.gnu.org; Mon, 16 Jun 2025 05:09:24 -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 1uR5q9-0000FQ-W8; Mon, 16 Jun 2025 05:09:18 -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=A0EVvOVEPiBbQFU9ZB/JZ+5FKP60eggKQe4mCcnBqBI=; b=pq4wp+H0NbdM
 SzQ0FhmOlc9yoz/Xcj4D+gURotg+zXC8l+cGqYfVdoIVlkvPM70gNSzvkuP+I6FKDp9JpGtPVxKDg
 l8vRra+fXvXYoSEiBoWN3k92z7QJGydsZUrbSGWvsxZtLOvr+HZFlv8TG2/21kiN8QIHq2VF0FVrd
 hkIIWLMnEHzrgt/WDoHoF/6cnpcjIO160Gbr+xqlLLuJ2fH6WrALLxpiIog7rk9Hlv5bP9YpSIUPk
 JpgnjaCqToa2SjGGdlnHUubA+SQ1wMP3pbjLcWKMkggddxmefoz8NIA1SQYJ6gtFe6nveA/SYMR+i
 T9tz0wm+fs7w6VvFJ/8ZJA==;
Date: Mon, 16 Jun 2025 12:09:14 +0300
Message-Id: <86bjqooxxh.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
In-Reply-To: <CAKDRQS5ZnTKp2u4LO8iZKT=Wci1RSLU=Ak0DMk52GwqqFjt5+g@HIDDEN>
 (message from Jimmy Yuen Ho Wong on Sun, 15 Jun 2025 17:30:47 +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>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 <86tt4hoxs3.fsf@HIDDEN>
 <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@HIDDEN>
 <86sek1ow4v.fsf@HIDDEN>
 <CAKDRQS4J7wKeKG-cm6mAMLuoPRfiGL3DbyZ+mQkMQay_LyQDwQ@HIDDEN>
 <86plf5ov0t.fsf@HIDDEN>
 <CAKDRQS5ZnTKp2u4LO8iZKT=Wci1RSLU=Ak0DMk52GwqqFjt5+g@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: Sun, 15 Jun 2025 17:30:47 +0100
> Cc: 78777 <at> debbugs.gnu.org
> 
>  I understand what you are saying, but not why you think it's a bug.
>  Once again, the call to after-change-functions in this scenario is
>  done not from insert-file-contents, but from the function that decodes
>  the text read from the file.  That function runs in a temporary
>  buffer, which has no associated file name.
> 
> Because the docstring of after-change-functions says the hooks are called with the current buffer, and the
> current buffer at the time insert-file-contents is called, is the file buffer, not the code conversion buffer. The
> message printed out also indicated that the current buffer at the time the after-change-functions lambda is
> called is indeed the file buffer, not the code conversion buffer. The file buffer's buffer-file-name should not
> be set to nil by insert-file-contents or any function it calls. As far as I know, only `insert-file-contents` exhibits
> this undocumented behavior for any functions that change buffer contents.

OK, I see what happens.  insert-file-contents intentionally binds
buffer-file-name temporarily to nil when it is called with REPLACE
non-nil, during the deletion or insertion from the code-conversion
buffer.  It does that to avoid prompting the user via
ask-user-about-supersession-threat, which in this case will confuse.

So this is a feature, an intentional behavior.

> The guarantee of after-change-functions being called with the current buffer isn't very useful if crucial
> variables of the current buffer such as the buffer file name cannot also be guaranteed to remain the same.
> This use case is illustrated by the tickets I linked to in my original report. There exist many file formatter
> packages that replace the content of the current buffer with a temporary file with the formatted file content
> inside a before-save-hook due to slowness of replace-buffer-content. When these packages are used in
> combination with lsp-mode, which has a function added to after-change-functions that needs access to the
> current buffer's file name in order to synchronize the document between the editor and the language server.

I suggest that buffer-modification hooks use buffer-file-truename
instead, it will provide the correct file name in this (and other)
cases.




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; 15 Jun 2025 16:31:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 12:31:39 2025
Received: from localhost ([127.0.0.1]:59292 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQqGc-0004EY-UL
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 12:31:39 -0400
Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:56462)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <wyuenho@HIDDEN>) id 1uQqGY-0004AF-1K
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 12:31:32 -0400
Received: by mail-pl1-x630.google.com with SMTP id
 d9443c01a7336-236470b2dceso30639095ad.0
 for <78777 <at> debbugs.gnu.org>; Sun, 15 Jun 2025 09:31:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1750005084; x=1750609884; 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=/WIIFeTMa5YEvxww0NR7+SohlCY1+1RkcDqUBUBcQ+o=;
 b=JcDHUyJzBxxPSwRZKzT3g+JAkvuot/XPB2qk2/6s07DuKpaQnfE8xShUwvzbAxUs0F
 3fXCw6oCs8NFlWHvp3vY51eR4V5WFRNY4lGpkewBCFwSeNX1RQtn5+6rrcYNvXoWrpkG
 jYUzPtyrAY3bJfnqB/jKHz4PxtLaexxx1IyVrl2votDQfAUbb2ij3CVX35GEhkm1ZD+p
 F5B20Lq59MPxZKdDevSW5JPe5WgjZ6x8zZ3UV1T/gCjdCCzNOhEl3/85d5yIlD07VYPx
 uYl5gHw8OSeqc7nYztEGidCIdsN9zAWm5b+y6B7GkQ7qRfkMmN5tNLcxxr2M4LN4bgRr
 zS/A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1750005084; x=1750609884;
 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=/WIIFeTMa5YEvxww0NR7+SohlCY1+1RkcDqUBUBcQ+o=;
 b=ryk+DboeldcYwS5m5LDhsulfPq5i7enzpfKIJMh56lXhxvmnTc/qM9YXY8GWFK28Gg
 K12bPaQnLwxjKgrjjKzY/cxZ+A7hWNceTt2sa2feM7PNupSKykImsk/oK9AukLlezIPK
 G23yJmT9NkpuEDGyvZQV8vO/BwT3tNvQ74msHBE798W8soxHevxkvvtb/TXyOiiscXpg
 qQu1KYlZOb+u9B402piZtV38mGvAxguM6MZzC8pPXQA/c5TQ53r1m/+toSJKYsoLRqSg
 oiRHmverMpQQG/ofhcYaQS1OJ/VEpVkNWz60udzUEnNYosL/kOF4nGDvp2CDCw8p6MCW
 TaKA==
X-Gm-Message-State: AOJu0Yyg8UtYDmk0EUUaX6P+2PlqWYGH/w3jnD7QHHXJRnyEOHauW3wb
 x49ZEgML4EGdi79o/P3WgIoRpjg3cALrjziuOh+vCB5N+UfdaJXkuTmqZoCTB/VWHp0XlGcJ0lF
 d+at9AmhNJrvMkDqKYvNOrOG6Za6xwqM=
X-Gm-Gg: ASbGncvdPouFbm6G6zn+9v5YMk5iiG7yPESHyadlcg7v/1gSqvG6KGvIQYJXHyBfcWW
 3+unI8piz+INt1dh+SpWcdp2/kY1pSWmYHKZ6Gedtgfv75KElwKKYqnEzdTqyu8km+bo6o23tQd
 spSPJ+D8ffCVYfBAtl4oNG8gb71Sb6f7aKCPwyucHDYfD505de0g3WAWPGEexZHeCH7acSYqoC5
 Uizxw==
X-Google-Smtp-Source: AGHT+IG6S5GoCg5Q1vSqaU9X84nUSUObPKK8hPiiIN6Bs95affgEPyqIQrCyP8knOpiYsdRU9QI3fbc/4UL6vMwSWa0=
X-Received: by 2002:a17:903:18c:b0:234:bca7:2920 with SMTP id
 d9443c01a7336-2366b3ad36fmr98427205ad.24.1750005083527; Sun, 15 Jun 2025
 09:31:23 -0700 (PDT)
MIME-Version: 1.0
References: <m28qlwyk05.fsf@HIDDEN> <8634c4g6v0.fsf@HIDDEN>
 <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 <86tt4hoxs3.fsf@HIDDEN>
 <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@HIDDEN>
 <86sek1ow4v.fsf@HIDDEN>
 <CAKDRQS4J7wKeKG-cm6mAMLuoPRfiGL3DbyZ+mQkMQay_LyQDwQ@HIDDEN>
 <86plf5ov0t.fsf@HIDDEN>
In-Reply-To: <86plf5ov0t.fsf@HIDDEN>
From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
Date: Sun, 15 Jun 2025 17:30:47 +0100
X-Gm-Features: AX0GCFv7I5iwiFE2cecapLtQ9KJxyvlkbCd8PGsqNcQ826kzfZAAhCbhgXGUnAI
Message-ID: <CAKDRQS5ZnTKp2u4LO8iZKT=Wci1RSLU=Ak0DMk52GwqqFjt5+g@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="0000000000005bdd9e06379ecff1"
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 (-)

--0000000000005bdd9e06379ecff1
Content-Type: text/plain; charset="UTF-8"

>
> I understand what you are saying, but not why you think it's a bug.
> Once again, the call to after-change-functions in this scenario is
> done not from insert-file-contents, but from the function that decodes
> the text read from the file.  That function runs in a temporary
> buffer, which has no associated file name.
>

Because the docstring of after-change-functions says the hooks are called
with the current buffer, and the current buffer at the time
insert-file-contents is called, is the file buffer, not the code conversion
buffer. The message printed out also indicated that the current buffer at
the time the after-change-functions lambda is called is indeed the file
buffer, not the code conversion buffer. The file buffer's buffer-file-name
should not be set to nil by insert-file-contents or any function it
calls. As far as I know, only `insert-file-contents` exhibits this
undocumented behavior for any functions that change buffer contents.

The guarantee of after-change-functions being called with the current
buffer isn't very useful if crucial variables of the current buffer such as
the buffer file name cannot also be guaranteed to remain the same. This use
case is illustrated by the tickets I linked to in my original report. There
exist many file formatter packages that replace the content of the current
buffer with a temporary file with the formatted file content inside a
before-save-hook due to slowness of replace-buffer-content. When these
packages are used in combination with lsp-mode, which has a function added
to after-change-functions that needs access to the current buffer's file
name in order to synchronize the document between the editor and the
language server.

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

<div dir=3D"ltr"><div class=3D"gmail_quote gmail_quote_container"><blockquo=
te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px =
solid rgb(204,204,204);padding-left:1ex">I understand what you are saying, =
but not why you think it&#39;s a bug.<br>
Once again, the call to after-change-functions in this scenario is<br>
done not from insert-file-contents, but from the function that decodes<br>
the text read from the file.=C2=A0 That function runs in a temporary<br>
buffer, which has no associated file name.<br></blockquote><div><br></div><=
div>Because the docstring of after-change-functions says the hooks are call=
ed with the current buffer, and the current buffer at the time insert-file-=
contents is called, is the file buffer, not the code conversion buffer. The=
 message printed out also indicated that the current buffer at the time the=
 after-change-functions lambda is called is indeed the file buffer, not the=
=C2=A0code conversion buffer. The file buffer&#39;s buffer-file-name should=
 not be set to nil by insert-file-contents or any function it calls.=C2=A0A=
s far as I know, only `insert-file-contents` exhibits this undocumented beh=
avior for any functions that change=C2=A0buffer contents.</div><div><br></d=
iv><div>The guarantee of after-change-functions being called with the curre=
nt buffer isn&#39;t very useful if crucial variables of the current buffer =
such as the buffer file name cannot also be guaranteed to remain the same. =
This use case is illustrated by the tickets I linked to in my original repo=
rt. There exist many file formatter packages that replace=C2=A0the content =
of the current buffer with a temporary file with the formatted file content=
 inside a before-save-hook due to slowness of replace-buffer-content. When =
these packages are used in combination with lsp-mode, which has a function =
added to after-change-functions that needs access to the current buffer&#39=
;s file name in order to synchronize the document between the editor and th=
e language server.<br><br><br></div></div></div>

--0000000000005bdd9e06379ecff1--




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; 15 Jun 2025 16:00:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 12:00:00 2025
Received: from localhost ([127.0.0.1]:59052 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQpm0-0007TO-0N
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:59:59 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:44072)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uQply-0007T1-Bs
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:59:54 -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 1uQplt-0005j6-1T; Sun, 15 Jun 2025 11:59: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=hlySn9ad508m5i/MkjtWtgTyj0A0TlrZwiWCAhvCiDA=; b=NrL6vpx06gjH
 /eFsoPoE5auGhLUNGF9oX1NjVnXADDvIxzYMBm9mBHiE4KVJ86J1ppDJ5M4eAtI665XSYoQHzy4F3
 JbKB6nalS/dW7Q70Wcxn1ZVMkp5azXW23xDBE6E9RfxVfekCNY5j+ikQWrd73EGP4VXpDYulSquvO
 T1Z0LMdKyFAtHQ6wXcZsigQv5DoLgEcX5Gjgr9ynAvFKHoqT8+j2a/wucN3itkyfZfDaR4vSLRlaV
 44y4LH5hxV3OGjHDY7ulrlCvK3qcF7+hE612K20+LVsE5hiEhbn+OctuqtaCoxCnPwxAdSSl8qm5L
 +1aVAuY0uzQLAhDOvhBftA==;
Date: Sun, 15 Jun 2025 18:59:46 +0300
Message-Id: <86plf5ov0t.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
In-Reply-To: <CAKDRQS4J7wKeKG-cm6mAMLuoPRfiGL3DbyZ+mQkMQay_LyQDwQ@HIDDEN>
 (message from Jimmy Yuen Ho Wong on Sun, 15 Jun 2025 16:40:42 +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>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 <86tt4hoxs3.fsf@HIDDEN>
 <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@HIDDEN>
 <86sek1ow4v.fsf@HIDDEN>
 <CAKDRQS4J7wKeKG-cm6mAMLuoPRfiGL3DbyZ+mQkMQay_LyQDwQ@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: Sun, 15 Jun 2025 16:40:42 +0100
> Cc: 78777 <at> debbugs.gnu.org
> 
>  Yes, and that lone call is never made in your scenario.
> 
>  So I'm no longer sure what problem are we discussing here.
> 
> The lone call to insert-file-contents, as in step 5 of my reproduction. Calling insert-file-contents after typing in
> a file buffer runs the after-change-functions hooks. When these hooks are run, the current buffer's file name
> is seen to have been temporarily set to nil, which should not be the case.
> 
> Is this clear?

I understand what you are saying, but not why you think it's a bug.
Once again, the call to after-change-functions in this scenario is
done not from insert-file-contents, but from the function that decodes
the text read from the file.  That function runs in a temporary
buffer, which has no associated file name.

The Subject of this bug says "insert-file-contents should not set
buffer-file-name yo nil", but what I found that insert-file-contents
doesn't set buffer-file-name to nil.  It's an illusion created by the
way you use after-change-functions.





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; 15 Jun 2025 15:41:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 11:41:26 2025
Received: from localhost ([127.0.0.1]:58859 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQpU5-0005wT-Sx
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:41:26 -0400
Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:56770)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <wyuenho@HIDDEN>) id 1uQpU4-0005vr-GT
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:41:24 -0400
Received: by mail-pj1-x1034.google.com with SMTP id
 98e67ed59e1d1-313eeb77b1fso1436076a91.1
 for <78777 <at> debbugs.gnu.org>; Sun, 15 Jun 2025 08:41:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1750002078; x=1750606878; 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=DFHu8DlShvYlPh21YBz08axkFTvT1mXonZ+h2/AZy1Q=;
 b=JfeM5Z0e2zttmYoxcU6TyzM2SMZaaf6io0YjmObi4kAsyQAgd1PsYgcnIQNtR3OQBM
 dpZA6JeNh7Ow5/uKtgzMoFi7pnCSe2nNbgnaNSXLOPA+e/+XsN4DJRJCxe+vmQnmaJtS
 +6lSsB6CVNzqYyEN7F0zO1xLjPJedX5ttrXU40f7/25N25sTvE/RJ0MayYQ8WFFRN7Hg
 HCxpVS4EB+uZR9sNhA8/B7/MQOhGcfBYOTO6sy+EFOl9xRusOVE4gKy9NtesIQ7CGEaH
 OLN3TsNgnnXKRHubY0NBD6P6Q50oA2DIw4xBHFqVpb3d0141mFjQeu4D3a/zZIM13kDB
 PGLw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1750002078; x=1750606878;
 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=DFHu8DlShvYlPh21YBz08axkFTvT1mXonZ+h2/AZy1Q=;
 b=owuGW4WNMPCiyga20uYPoE/docsrMW7/y1bV0d2AGTQRAFxkN0gDFQ9zkDgrAz2aQA
 PR14M6Me4cdU1Iid9JVZHJDHJ6KJX2viD2guMDjn9Z1xtCdjJD2uT74rqRQlWvUmO5xW
 Jnn1xP/HaIkEdzjPF8bu3s0s+/DsCXlfDDL6hZZJChCCm6UDMOa9Xd75z3rQXyfzuqlj
 8PU+JJvWiHcUk2iU4mpEjs9xyi9JnkhA/jloPJDVDm9ctfj1Z3p4tythQxMWeHc3vw2S
 r+kS4tgLAcABGC8R4VcY8pnPGwtODxY1/a07Lx+55FoBIpeqgmJzceT/ptw6MKHwte2N
 sDEQ==
X-Gm-Message-State: AOJu0YwLuJK59ay8bWeKu19hguLYO0rmS+zT4rtNJaa/hxuJ3snHFm20
 n6p30Tc/t0Q14TGlQzemj9oQZXEoc2TjcddAbdZOqd3Pr4DzEIXxzl6H0VuZVFuEhgW5IIzzz+X
 Sz2xiCAFxDsfLzdt26dKXx5ZBSZ1S8xmShtF1
X-Gm-Gg: ASbGnctg/y1PHwBsMjDqUcUW5BtN9mHGUnjMZiAJw3m84cWmjoVfNVV8iy2X97QmE80
 FYRGvQn+pHzhLqCScMw8U/aogEAF15mC/eQIfT8wq5dAdN0Xy7vcHxnWA8xd+CQN4cPoX2PgZ1j
 Lub3ueIF34KUzBE23ddqR0pFzsj15wNa/8kNxGugyZGwKHOzgzDafMJigvCT8EWpcFmBHAsFB79
 Xyp6IvdYm8vbts=
X-Google-Smtp-Source: AGHT+IFoogzMSllS53ckli/e8tTbV9MB7TZsdvam0SL6jmvTWnQ6ymqJK8L+fs0vpHewgFkzNFIf/WjoH+NvXRZa+Jo=
X-Received: by 2002:a17:90b:3c8a:b0:311:ba32:164f with SMTP id
 98e67ed59e1d1-313f1c9d429mr9880068a91.8.1750002078365; Sun, 15 Jun 2025
 08:41:18 -0700 (PDT)
MIME-Version: 1.0
References: <m28qlwyk05.fsf@HIDDEN> <8634c4g6v0.fsf@HIDDEN>
 <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 <86tt4hoxs3.fsf@HIDDEN>
 <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@HIDDEN>
 <86sek1ow4v.fsf@HIDDEN>
In-Reply-To: <86sek1ow4v.fsf@HIDDEN>
From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
Date: Sun, 15 Jun 2025 16:40:42 +0100
X-Gm-Features: AX0GCFu8UCxFAtV8GIAQqUZqHJ3hF_ez-VyT1GUYThpfp2CbMt1UaBIQSrzBVTY
Message-ID: <CAKDRQS4J7wKeKG-cm6mAMLuoPRfiGL3DbyZ+mQkMQay_LyQDwQ@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="0000000000003cbe3206379e1cca"
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 (-)

--0000000000003cbe3206379e1cca
Content-Type: text/plain; charset="UTF-8"

> Yes, and that lone call is never made in your scenario.
>
> So I'm no longer sure what problem are we discussing here.
>

The lone call to insert-file-contents, as in step 5 of my reproduction.
Calling insert-file-contents after typing in a file buffer runs the
after-change-functions hooks. When these hooks are run, the current
buffer's file name is seen to have been temporarily set to nil, which
should not be the case.

Is this clear?

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

<div dir=3D"ltr"><div dir=3D"ltr"></div><div class=3D"gmail_quote gmail_quo=
te_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">Yes, and th=
at lone call is never made in your scenario.<br>
<br>
So I&#39;m no longer sure what problem are we discussing here.<br></blockqu=
ote><div><br></div><div>The lone call to insert-file-contents, as in step 5=
 of my reproduction. Calling insert-file-contents after typing in a file bu=
ffer runs the after-change-functions hooks. When these hooks are run, the c=
urrent buffer&#39;s file name is seen to have been temporarily set to nil, =
which should not be the case.<br><br>Is this clear?</div></div></div>

--0000000000003cbe3206379e1cca--




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; 15 Jun 2025 15:35:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 11:35:55 2025
Received: from localhost ([127.0.0.1]:58795 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQpOl-0005Sz-Aw
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:35:55 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:35260)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uQpOi-0005Sh-Ut
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:35:53 -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 1uQpOd-0003HU-Ix; Sun, 15 Jun 2025 11:35:47 -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=98hqSp1/Jsvj/frttWGAQKXbV4M1FEBl5rakRCTMVfQ=; b=UaxZSiprAEAX
 tvib/o6cmchfx3f41z661Aj1H1QR83S8CZxLGlODtB5rKq4cyeXSSGe4Zt4Np4ETpmiHdfePI0VlU
 NGVmy2XQ1dG2qSgLOcqcb7sbspLtYD1a4cWFRLygbJAikzXukJjhvHrWl30w5Xbp2HC7HegKeMsbg
 GEMrFsbwBQoTZHZIaFT97daftVBLuOppzqIPEmhzvhiOV0hos9N9MJrSs8xCYkg8vs3TXkCmQqnRu
 xcFTQgyzztUlF+n2LUj7k4rpWwPYAffp3p/lrEj3pEGm12mVH2w7z58F8Oksm0qqr9HbXFyllJHmX
 TOf4B6hWI1dyPgtsuvAakw==;
Date: Sun, 15 Jun 2025 18:35:44 +0300
Message-Id: <86sek1ow4v.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
In-Reply-To: <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@HIDDEN>
 (message from Jimmy Yuen Ho Wong on Sun, 15 Jun 2025 16:17:43 +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>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 <86tt4hoxs3.fsf@HIDDEN>
 <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@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: Sun, 15 Jun 2025 16:17:43 +0100
> Cc: 78777 <at> debbugs.gnu.org
> 
>  That's not what I see.  The only call to after-change-functions that
>  insert-file-contents does is not done in your recipe: if I set a
>  breakpoint there, it is never hit.
> 
>  So I have no doubt that what you see is an unrelated call to
>  after-change-functions.  The evidence that current-buffer returns the
>  buffer name you expect is not enough: the actual current buffer can be
>  different, and I saw it in GDB.
> 
>  So, given what I see under a debugger, there's no bug here.
> 
>  Why did you think insert-file-contents should at all call
>  after-change-functions in this scenario?
> 
> I was never able to set up GDB as I'm on a Mac, so I actually am not sure if the signal_after_change call is
> made directly inside insert-file-contents. Looking at it again, it can't possibly be called there as that line is
> under the notfound label, which is only jumped to when the file descriptor is invalid.
> 
> It is possible that some other Emacs internal machinery set the current buffer-file-name to nil temporarily and
> invoke signal_after_change after insert-file-contents has replaced the buffer content, but I have not been
> able to identify where. What is sure is a lone call to insert-file-contents runs the after-change-functions.

Yes, and that lone call is never made in your scenario.

So I'm no longer sure what problem are we discussing 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; 15 Jun 2025 15:18:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 11:18:28 2025
Received: from localhost ([127.0.0.1]:58580 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQp7s-0000xA-6N
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:18:28 -0400
Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:53367)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <wyuenho@HIDDEN>) id 1uQp7p-0000wZ-P7
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:18:26 -0400
Received: by mail-pj1-x102c.google.com with SMTP id
 98e67ed59e1d1-311a6236effso3065307a91.2
 for <78777 <at> debbugs.gnu.org>; Sun, 15 Jun 2025 08:18:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1750000699; x=1750605499; 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=9o1ybaWxTqGMJn1x7AsYJV8RUljz2gp1L14Hzrro4IY=;
 b=jmQppMDoHl5QHJhqTTYScBiyO82l9/wC7QzWPSiuHSxe1AjwusSfEWehojF45/MUYq
 6SJ0+pRnRt3WTS2u6iDVyBDqvNrgeSIRHkmaznp0GE3jEECLBc+ZVW5PSTjRHBJ3GK7A
 8ZSGsHu4YIoYzX5qWB95CfvzLYpuO+D0HlYrzV2j943a+sGy+LmW5BMRirJ7lENg2fDL
 CVOvIfcnfDfSn4v+z13/jZygcWCMSPp0YCjzxbCbcCdjKUjy+aKxGrZedDkBqjHHDl0e
 mZTeTPVUi1eK57Gga5XpGDpuy3yVbJZiktK58pBUOHSZzFTA+bgoXg4XS5pZO5u0vLWa
 s+2g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1750000699; x=1750605499;
 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=9o1ybaWxTqGMJn1x7AsYJV8RUljz2gp1L14Hzrro4IY=;
 b=P7kTBTnq6SneoFCaE9yfzW0bhDNLJjrE5KZ1tNEPNUa5vVZ59ah4c0J9xYBAun5DId
 fryWQ8UmJLPZPqXcU6p2mwcnXqDZPWqQeojSL9T9pX9fOLrYo7TT081NlMmSbewXvYde
 FOqMmm2nGx5ZgaoruJh773HjXgOVyKSHiyhmVw/8MDQNgkYyAYPqYLSj78U+AoxflkVF
 fTdeXMRaklpxG5Bt+mJ81pDre6DZNTIS9J5MALeO7hBTtJagvIEpRh8fdZkFX+9yGav9
 h9pHgmgnp6yp14lAKjr8+JYiLGgFPv8IwbbRU92WI9pS0XgItTit3jcEIvTAAEJfr9OI
 m3Yg==
X-Gm-Message-State: AOJu0YzPsB7LDoKE9uMsM26nB5hknAZtLliAkA49N0QJAdFXDa0kWpCb
 rodiht9d9aJcUAukxZ2r73sD8sVyJlbWMIXAVMityHaZ9+XlxV+fCEQjk7MY/15JsvULtypwq8L
 /GA+HUuoBA0SaWktYv2BL+3JLrCQEPNk=
X-Gm-Gg: ASbGncs8YzxHf0pg9ghp583+DnSKNhLHN4xAwPmaNSGLMUJ9lTm7sk2VdLfQiozQWxo
 untQLNDMKmtBINBAqJVIZzJ3lHZCtfd4xwsipEBgRdAuqCjPqnlA3M77724MTFkU2VnSGSQdyaQ
 muSgosE4QBW5ZkJwm9vF8e1T5qIqurUHsmDFTstKRL9xd/HTpXJRbyDt4TNbf7flF5xvhQpp5yp
 oyJ
X-Google-Smtp-Source: AGHT+IEApyLcmBVYpy/IX/JhUsMuO/PX0U1u3Uwgv5X74gFJLr4566L5+F3/Jz7OlXkMTBSkaJLNt4rXw6WQdppDvww=
X-Received: by 2002:a17:90b:1ccc:b0:311:2f5:6b1 with SMTP id
 98e67ed59e1d1-313f1deb5efmr8011647a91.22.1750000699518; Sun, 15 Jun 2025
 08:18:19 -0700 (PDT)
MIME-Version: 1.0
References: <m28qlwyk05.fsf@HIDDEN> <8634c4g6v0.fsf@HIDDEN>
 <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 <86tt4hoxs3.fsf@HIDDEN>
In-Reply-To: <86tt4hoxs3.fsf@HIDDEN>
From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
Date: Sun, 15 Jun 2025 16:17:43 +0100
X-Gm-Features: AX0GCFsOX0OCiAXP1RfCot_06t3x5CZP7sqLceRiN5Ow85wKwdUo-czWaEhT2F0
Message-ID: <CAKDRQS43dwbkJGktwH73CyunmRSgEYLzZAq9s7nPGDhtKX0Stg@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="0000000000000d36d706379dca95"
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 (-)

--0000000000000d36d706379dca95
Content-Type: text/plain; charset="UTF-8"

>
> That's not what I see.  The only call to after-change-functions that
> insert-file-contents does is not done in your recipe: if I set a
> breakpoint there, it is never hit.
>
> So I have no doubt that what you see is an unrelated call to
> after-change-functions.  The evidence that current-buffer returns the
> buffer name you expect is not enough: the actual current buffer can be
> different, and I saw it in GDB.
>
> So, given what I see under a debugger, there's no bug here.
>
> Why did you think insert-file-contents should at all call
> after-change-functions in this scenario?
>

I was never able to set up GDB as I'm on a Mac, so I actually am not sure
if the signal_after_change call is made directly inside
insert-file-contents. Looking at it again, it can't possibly be called
there as that line is under the notfound label, which is only jumped to
when the file descriptor is invalid.

It is possible that some other Emacs internal machinery set the current
buffer-file-name to nil temporarily and invoke signal_after_change after
insert-file-contents has replaced the buffer content, but I have not been
able to identify where. What is sure is a lone call to insert-file-contents
runs the after-change-functions.

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

<div dir=3D"ltr"><div class=3D"gmail_quote gmail_quote_container"><blockquo=
te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px =
solid rgb(204,204,204);padding-left:1ex">That&#39;s not what I see.=C2=A0 T=
he only call to after-change-functions that<br>
insert-file-contents does is not done in your recipe: if I set a<br>
breakpoint there, it is never hit.<br>
<br>
So I have no doubt that what you see is an unrelated call to<br>
after-change-functions.=C2=A0 The evidence that current-buffer returns the<=
br>
buffer name you expect is not enough: the actual current buffer can be<br>
different, and I saw it in GDB.<br>
<br>
So, given what I see under a debugger, there&#39;s no bug here.<br>
<br>
Why did you think insert-file-contents should at all call<br>
after-change-functions in this scenario?<br></blockquote><div><br>I was nev=
er able to set up GDB as I&#39;m on a Mac, so I actually am not sure if the=
 signal_after_change call is made directly inside insert-file-contents. Loo=
king at it again, it can&#39;t possibly be called there as=C2=A0that line i=
s under the notfound label, which is only jumped to when the file descripto=
r is invalid.<br><br>It is possible that some other Emacs internal machiner=
y=C2=A0set the current buffer-file-name to nil temporarily and invoke signa=
l_after_change after insert-file-contents has replaced the buffer content, =
but I have not been able to identify where. What is sure is a lone call to =
insert-file-contents runs the after-change-functions.</div></div></div>

--0000000000000d36d706379dca95--




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; 15 Jun 2025 15:00:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 11:00:28 2025
Received: from localhost ([127.0.0.1]:58394 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQoqQ-0007hv-Fd
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:00:28 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:46446)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uQoqL-0007fL-D2
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 11:00:24 -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 1uQoqF-0003gj-GQ; Sun, 15 Jun 2025 11:00:15 -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=d2fHmMFnhhL3lOR2t0VdnglBIk4sQCjXbBJTaM9iDSw=; b=Z4g8H7W4MAVw
 ZVRDmOS7T/nYuJAftKytxy3yJ/R52eGOC1efkqfiWbx5lrw9dbXyKJBk7JaC9BWeW41eUOe+p60k5
 iGdVHeq54sSsOjqul7j79j0JYGK3be81QkaWBvOxVOfwv1LDxMXYAEBBs0DE+BOTkT7oAwRSmHZbv
 xsmNjC94stZAdn2CNvxNSHkKm/23esZ3s5i16knHHcleF3skbbnIY06TTOVaLAIL44C5TxPj5WvBh
 IzSrvlwQ5rzpTg2CiU2nHNAhUOLlDFh2if25HUqacORABrL8qwDyi1IEGep5z1Omwvn1TZjOnNeXp
 KiDJykYYHW+DikpdqaKYBg==;
Date: Sun, 15 Jun 2025 18:00:12 +0300
Message-Id: <86tt4hoxs3.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
In-Reply-To: <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@HIDDEN>
 (message from Jimmy Yuen Ho Wong on Sun, 15 Jun 2025 15:45:02 +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>
 <86y0tuqsut.fsf@HIDDEN>
 <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@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: Sun, 15 Jun 2025 15:45:02 +0100
> Cc: 78777 <at> debbugs.gnu.org
> 
>  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.
> 
>  I have suspected the same as the only call to set a buffer's name to nil is found in the implementation of
> insert-file-contents near the code conversion buffer, but that's a red herring. As you can see from my
> report, the after-change-function does contain a call to (current-buffer), and the message prints out the file
> buffer's name correctly.

That's not what I see.  The only call to after-change-functions that
insert-file-contents does is not done in your recipe: if I set a
breakpoint there, it is never hit.

So I have no doubt that what you see is an unrelated call to
after-change-functions.  The evidence that current-buffer returns the
buffer name you expect is not enough: the actual current buffer can be
different, and I saw it in GDB.

So, given what I see under a debugger, there's no bug here.

Why did you think insert-file-contents should at all call
after-change-functions in this scenario?




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; 15 Jun 2025 14:45:51 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 15 10:45:51 2025
Received: from localhost ([127.0.0.1]:58360 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uQocG-0006TU-Dp
	for submit <at> debbugs.gnu.org; Sun, 15 Jun 2025 10:45:50 -0400
Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:53493)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <wyuenho@HIDDEN>) id 1uQocC-0006SA-5b
 for 78777 <at> debbugs.gnu.org; Sun, 15 Jun 2025 10:45:45 -0400
Received: by mail-pj1-x102d.google.com with SMTP id
 98e67ed59e1d1-311a6236effso3053848a91.2
 for <78777 <at> debbugs.gnu.org>; Sun, 15 Jun 2025 07:45:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1749998738; x=1750603538; 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=X6tVdVfxSydgdM4f/igaGl0qVNgO512xbYGg7emeyXI=;
 b=fdShh+gWvzuEzXKSSPTpN4zjMFtW1Jtlv4G0D/196GDUsMfmhjgYLMfIE1CjGlV3+f
 8hyN0fDrk/yy/bnZpHZtuC7tIuVMoeVoTq1EaDj0f1QOx9jfay91utdh8CVtyvBf0ril
 tOs9napRsbLySYcjBlYS9xtequTN1k05qzVMWPUZWDfBmnwPFSKrDZBhBCNU+vv6OZNU
 b6qRJb+KzAf0/bylzVa4KidDDioIlT8yRxEtOd3ZBE5PnrlWQ5QfLljh8FmxILo7jPk1
 7uXjgj7E6yHhbZJTwDm4Pqlf6nPX9Y/S4E2C377TzFkFC2SIXe0nGtl5om7Gvjw36AoV
 iHvg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1749998738; x=1750603538;
 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=X6tVdVfxSydgdM4f/igaGl0qVNgO512xbYGg7emeyXI=;
 b=XQp6oq0ylyqv04CBQXvMAeTOzKSBlLRnXPFgy/YLGs/XT0c4Ph6lZH0bgwlsfxSNfp
 x7jM+4XScgMlcXhWGfiIZUVC3vftqJDJb8Ar707nzLQqXWgesYvksPqkzkN1dkT0Z3gs
 xSM6P9Azm34a3SrqiOJWeBahmsborv9c61yl3fEomVvev8rHN3ywRv2cWpT0X6LMKPj4
 q6rwyTdlWQ5tfFjSvEkKq2riP5jO+nT4CBt5hf14sGFlhxeIPNURVky4+2Ciz2+0QpY0
 7MfSYKui6ycFgn2Rmc3p0MWGUvZlho5Qt8JcOZf3nFcqKfor6iVEmHHJVeWHsLUCnWED
 B5NA==
X-Gm-Message-State: AOJu0YzEkYpt1qltWZOcXTw8BY9N9IPsU00BP9KFvIEUQ8vOk4kdR6dX
 UGIdWMbLePeu7t1KNrA7eVn+3dUhk3ojtyp/fHXOHQiVxmC5S4HbZfsxtAZW41A1iBDPFRzQHVd
 u5Lh5/18RYVyl5WO7pg3poUDxlKH5p90=
X-Gm-Gg: ASbGncv6KpPGb869il38Qcus1glhAlw/j6ZWGhbc7mjGEeNp/KiQgIqYWbAOu/UGYgb
 gEqPv89o2VVLQEwOp7b/jHGRL2+ydzcwmky7YMhyoP7O6uw+99mWOpiOCgPoEJFgp4rQWcmaZGo
 wAiE/7J5VZ+UYQqYrGmd2nv6PLX0eWg3PjGhfXY9U9kH57wEz7xqbH4j1vhXVl+17NVTA5xDzB6
 Pd6RvpwYF83kUA=
X-Google-Smtp-Source: AGHT+IEP2NyOYXf8MIlh66W1kb3t8aatpq6TNQrdO1O47muj2ugaSbqr+hkxiBrvn1/LCmc29UR8MJ+V2pRzR7kUTmo=
X-Received: by 2002:a17:90b:1cc3:b0:311:d05c:936 with SMTP id
 98e67ed59e1d1-313f1daa6a7mr11166319a91.17.1749998737899; Sun, 15 Jun 2025
 07:45:37 -0700 (PDT)
MIME-Version: 1.0
References: <m28qlwyk05.fsf@HIDDEN> <8634c4g6v0.fsf@HIDDEN>
 <CAKDRQS7tZp_7SYS1Kh-zvUSuEnaRnzWQSoJvqMTRjO_fzt=19w@HIDDEN>
 <86y0tuqsut.fsf@HIDDEN>
In-Reply-To: <86y0tuqsut.fsf@HIDDEN>
From: Jimmy Yuen Ho Wong <wyuenho@HIDDEN>
Date: Sun, 15 Jun 2025 15:45:02 +0100
X-Gm-Features: AX0GCFuRQSbY75kP85g0DZOZLAyJy69SsU2a3Ea-rfnkHdD2EY-oKfYGLE-D8mM
Message-ID: <CAKDRQS4v=YOkso_=Nn81rYvqmvO9jgwoW4m+JhyOw+oSo6oMOg@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="00000000000021460506379d55dd"
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 (-)

--00000000000021460506379d55dd
Content-Type: text/plain; charset="UTF-8"

> 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.
>

 I have suspected the same as the only call to set a buffer's name to nil
is found in the implementation of insert-file-contents near the code
conversion buffer, but that's a red herring. As you can see from my report,
the after-change-function does contain a call to (current-buffer), and the
message prints out the file buffer's name correctly.

Curiously, if you save the file between step 4 and 5 from my reproduction
instruction, the buffer-file-name is printed correctly.

Hope this helps.

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

<div dir=3D"ltr"><div dir=3D"ltr"></div><div class=3D"gmail_quote gmail_quo=
te_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">I think you=
r after-change-function is called not due to<br>
insert-file-contents inserting the text from the file, but from the<br>
functions that decode the file&#39;s text.=C2=A0 To see if this is true, ma=
ke<br>
your after-change-function show the name of the current buffer.=C2=A0 If<br=
>
I&#39;m right, you will see something like &quot; *code conversion works&qu=
ot; as<br>
the name of the buffer, in which case indeed buffer-filename is<br>
expected to be nil, and I don&#39;t see a bug here.<br></blockquote><div><b=
r></div><div>=C2=A0I have suspected the same as the only call to set a buff=
er&#39;s name to nil is found in the implementation of insert-file-contents=
 near the code conversion buffer, but that&#39;s a red herring. As you can =
see from my report, the after-change-function does contain a call to (curre=
nt-buffer), and the message prints out the file buffer&#39;s name correctly=
.<br><br>Curiously, if you save the file between step 4 and 5 from my repro=
duction instruction, the buffer-file-name is printed correctly.</div><div><=
br></div><div>Hope this=C2=A0helps.</div></div></div>

--00000000000021460506379d55dd--




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; 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: Mon, 16 Jun 2025 09:15:01 UTC

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