From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christoph via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66534: 30.0.50; [PATCH] Expand file-name of ~/.emacs before attempt to load it Date: Sat, 14 Oct 2023 11:04:14 +0200 Message-ID: References: <83r0lxsnhz.fsf@gnu.org> Reply-To: Christoph Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25989"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66534@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 14 14:47:10 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qre2w-0006cA-FY for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Oct 2023 14:47:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qre2b-0000Bg-A0; Sat, 14 Oct 2023 08:46:49 -0400 Original-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 1qre2S-0008VT-ER for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 08:46:45 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qre2R-0001he-4G for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 08:46:39 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qre2o-0004Lb-Lr for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 08:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Christoph Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Oct 2023 12:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66534 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66534-submit@debbugs.gnu.org id=B66534.169728758316629 (code B ref 66534); Sat, 14 Oct 2023 12:47:02 +0000 Original-Received: (at 66534) by debbugs.gnu.org; 14 Oct 2023 12:46:23 +0000 Original-Received: from localhost ([127.0.0.1]:48101 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qre2A-0004K7-0x for submit@debbugs.gnu.org; Sat, 14 Oct 2023 08:46:23 -0400 Original-Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:58532) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qraZr-0008QA-Hi for 66534@debbugs.gnu.org; Sat, 14 Oct 2023 05:05:10 -0400 Original-Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-53e08e439c7so4483380a12.0 for <66534@debbugs.gnu.org>; Sat, 14 Oct 2023 02:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1697274266; x=1697879066; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=a/LUX47i9ycfVy33mIqr0qgRIgGyfZpB5SEF98ij2W8=; b=W4E8qLJ5TFV95ZScCL5mz4SemfiucuD19LGz/JO3zJIFu1gf9V5Knz16WPEe4JUOPB Pc/VuaN81gKDuajPZaqK+ZchDy7sGgXpQLl+MSo2E9mvrN8UDbgYyijZR6HiNxjza331 KSnhcg4U7hOpbmusm7tNcrewOf5izDukrd31b8/plhV64gVgnz28UYBRs9BVjK6/UG4C jGc0676lh7uaaZ3gmmRgK3dfAPLt1rbF0DQpveHRomgaB+d9JhPFbrmTAgJm4ExkAkPL zCNu9W0cQW+RJPmXL7VcGi9iRx3vwQrZRjL0nYLet9c3CGx959fpiEt3Ts799nP4BnTC b8IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697274266; x=1697879066; h=content-transfer-encoding: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=a/LUX47i9ycfVy33mIqr0qgRIgGyfZpB5SEF98ij2W8=; b=CZR5NvmOz7lcFSzSX/2jthwDoaUoGbJOTfv53cFHbNQiL1HaHENRrGlb9kIw27RFhv ZKoUw3YFSfH/pXSF8N1XXNAYMDiCou5xI2yZWebfqB4TPq8FtWitAxIfT9tF11I7XDGR qLG8FCHUF6hYsHUsQqwKalj8vPJhpI6dmUtMbJJ34gAiqZuXTJ90AaCfd4AlHV8sx2RI 0SWJ27iz5d8L+i+HUFRkVkqEdYouc29IqZHugfFsRWPMzwbCw9RzEPaIc0rC2QJmWVZt 67q9A8o3cg9LDdZswN/TCCQq0DiYHCNu1Hl5rPFAly6ppEPEvGhLeB2u6raI9Q4O64kG AzoQ== X-Gm-Message-State: AOJu0YyE6blPZUNp3KasumOkEznNFdmfZZmjBhuwtEjDdJ1MYWJ4wx0D +ZZDMAKfm4bp2+RoMRuiWvGX8unPUwP4XSEH2XyzwWkZ3sg= X-Google-Smtp-Source: AGHT+IF3lVmsMqHY0eXXp7aEyDCYIh5Lkyic6Utsri0vYksYGic4H8e1/Sx02lZzkr/HYS2PwxNZ2wvIxtq8bobKOxo= X-Received: by 2002:a05:6402:b0f:b0:536:aead:3486 with SMTP id bm15-20020a0564020b0f00b00536aead3486mr20827589edb.40.1697274265974; Sat, 14 Oct 2023 02:04:25 -0700 (PDT) In-Reply-To: <83r0lxsnhz.fsf@gnu.org> X-Mailman-Approved-At: Sat, 14 Oct 2023 08:46:21 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272417 Archived-At: On Sat, Oct 14, 2023 at 8:54=E2=80=AFAM Eli Zaretskii wrote: > > > Date: Fri, 13 Oct 2023 20:41:16 +0200 > > From: Christoph via "Bug reports for GNU Emacs, > > the Swiss army knife of text editors" > > > > I noticed that during startup, emacs tries to load ~/.emacs (with > > different extensions) many times over. You can see this by using > > strace and tracing the openat syscall. The problem is, that `load' > > does not expand the ~/ in the filename passed to it. So it does not > > recognize the file as being absolute and tries to resolve it using > > the load-path. > > > > While resolving the path in the openp function in lread.c, > > `expand-file-name' is used with the default directory being the > > elements of the load-path. Since for `expand-file-name', ~/.emacs is > > an absolute path, it returns the path unchanged, and load tries to > > load ~/.emacs many times over. > > I don't understand what you are saying here. The last sentence is > incorrect, as evidenced by the following: > > (expand-file-name "~/.emacs" "/tmp") > =3D> "/home/eliz/.emacs" > > IOW, "~/.emacs" is indeed treated by Emacs as an absolute file name, > but expand-file-name does NOT return "~/.emacs" unchanged. What I meant is "unchanged" in the regard to the default directory. You can give any default directory to expand-file-name and it will always return the first argument in its expanded form, if the expanded form of the first argument is an absolute path. > > So please explain what exactly is the problem you see here, and in > particular what issues that problem causes in your case. > > Thanks. If you start Emacs without an ~/.emacs file, and with using .emacs.d and not .config/emacs, I think there is a difference as well, Emacs will try to load ~/.emacs `(length load-path)' times. If I start Emacs with strace -e openat I see the following lines 147 times: openat(AT_FDCWD, "/home/chris/.emacs", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.gz", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.so", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.so.gz", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.elc", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.elc.gz", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.el", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/chris/.emacs.el.gz", O_RDONLY|O_CLOEXEC) =3D -1 ENOENT (No such file or directory) But Emacs should only try to load the file once. The problem is that the path to ~/.emacs is not expanded before it is handed to `load' and load basically does: (dolist (path load-path) (low-level-load (expand-file-name "~/.emacs" path))) where low-level-load is some magic function which really loads a file. There is off course more going on, like iterating over the extension and such, but I want to keep it simple, since I am not familiar with it at all. `load' does check if the given path is absolute and changes its behavior. If the path is absolute, `load' does not take the load-path into account, but paths beginning with "~/" are not recognized as beeing absolute, hence the paths should be expanded before passing them to `load'. Because all the other paths to init files (early-init.el and init.el) are expanded before they are passed to `load', I think "~/.emacs" should be expanded as well. There is also the question if `load' itself should be able to handle paths that begin with "~/" correctly, or if the user is expected to expand paths before passing them to `load'. Regards, Christoph