From unknown Fri Aug 15 16:00:48 2025 X-Loop: help-debbugs@gnu.org Subject: bug#65308: (find-file) botches buffer-file-name in -batch mode Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Aug 2023 11:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65308 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 65308@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.169209869911554 (code B ref -1); Tue, 15 Aug 2023 11:25:02 +0000 Received: (at submit) by debbugs.gnu.org; 15 Aug 2023 11:24:59 +0000 Received: from localhost ([127.0.0.1]:35091 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsAU-00030I-Sa for submit@debbugs.gnu.org; Tue, 15 Aug 2023 07:24:59 -0400 Received: from lists.gnu.org ([2001:470:142::17]:40598) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsAS-000300-Ib for submit@debbugs.gnu.org; Tue, 15 Aug 2023 07:24:57 -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 ) id 1qVsAL-0006Rt-MM for bug-gnu-emacs@gnu.org; Tue, 15 Aug 2023 07:24:49 -0400 Received: from forward102c.mail.yandex.net ([178.154.239.213]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qVsAI-0003xf-Ba for bug-gnu-emacs@gnu.org; Tue, 15 Aug 2023 07:24:49 -0400 Received: from mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1380:0:640:6985:0]) by forward102c.mail.yandex.net (Yandex) with ESMTP id 2B1C860103 for ; Tue, 15 Aug 2023 14:24:39 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id cOdxhS4DaW20-N4WpIQAV; Tue, 15 Aug 2023 14:24:38 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1692098678; bh=ujgWMJV/dBYLLyOBZa6XfR0qPxagY0UI29S1Jj59+7c=; h=Date:To:From:Subject:Message-ID; b=TPUvcLwqaxGiZxFNAXN2KrNMrwtX470m0atagqAAvPNNUlIFMm3SYPmjf4xLG1Yco +MaCbZ1aDd+i2NQ436j0266gQGFE4zAd30Wjcn4lXUgN+SLwcz7Qsw0jncM6YovqGl 4YmhHZVZfLKAg88Fo+5LC+xl9lryau4V1LvaHOm8= Authentication-Results: mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> From: Konstantin Kharlamov Date: Tue, 15 Aug 2023 14:25:16 +0300 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 MIME-Version: 1.0 Received-SPF: pass client-ip=178.154.239.213; envelope-from=Hi-Angel@yandex.ru; helo=forward102c.mail.yandex.net 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, 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) This was found while trying to use Emacs in `-batch` mode to regexp- replace many files in a project. Turns out calling `(save-buffer)` will make it say that directory does not exist, and the reason for that is that `buffer-file-name` gets mangled filename. # Steps to reproduce $ mkdir dir && touch dir/1 dir/2 $ emacs -batch --eval '(progn (dolist (file command-line-args-left) (find-= file file) (print buffer-file-name))))' dir/1 dir/2 = =20 "/tmp/dir/1" "/tmp/dir/dir/2" ## Expected Second print would say `/tmp/dir/2` ## Actual Second print refers to non-existing `/tmp/dir/dir/2`. # Versions tested Reproducible with stable 29.1 and somewhat old master as of commit 04710bd01b2 From unknown Fri Aug 15 16:00:48 2025 X-Loop: help-debbugs@gnu.org Subject: bug#65308: (find-file) botches buffer-file-name in -batch mode Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Aug 2023 12:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65308 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Konstantin Kharlamov Cc: 65308@debbugs.gnu.org Received: via spool by 65308-submit@debbugs.gnu.org id=B65308.16921010223033 (code B ref 65308); Tue, 15 Aug 2023 12:04:02 +0000 Received: (at 65308) by debbugs.gnu.org; 15 Aug 2023 12:03:42 +0000 Received: from localhost ([127.0.0.1]:35129 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsly-0000mp-DQ for submit@debbugs.gnu.org; Tue, 15 Aug 2023 08:03:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsls-0000mW-Pe; Tue, 15 Aug 2023 08:03:40 -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 ) id 1qVsln-0003LH-8f; Tue, 15 Aug 2023 08:03:31 -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=oAuf7RTblIkJIyMtnvWlMNZsPUcFfqGzSxB/zhWEAEY=; b=MKC9bzI6N6Yf +QWmCzkp/fiBBGhdPApNMzC8954pKDuzsFqTznv+bKTx1nnvWpwIIE2zBngU+XKdcpLHSfWuyk1mZ hyvQgYYtv4wr+W04bm7bhINV5UlEzwrd1+TkqZx1onsAdxls4Eg6k299rftYI+3wKvdCa0hYraG5Y /1P2QUn9DLnxf6n+MKvT8W3AhzaLXXrLXdql9RpYDi7kgA4681IgYqMLAvgd/0Ik9/3fSvcLDRdr1 p4iNAoIoY9ATT7g8OIDkwRAK1vpSs6Sz3l/Pa8d/A1jPyHi8EKoZokO92mxl5Xml++P5DM4G3wzwP p3Nc7HeyC8Z1Y/oHwUq5BQ==; Date: Tue, 15 Aug 2023 15:03:15 +0300 Message-Id: <83leeca4xo.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> (message from Konstantin Kharlamov on Tue, 15 Aug 2023 14:25:16 +0300) References: <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) tags 65308 notabug thanks > From: Konstantin Kharlamov > Date: Tue, 15 Aug 2023 14:25:16 +0300 > > $ mkdir dir && touch dir/1 dir/2 > $ emacs -batch --eval '(progn (dolist (file command-line-args-left) (find-file file) (print buffer-file-name))))' dir/1 dir/2 > > "/tmp/dir/1" > > "/tmp/dir/dir/2" > > ## Expected > > Second print would say `/tmp/dir/2` > > ## Actual > > Second print refers to non-existing `/tmp/dir/dir/2`. IMO, this is the expected behavior: relative file names are interpreted relative to the current buffer's default-directory. After the first find-file, the current buffer visits the file "/tmp/dir/1", whose default-directory is "/tmp/dir/". There's no bug here. To get what you want, run the command-line arguments through expand-file-name _before_ calling find-file. From unknown Fri Aug 15 16:00:48 2025 X-Loop: help-debbugs@gnu.org Subject: bug#65308: (find-file) botches buffer-file-name in -batch mode Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Aug 2023 12:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65308 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: notabug To: Eli Zaretskii Cc: 65308@debbugs.gnu.org Received: via spool by 65308-submit@debbugs.gnu.org id=B65308.169210179414461 (code B ref 65308); Tue, 15 Aug 2023 12:17:02 +0000 Received: (at 65308) by debbugs.gnu.org; 15 Aug 2023 12:16:34 +0000 Received: from localhost ([127.0.0.1]:35136 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsyQ-0003lA-9C for submit@debbugs.gnu.org; Tue, 15 Aug 2023 08:16:34 -0400 Received: from forward502a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:d502]:48834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsyL-0003kt-Nn for 65308@debbugs.gnu.org; Tue, 15 Aug 2023 08:16:32 -0400 Received: from mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:5e51:0:640:23ee:0]) by forward502a.mail.yandex.net (Yandex) with ESMTP id 7E1C95E772; Tue, 15 Aug 2023 15:16:23 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id MGewmX9DXqM0-YfUGrDSd; Tue, 15 Aug 2023 15:16:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1692101783; bh=8DNU0W3LPcuJJjnwy90axtFkhJQK5+/kWXk9WbTEFwY=; h=References:Date:In-Reply-To:Cc:To:From:Subject:Message-ID; b=ugmpIES3+egfl/pqyyaX13FJSfGKp/dcWPOO9SufTwcQOhBYcmkzOT5fMOOy/cfiT rdC7azl11kcqnlayiePYSlJis8WqZHZGJC3o7e4bpmXKbUabvyFYXL9xiKj3R1hI1Z oO2EAzdWT8XCQBK7gXP4AU/iZA2m3gDyniY2sGuE= Authentication-Results: mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: From: Konstantin Kharlamov Date: Tue, 15 Aug 2023 15:17:00 +0300 In-Reply-To: <83leeca4xo.fsf@gnu.org> References: <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> <83leeca4xo.fsf@gnu.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 MIME-Version: 1.0 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On Tue, 2023-08-15 at 15:03 +0300, Eli Zaretskii wrote: > tags 65308 notabug > thanks >=20 > > From: Konstantin Kharlamov > > Date: Tue, 15 Aug 2023 14:25:16 +0300 > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0$ mkdir dir && touch di= r/1 dir/2 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0$ emacs -batch --eval '= (progn (dolist (file command-line- > > args-left) (find-file file) (print buffer-file-name))))' dir/1 > > dir/2=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=20 > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0"/tmp/dir/1" > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0"/tmp/dir/dir/2" > >=20 > > ## Expected > >=20 > > Second print would say `/tmp/dir/2` > >=20 > > ## Actual > >=20 > > Second print refers to non-existing `/tmp/dir/dir/2`. >=20 > IMO, this is the expected behavior: relative file names are > interpreted relative to the current buffer's default-directory.=C2=A0 > After > the first find-file, the current buffer visits the file "/tmp/dir/1", > whose default-directory is "/tmp/dir/". >=20 > There's no bug here.=C2=A0 To get what you want, run the command-line > arguments through expand-file-name _before_ calling find-file. Oh, okay, thank you, I see. I settled with calling a `(kill-buffer)` after `(save-buffer)`, which I guess works because each time the buffer is killed we get back to the *scratch* buffer that has the original "current directory". From unknown Fri Aug 15 16:00:48 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Konstantin Kharlamov Subject: bug#65308: closed (Re: bug#65308: (find-file) botches buffer-file-name in -batch mode) Message-ID: References: <83jztwa3uq.fsf@gnu.org> <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> X-Gnu-PR-Message: they-closed 65308 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: notabug Reply-To: 65308@debbugs.gnu.org Date: Tue, 15 Aug 2023 12:27:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1692102422-15436-1" This is a multi-part message in MIME format... ------------=_1692102422-15436-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #65308: (find-file) botches buffer-file-name in -batch mode which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 65308@debbugs.gnu.org. --=20 65308: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D65308 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1692102422-15436-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 65308-done) by debbugs.gnu.org; 15 Aug 2023 12:26:42 +0000 Received: from localhost ([127.0.0.1]:35153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVt8E-00040T-BS for submit@debbugs.gnu.org; Tue, 15 Aug 2023 08:26:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVt8C-00040D-A6 for 65308-done@debbugs.gnu.org; Tue, 15 Aug 2023 08:26:41 -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 ) id 1qVt87-0000XJ-1F; Tue, 15 Aug 2023 08:26:35 -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=9xy3KIgiiVzwa3ewz7dQ/BYkh/MiL6AYmXHLQY3lRbE=; b=OLBn6P3MlRdvWMD1Uwl3 x+Yx8t8gGvfuXwMXADwV1E6LakpQHRPFpmLtxHZ/RG0RKyokUZzllfzdgc0GUj31zIi+u3CmTPTBL vptEZtOBzAPpCWKQze8AOBca4iWmn68w8Pmd1aj8Ijv2G4E9WfuAJPJXSTBDcdh9jMEJfyEdDZ5BS NxZfovfNYQD3+o4cHApw7EqrMjkPLItAIaGrqi2SaGvCqxp/Nr52WeTroxO7v0EFpezgTR/wZbQfN u2f+RI8v2DOUOaeEWwmFmS0jhA/gwHJiZ2zO/KG18bvuT7AyQ+OfPkgThYw1ZWpcFM3kZ8r1Laeu0 OxWlDhkiV5h7vw==; Date: Tue, 15 Aug 2023 15:26:37 +0300 Message-Id: <83jztwa3uq.fsf@gnu.org> From: Eli Zaretskii To: Konstantin Kharlamov In-Reply-To: (message from Konstantin Kharlamov on Tue, 15 Aug 2023 15:17:00 +0300) Subject: Re: bug#65308: (find-file) botches buffer-file-name in -batch mode References: <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> <83leeca4xo.fsf@gnu.org> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 65308-done Cc: 65308-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Konstantin Kharlamov > Cc: 65308@debbugs.gnu.org > Date: Tue, 15 Aug 2023 15:17:00 +0300 > > On Tue, 2023-08-15 at 15:03 +0300, Eli Zaretskii wrote: > > There's no bug here.  To get what you want, run the command-line > > arguments through expand-file-name _before_ calling find-file. > > Oh, okay, thank you, I see. I settled with calling a `(kill-buffer)` > after `(save-buffer)`, which I guess works because each time the buffer > is killed we get back to the *scratch* buffer that has the original > "current directory". Yes, that will work, as will using save-current-buffer etc. But please note that relying on the default-directory of some random buffer when using relative file names is always fraught with surprises in Emacs, which is why I suggested to use expand-file-name instead. Closing. ------------=_1692102422-15436-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 15 Aug 2023 11:24:59 +0000 Received: from localhost ([127.0.0.1]:35091 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsAU-00030I-Sa for submit@debbugs.gnu.org; Tue, 15 Aug 2023 07:24:59 -0400 Received: from lists.gnu.org ([2001:470:142::17]:40598) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVsAS-000300-Ib for submit@debbugs.gnu.org; Tue, 15 Aug 2023 07:24:57 -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 ) id 1qVsAL-0006Rt-MM for bug-gnu-emacs@gnu.org; Tue, 15 Aug 2023 07:24:49 -0400 Received: from forward102c.mail.yandex.net ([178.154.239.213]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qVsAI-0003xf-Ba for bug-gnu-emacs@gnu.org; Tue, 15 Aug 2023 07:24:49 -0400 Received: from mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1380:0:640:6985:0]) by forward102c.mail.yandex.net (Yandex) with ESMTP id 2B1C860103 for ; Tue, 15 Aug 2023 14:24:39 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id cOdxhS4DaW20-N4WpIQAV; Tue, 15 Aug 2023 14:24:38 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1692098678; bh=ujgWMJV/dBYLLyOBZa6XfR0qPxagY0UI29S1Jj59+7c=; h=Date:To:From:Subject:Message-ID; b=TPUvcLwqaxGiZxFNAXN2KrNMrwtX470m0atagqAAvPNNUlIFMm3SYPmjf4xLG1Yco +MaCbZ1aDd+i2NQ436j0266gQGFE4zAd30Wjcn4lXUgN+SLwcz7Qsw0jncM6YovqGl 4YmhHZVZfLKAg88Fo+5LC+xl9lryau4V1LvaHOm8= Authentication-Results: mail-nwsmtp-smtp-production-main-54.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: <5a188f33a3580e9046a28ba6bd527ff20d54366d.camel@yandex.ru> Subject: (find-file) botches buffer-file-name in -batch mode From: Konstantin Kharlamov To: bug-gnu-emacs@gnu.org Date: Tue, 15 Aug 2023 14:25:16 +0300 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 MIME-Version: 1.0 Received-SPF: pass client-ip=178.154.239.213; envelope-from=Hi-Angel@yandex.ru; helo=forward102c.mail.yandex.net 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, 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) This was found while trying to use Emacs in `-batch` mode to regexp- replace many files in a project. Turns out calling `(save-buffer)` will make it say that directory does not exist, and the reason for that is that `buffer-file-name` gets mangled filename. # Steps to reproduce $ mkdir dir && touch dir/1 dir/2 $ emacs -batch --eval '(progn (dolist (file command-line-args-left) (find-= file file) (print buffer-file-name))))' dir/1 dir/2 = =20 "/tmp/dir/1" "/tmp/dir/dir/2" ## Expected Second print would say `/tmp/dir/2` ## Actual Second print refers to non-existing `/tmp/dir/dir/2`. # Versions tested Reproducible with stable 29.1 and somewhat old master as of commit 04710bd01b2 ------------=_1692102422-15436-1--