unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
@ 2020-12-12 18:10 tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2020-12-14 17:11 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2020-12-12 18:10 UTC (permalink / raw)
  To: 45197

Subject says all.

How to reproduce:
1. $ cd /tmp
2. $ mkdir -p test-home/.config/emacs
3. $ cd test-home
4. $ HOME=$PWD emacs
5. M-x customize, edit something and Save for Future Sessions.
=> Wrote /tmp/test-home/.config/emacs/init

init (not init.el) is created.
This is because user-init-file is set to “/tmp/test-home/.config/emacs/init”.

Emacs manual doesn’t refer ~/.config/emacs/init so I think this is not intended.

Changing
     (lambda ()
       (expand-file-name
        “init"
        startup-init-directory))
to
     (lambda ()
       (expand-file-name
        “init.el"
        startup-init-directory))
in startup.el
maybe solve this (like early-init.el)?

--
tsuucat






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-12 18:10 bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension) tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2020-12-14 17:11 ` Lars Ingebrigtsen
  2020-12-14 17:23   ` Robert Pluim
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-14 17:11 UTC (permalink / raw)
  To: tsuucat; +Cc: 45197

tsuucat <tsuucat@icloud.com> writes:

> This is because user-init-file is set to “/tmp/test-home/.config/emacs/init”.

This was part of:

    Add early init file, stop package-initialize insertion
    
    Discussion on emacs-devel leading up to this change (approximately 150
    messages):
    
    - https://lists.gnu.org/archive/html/emacs-devel/2017-08/msg00154.html
    - https://lists.gnu.org/archive/html/emacs-devel/2017-08/msg00433.html
    - https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00023.html
    - https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00599.html
    - https://lists.gnu.org/archive/html/emacs-devel/2017-10/msg00332.html

I did not read those 150 messages, and this code is uncommented in
startup.el:

     (lambda ()
       (expand-file-name
        "init"
        startup-init-directory))

Does anybody know whether this is just a typo?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-14 17:11 ` Lars Ingebrigtsen
@ 2020-12-14 17:23   ` Robert Pluim
  2020-12-14 17:46   ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2020-12-14 17:52   ` Eli Zaretskii
  2 siblings, 0 replies; 9+ messages in thread
From: Robert Pluim @ 2020-12-14 17:23 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 45197, tsuucat

Lars Ingebrigtsen <larsi@gnus.org> writes:

> tsuucat <tsuucat@icloud.com> writes:

> I did not read those 150 messages, and this code is uncommented in
> startup.el:
>
>      (lambda ()
>        (expand-file-name
>         "init"
>         startup-init-directory))
>
> Does anybody know whether this is just a typo?

Iʼm not sure it is. startup--load-user-init-file does this:

              (when (and (eq user-init-file t) alternate-filename-function)
                (let ((alt-file (funcall alternate-filename-function)))
                  (and (equal (file-name-extension alt-file) "el")
                       (setq alt-file (file-name-sans-extension alt-file)))
		  (unless init-file-name
		    (setq init-file-name alt-file))
                  (load alt-file 'noerror 'nomessage)))

which makes me wonder if itʼs trying to cater for people who compile
their init.el file, since this code doesnʼt actually probe the
filesystem, but presumably later we do (load init-file-name), which
will match .elc and .el suffixes.

Robert





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-14 17:11 ` Lars Ingebrigtsen
  2020-12-14 17:23   ` Robert Pluim
@ 2020-12-14 17:46   ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2020-12-14 17:52   ` Eli Zaretskii
  2 siblings, 0 replies; 9+ messages in thread
From: tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2020-12-14 17:46 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 45197


> I did not read those 150 messages, and this code is uncommented in
> startup.el:
> 
>     (lambda ()
>       (expand-file-name
>        "init"
>        startup-init-directory))


I found the explicit .el extension of "early-init.el” in startup.el is from
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=3d9a56f00040cbfc8fb92c4379344d7e91e2dff2.

--
tsuucat






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-14 17:11 ` Lars Ingebrigtsen
  2020-12-14 17:23   ` Robert Pluim
  2020-12-14 17:46   ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2020-12-14 17:52   ` Eli Zaretskii
  2020-12-15  6:14     ` Lars Ingebrigtsen
  2 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-12-14 17:52 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 45197, tsuucat

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Mon, 14 Dec 2020 18:11:49 +0100
> Cc: 45197@debbugs.gnu.org
> 
> I did not read those 150 messages, and this code is uncommented in
> startup.el:
> 
>      (lambda ()
>        (expand-file-name
>         "init"
>         startup-init-directory))
> 
> Does anybody know whether this is just a typo?

It isn't: the code later tries appending .el to the name.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-14 17:52   ` Eli Zaretskii
@ 2020-12-15  6:14     ` Lars Ingebrigtsen
  2020-12-15 16:23       ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-15  6:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 45197, tsuucat

Eli Zaretskii <eliz@gnu.org> writes:

>> I did not read those 150 messages, and this code is uncommented in
>> startup.el:
>> 
>>      (lambda ()
>>        (expand-file-name
>>         "init"
>>         startup-init-directory))
>> 
>> Does anybody know whether this is just a typo?
>
> It isn't: the code later tries appending .el to the name.

The code flow isn't trivial to follow here, but this is the code:

         (when (and (eq user-init-file t) alternate-filename-function)
                (let ((alt-file (funcall alternate-filename-function)))
                  (and (equal (file-name-extension alt-file) "el")
                       (setq alt-file (file-name-sans-extension alt-file)))
		  (unless init-file-name
		    (setq init-file-name alt-file))
                  (load alt-file 'noerror 'nomessage)))

              ;; If we did not find the user's init file, set
              ;; user-init-file conclusively.  Don't let it be
              ;; set from default.el.
              (when (eq user-init-file t)
                (setq user-init-file init-file-name)))

alternate-filename-function is the lambda up there, so it's
"/tmp/test-home/.config/emacs/init".  So this always sets user-init-file
to the .el-less file name.  (Well, it would have even if the alternate
file name had ended in ".el".)

That makes sense for making a file name for `load' (so that it'll load
the .elc file, if it exists), but setting `user-init-file' to that
.el-less name sounds like the problem here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-15  6:14     ` Lars Ingebrigtsen
@ 2020-12-15 16:23       ` Eli Zaretskii
  2020-12-16  1:47         ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-12-15 16:23 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 45197, tsuucat

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: tsuucat@icloud.com,  45197@debbugs.gnu.org
> Date: Tue, 15 Dec 2020 07:14:58 +0100
> 
> alternate-filename-function is the lambda up there, so it's
> "/tmp/test-home/.config/emacs/init".  So this always sets user-init-file
> to the .el-less file name.  (Well, it would have even if the alternate
> file name had ended in ".el".)
> 
> That makes sense for making a file name for `load' (so that it'll load
> the .elc file, if it exists), but setting `user-init-file' to that
> .el-less name sounds like the problem here?

I'm not arguing against the fact that there's a bug, I'm just saying
that there's code which was supposed to handle this, and I think
that's where this should be fixed.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-15 16:23       ` Eli Zaretskii
@ 2020-12-16  1:47         ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2020-12-17 11:18           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2020-12-16  1:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, 45197

[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]

		  (unless init-file-name
		    (setq init-file-name alt-file))
is added
in https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=4118297ae2fab4886b20d193ba511a229637aea3.

Before this commit, I think ‘.emacs’ is always used  for ‘user-init-file’ value if
init file is missing.

                 (and (equal (file-name-extension alt-file) "el")
                      (setq alt-file (file-name-sans-extension alt-file)))
...
                 (load alt-file 'noerror 'nomessage)))

should be also changed in the commit to use “init.el” not “init".


> 2020/12/16 1:23、Eli Zaretskii <eliz@gnu.org>:
> 
>> From: Lars Ingebrigtsen <larsi@gnus.org>
>> Cc: tsuucat@icloud.com,  45197@debbugs.gnu.org
>> Date: Tue, 15 Dec 2020 07:14:58 +0100
>> 
>> alternate-filename-function is the lambda up there, so it's
>> "/tmp/test-home/.config/emacs/init".  So this always sets user-init-file
>> to the .el-less file name.  (Well, it would have even if the alternate
>> file name had ended in ".el".)
>> 
>> That makes sense for making a file name for `load' (so that it'll load
>> the .elc file, if it exists), but setting `user-init-file' to that
>> .el-less name sounds like the problem here?
> 
> I'm not arguing against the fact that there's a bug, I'm just saying
> that there's code which was supposed to handle this, and I think
> that's where this should be fixed.


I can’t find such a code.

I made a patch to set 'user-init-file' value to init”.el" for XDG convention users 
who do not have an init file.

(But alternate-filename-function is only used for "init.el” so 
                  ...(if (equal (file-name-extension alt-file)
				 "el")
			    (file-name-sans-extension alt-file)
                          alt-file)...
may be redundant.)

--
tsuucat

[-- Attachment #2: 0001-Fix-user-init-file-value-when-file-is-missing-in-XDG.patch --]
[-- Type: application/octet-stream, Size: 1819 bytes --]

From 7373c4d4def8435de21a228bbce3aca29a5982bf Mon Sep 17 00:00:00 2001
From: Masahiro Nakamura <tsuucat@icloud.com>
Date: Wed, 16 Dec 2020 09:24:41 +0900
Subject: [PATCH] Fix 'user-init-file' value when file is missing in XDG
 convention

* lisp/startup.el (startup--load-user-init-file): Do not remove .el
extension from alt-file.
(command-line): Pass 'init.el', with an explicit .el extension, to
startup--load-user-init-file.  This sets 'user-init-file' value to
init.el for XDG convention users who do not have an init file.
---
 lisp/startup.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 9f67dfde12..c470170fb0 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -949,11 +949,13 @@ startup--load-user-init-file
 
               (when (and (eq user-init-file t) alternate-filename-function)
                 (let ((alt-file (funcall alternate-filename-function)))
-                  (and (equal (file-name-extension alt-file) "el")
-                       (setq alt-file (file-name-sans-extension alt-file)))
 		  (unless init-file-name
 		    (setq init-file-name alt-file))
-                  (load alt-file 'noerror 'nomessage)))
+                  (load (if (equal (file-name-extension alt-file)
+				 "el")
+			    (file-name-sans-extension alt-file)
+                          alt-file)
+                        'noerror 'nomessage)))
 
               ;; If we did not find the user's init file, set
               ;; user-init-file conclusively.  Don't let it be
@@ -1382,7 +1384,7 @@ command-line
          "~/.emacs")))
      (lambda ()
        (expand-file-name
-        "init"
+        "init.el"
         startup-init-directory))
      (not inhibit-default-init))
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension)
  2020-12-16  1:47         ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2020-12-17 11:18           ` Lars Ingebrigtsen
  0 siblings, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-17 11:18 UTC (permalink / raw)
  To: tsuucat; +Cc: 45197

tsuucat <tsuucat@icloud.com> writes:

> 		  (unless init-file-name
> 		    (setq init-file-name alt-file))
> is added
> in https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=4118297ae2fab4886b20d193ba511a229637aea3.
>
> Before this commit, I think ‘.emacs’ is always used  for ‘user-init-file’ value if
> init file is missing.
>
>                  (and (equal (file-name-extension alt-file) "el")
>                       (setq alt-file (file-name-sans-extension alt-file)))
> ...
>                  (load alt-file 'noerror 'nomessage)))
>
> should be also changed in the commit to use “init.el” not “init".

Yes, I think the code here is just confused -- alt-file is "init" by
default, but since it's passed in as a closure, pretty much anything can
be returned, right?  The code does the right thing in stripping the
".el" before passing it to `load', because then `load' will load
init.elc if it exists.

But we can't add back ".el" before setting init-file-name, because the
alt-file may legitimately be ".emacs", and should not then be forced to
".emacs.el".

So I think the "init" in the alt-file closure is the problem: It should
be "init.el", and init-file-name should be set to that verbatim.  (But
the ".el" should still be stripped before doing the `load'.)

I think.  I've now done this change in Emacs 28, but I'm not
super-confident about it -- there's many subtleties here...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-17 11:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-12 18:10 bug#45197: Saving customizations makes ~/.config/emacs/init (no .el extension) tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-12-14 17:11 ` Lars Ingebrigtsen
2020-12-14 17:23   ` Robert Pluim
2020-12-14 17:46   ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-12-14 17:52   ` Eli Zaretskii
2020-12-15  6:14     ` Lars Ingebrigtsen
2020-12-15 16:23       ` Eli Zaretskii
2020-12-16  1:47         ` tsuucat via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-12-17 11:18           ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).