unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#54381: 29.0.50; Automatically load custom-file
@ 2022-03-14  8:21 Pedro Andres Aranda Gutierrez
  2022-03-14  9:47 ` Lars Ingebrigtsen
  2022-03-17  6:38 ` bug#54381: Handling a corner case Pedro Andres Aranda Gutierrez
  0 siblings, 2 replies; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-03-14  8:21 UTC (permalink / raw)
  To: 54381


[-- Attachment #1.1: Type: text/plain, Size: 915 bytes --]

Attached is a patch to automatically load custom-file when defined.

Motivation:
After 30 years of emacs use, I'm getting tired of the need to load
custom-file when you setq it.
And when introducing people to emacs, the question of why you need to load
it explicitly arises only too often.

Rationale:
1. if custom-file is nil, nothing changes
2. if you set custom-file:
  2a. If you don't load it explicitly in your init.el, it gets loaded at a
predictable place in the loading sequence (ie. after init.el was loaded)
  2b. If you load it explicity in init.el, it doesn't get loaded twice and
init.el "wins".
3. CORNER CASE:
   Q:Currently, my init.el defines custom-file, but I don't load it.
    A Add
  (setq custom-file-load-p nil)
to your init.el and emacs will not load custom-file

Best,
/Pedro A.Aranda
-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

[-- Attachment #1.2: Type: text/html, Size: 1382 bytes --]

[-- Attachment #2: 003-auto-load-custom.diff --]
[-- Type: text/x-patch, Size: 2101 bytes --]

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 7932031..299bae4 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -4710,6 +4710,13 @@ custom-group-state-update
 \f
 ;;; Reading and writing the custom file.
 
+;;;###autoload
+(defcustom custom-file-load-p t
+  "Load `custom-file' if it is not nil.
+Set this variable to `nil' if you want to define `custom-file' but not load it.
+This was possible. As per the old definition,someone could just define the variable
+and not load the file.")
+
 ;;;###autoload
 (defcustom custom-file nil
   "File used for storing customization information.
@@ -4722,10 +4729,12 @@ custom-file
 something like the following in your init file:
 
 (setq custom-file \"~/.config/emacs-custom.el\")
-(load custom-file)
 
-Note that both lines are necessary: the first line tells Custom to
-save all customizations in this file, but does not load it.
+This will load `custom-file' after the `user-init-file' if
+a) the file exists,
+b) `custom-file-load-p' is `t', and
+c) it was not loaded before explicitly with
+  (load-file custom-file).
 
 When you change this variable outside Custom, look in the
 previous custom file (usually your init file) for the
diff --git a/lisp/startup.el b/lisp/startup.el
index 9f0b23c..472e5f7 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1494,6 +1494,17 @@ command-line
     (when (featurep 'native-compile)
       (startup--update-eln-cache))
 
+    ;; Load the `custom-file' if it was not loaded before (see documentation)
+
+    ;; if the user defined the custom-file and didn't reset `custom-file-load-p'
+    (when (and custom-file custom-file-load-p)
+      ;; make sure that you get the expanded custom-file name
+      ;; because that's what appears in `load-history'
+      (let ((real-custom-file (expand-file-name custom-file)))
+        ;; if it was loaded, assoc will return non-nil
+        (unless (assoc real-custom-file load-history)
+          (load real-custom-file))))
+
     (when (and deactivate-mark transient-mark-mode)
       (with-current-buffer (window-buffer)
         (deactivate-mark)))

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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14  8:21 bug#54381: 29.0.50; Automatically load custom-file Pedro Andres Aranda Gutierrez
@ 2022-03-14  9:47 ` Lars Ingebrigtsen
  2022-03-14  9:48   ` Lars Ingebrigtsen
                     ` (2 more replies)
  2022-03-17  6:38 ` bug#54381: Handling a corner case Pedro Andres Aranda Gutierrez
  1 sibling, 3 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-14  9:47 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: 54381

Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:

> Attached is a patch to automatically load custom-file when defined.

[...]

> +;;;###autoload
> +(defcustom custom-file-load-p t

This isn't really feasible -- it'll lead to the custom file being loaded
twice for everybody that currently have a

(load custom-file)

in their init files (which will change the order of customisations).

So if we add this user option, it'll have to default to nil, and in that
case I don't see much point in the user option.  (Because people will
have to `setq' it in their init files.)

If we introduced the `custom-file' variable today, we'd load it
automatically, but I don't think it's possible to do so now without
breaking stuff.

Anybody else got an opinion?

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





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14  9:47 ` Lars Ingebrigtsen
@ 2022-03-14  9:48   ` Lars Ingebrigtsen
  2022-03-14 15:14     ` bug#54381: [External] : " Drew Adams
  2022-03-14 13:15   ` Eli Zaretskii
  2022-03-14 13:58   ` Robert Pluim
  2 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-14  9:48 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: 54381

Lars Ingebrigtsen <larsi@gnus.org> writes:

> This isn't really feasible -- it'll lead to the custom file being loaded
> twice for everybody that currently have a

+      ;; make sure that you get the expanded custom-file name
+      ;; because that's what appears in `load-history'
+      (let ((real-custom-file (expand-file-name custom-file)))
+        ;; if it was loaded, assoc will return non-nil
+        (unless (assoc real-custom-file load-history)
+          (load real-custom-file))))

Oops, I should have read the entire patch before answering...  so if
it's already loaded, it won't be reloaded.  So perhaps this is feasible
after all?

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





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14  9:47 ` Lars Ingebrigtsen
  2022-03-14  9:48   ` Lars Ingebrigtsen
@ 2022-03-14 13:15   ` Eli Zaretskii
  2022-03-14 15:26     ` Robert Pluim
  2022-03-14 13:58   ` Robert Pluim
  2 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2022-03-14 13:15 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 54381, paaguti

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Mon, 14 Mar 2022 10:47:03 +0100
> Cc: 54381@debbugs.gnu.org
> 
> So if we add this user option, it'll have to default to nil, and in that
> case I don't see much point in the user option.  (Because people will
> have to `setq' it in their init files.)

I agree.

> If we introduced the `custom-file' variable today, we'd load it
> automatically, but I don't think it's possible to do so now without
> breaking stuff.
> 
> Anybody else got an opinion?

Would it perhaps help if we could support automatic loading of the
custom file if its basename was something special, or perhaps one of a
small number of fixed names?  If we choose a name that is unlikely to
be in wide use, all people will need is to rename their files (and
modify the init file).





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14  9:47 ` Lars Ingebrigtsen
  2022-03-14  9:48   ` Lars Ingebrigtsen
  2022-03-14 13:15   ` Eli Zaretskii
@ 2022-03-14 13:58   ` Robert Pluim
  2022-04-14 14:05     ` Lars Ingebrigtsen
  2 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2022-03-14 13:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 54381, Pedro Andres Aranda Gutierrez

>>>>> On Mon, 14 Mar 2022 10:47:03 +0100, Lars Ingebrigtsen <larsi@gnus.org> said:

    Lars> Anybody else got an opinion?

I think the long thread on emacs-devel ended with the Montagues and
the Capulets deciding that now was not the time for war.

Robert
-- 





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

* bug#54381: [External] : bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14  9:48   ` Lars Ingebrigtsen
@ 2022-03-14 15:14     ` Drew Adams
  0 siblings, 0 replies; 15+ messages in thread
From: Drew Adams @ 2022-03-14 15:14 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Pedro Andres Aranda Gutierrez; +Cc: 54381@debbugs.gnu.org

> so if it's already loaded, it won't be reloaded.
> So perhaps this is feasible after all?

And yet you rejected that behavior when I proposed
it in emacs-devel.

Continue to give users control over loading
`custom-file'.  And give them the possibility to
have it loaded automatically after their init file.

There are lots of different scenarios, however.
See the two long emacs-devel threads about this
question.

https://lists.gnu.org/archive/html/emacs-devel/2022-01/msg00284.html

https://lists.gnu.org/archive/html/emacs-devel/2022-01/msg00386.html





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 13:15   ` Eli Zaretskii
@ 2022-03-14 15:26     ` Robert Pluim
  2022-03-14 16:19       ` Pedro Andres Aranda Gutierrez
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2022-03-14 15:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, 54381, paaguti

>>>>> On Mon, 14 Mar 2022 15:15:50 +0200, Eli Zaretskii <eliz@gnu.org> said:
    Eli> Would it perhaps help if we could support automatic loading of the
    Eli> custom file if its basename was something special, or perhaps one of a
    Eli> small number of fixed names?  If we choose a name that is unlikely to
    Eli> be in wide use, all people will need is to rename their files (and
    Eli> modify the init file).

If weʼre going to do it, then it should have one and only one option.

(locate-user-emacs-file "emacs-auto-custom.el")

perhaps?

Robert
-- 





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 15:26     ` Robert Pluim
@ 2022-03-14 16:19       ` Pedro Andres Aranda Gutierrez
  2022-03-14 16:36         ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-03-14 16:19 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 54381, Lars Ingebrigtsen

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

Eli> custom file if its basename was something special, or perhaps one of a
Eli> small number of fixed names?

(locate-user-emacs-file "custom.el")

perhaps?

Anyway, I've uploaded the patch so that is is not lost. Maybe in the future
someone revisits this and finds it cool.
I just want to get rid of the mandatory (load custom-file) in my init.el
and not break other people's current configs.

Again, I'm "preaching Emacs" among my students and the question of why
custom-file is not loaded automatically if you
define it is coming up only too often.

These youngsters have made me rethink many things... I like teaching :-)
keeps me vigilant

/PA


On Mon, 14 Mar 2022 at 16:26, Robert Pluim <rpluim@gmail.com> wrote:

> >>>>> On Mon, 14 Mar 2022 15:15:50 +0200, Eli Zaretskii <eliz@gnu.org>
> said:
>     Eli> Would it perhaps help if we could support automatic loading of the
>     Eli> custom file if its basename was something special, or perhaps one
> of a
>     Eli> small number of fixed names?  If we choose a name that is
> unlikely to
>     Eli> be in wide use, all people will need is to rename their files (and
>     Eli> modify the init file).
>
> If weʼre going to do it, then it should have one and only one option.
>
> (locate-user-emacs-file "emacs-auto-custom.el")
>
> perhaps?
>
> Robert
> --
>


-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

[-- Attachment #2: Type: text/html, Size: 2227 bytes --]

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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 16:19       ` Pedro Andres Aranda Gutierrez
@ 2022-03-14 16:36         ` Robert Pluim
  2022-03-14 16:47           ` Pedro Andres Aranda Gutierrez
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2022-03-14 16:36 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: 54381, Lars Ingebrigtsen

>>>>> On Mon, 14 Mar 2022 17:19:55 +0100, Pedro Andres Aranda Gutierrez <paaguti@gmail.com> said:

    Eli> custom file if its basename was something special, or perhaps one of a
    Eli> small number of fixed names?

    Pedro> (locate-user-emacs-file "custom.el")

    Pedro> perhaps?

No, I donʼt think that would be a good idea: thereʼs a "custom.el" in
the emacs sources already, and we should indicate somehow that this is
*data*, not code.

Robert
-- 





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 16:36         ` Robert Pluim
@ 2022-03-14 16:47           ` Pedro Andres Aranda Gutierrez
  2022-03-14 17:53             ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-03-14 16:47 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 54381, Lars Ingebrigtsen

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

Robert > No, I donʼt think that would be a good idea: thereʼs a "custom.el"
in
Robert> the emacs sources already, and we should indicate somehow that this
is
Robert> *data*, not code.

Don't follow you here. My customization file '~/.emacs.d/custom.el' is
code, isn't it?

/PA


On Mon, 14 Mar 2022 at 17:36, Robert Pluim <rpluim@gmail.com> wrote:

> >>>>> On Mon, 14 Mar 2022 17:19:55 +0100, Pedro Andres Aranda Gutierrez <
> paaguti@gmail.com> said:
>
>     Eli> custom file if its basename was something special, or perhaps one
> of a
>     Eli> small number of fixed names?
>
>     Pedro> (locate-user-emacs-file "custom.el")
>
>     Pedro> perhaps?
>
> No, I donʼt think that would be a good idea: thereʼs a "custom.el" in
> the emacs sources already, and we should indicate somehow that this is
> *data*, not code.
>
> Robert
> --
>


-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

[-- Attachment #2: Type: text/html, Size: 1812 bytes --]

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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 16:47           ` Pedro Andres Aranda Gutierrez
@ 2022-03-14 17:53             ` Robert Pluim
  2022-03-15  7:51               ` Pedro Andres Aranda Gutierrez
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2022-03-14 17:53 UTC (permalink / raw)
  To: Pedro Andres Aranda Gutierrez; +Cc: 54381, Lars Ingebrigtsen

>>>>> On Mon, 14 Mar 2022 17:47:49 +0100, Pedro Andres Aranda Gutierrez <paaguti@gmail.com> said:

    Pedro> Robert > No, I donʼt think that would be a good idea: thereʼs a "custom.el"
    Pedro> in
    Robert> the emacs sources already, and we should indicate somehow that this
    Pedro> is
    Robert> *data*, not code.

    Pedro> Don't follow you here. My customization file '~/.emacs.d/custom.el' is
    Pedro> code, isn't it?

Yes, thereʼs no distinction between code and data in lisp. But your
custom file should only contain `custom-set-variables' and
`custom-set-faces', not any old lisp forms.

Robert
-- 





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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 17:53             ` Robert Pluim
@ 2022-03-15  7:51               ` Pedro Andres Aranda Gutierrez
  0 siblings, 0 replies; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-03-15  7:51 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 54381, Lars Ingebrigtsen

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

OK, once again, one step back... maybe I'm completely wrong assuming things
based on my experience:
My full history step by step:

Background:
My first Emacs experience what on an HP700 where we had a 68020 HW emulator
and on a Sun SPARC where we had the schematic capture programs in the
1990... Always trying to have a single sys-independent initialisation
infra...

I've been using the variable `custom-file' (defined inside Emacs), setting
it to the path of the file where I want my customisation to reside.
After setting this variable, I've used (load custom-file) to load my
customisations (if they existed).
I have observed that the optimal place to put this (setq)(load) pair was at
the end of my init.el file, because some customisations came from packages
I loaded, etc.

Now, I have started encouraging my students to use Emacs and helping them
understand the basics of initialisation and customisation.
During this time, I have often been asked why the (setq)(load) pair is
needed. The reasoning behind this question mainly being that because
`custom-file' is defined in Emacs, it should be assumed that Emacs would
react to its being non-nil by loading it.

This question arose always when someone had not placed the (setq)(load)
pair at the end of init.el and a weird behaviour was observed.

Corner cases:
I do understand that someone may want to (setq)(load) somewhere in init.el
(ie not at the end) and I respect this by loading `custom-file' only once.

I do understand that someone can setq `custom-file' but not load it,
because customisations are session specific for this user and can be
discarded afterwards or because this user wants to try out things and then
integrate some of the customisations into init.el in a more permanent way.
This is what custom-file-load-p was included for.

I have tried to integrate all this (but just this) into the patch to make
Emacs an infinitesimal more beginner-friendly.

best, /PA

On Mon, 14 Mar 2022 at 18:53, Robert Pluim <rpluim@gmail.com> wrote:

> >>>>> On Mon, 14 Mar 2022 17:47:49 +0100, Pedro Andres Aranda Gutierrez <
> paaguti@gmail.com> said:
>
>     Pedro> Robert > No, I donʼt think that would be a good idea: thereʼs a
> "custom.el"
>     Pedro> in
>     Robert> the emacs sources already, and we should indicate somehow that
> this
>     Pedro> is
>     Robert> *data*, not code.
>
>     Pedro> Don't follow you here. My customization file
> '~/.emacs.d/custom.el' is
>     Pedro> code, isn't it?
>
> Yes, thereʼs no distinction between code and data in lisp. But your
> custom file should only contain `custom-set-variables' and
> `custom-set-faces', not any old lisp forms.
>
> Robert
> --
>


-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

[-- Attachment #2: Type: text/html, Size: 3724 bytes --]

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

* bug#54381: Handling a corner case
  2022-03-14  8:21 bug#54381: 29.0.50; Automatically load custom-file Pedro Andres Aranda Gutierrez
  2022-03-14  9:47 ` Lars Ingebrigtsen
@ 2022-03-17  6:38 ` Pedro Andres Aranda Gutierrez
  2022-03-17  7:09   ` Pedro Andres Aranda Gutierrez
  1 sibling, 1 reply; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-03-17  6:38 UTC (permalink / raw)
  To: 54381


[-- Attachment #1.1: Type: text/plain, Size: 317 bytes --]

Hi,

just updating the patch for reference. Now handles the green-field
deployment, i.e. I create a new init.el file and decide where I want to
store the custom-file, but custom-file doesn't exist yet.

Best, /PA

-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

[-- Attachment #1.2: Type: text/html, Size: 586 bytes --]

[-- Attachment #2: 003-auto-load-custom.diff --]
[-- Type: text/x-patch, Size: 2131 bytes --]

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 7932031397..4d4daeb6cb 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -4710,6 +4710,14 @@ custom-group-state-update
 \f
 ;;; Reading and writing the custom file.
 
+;;;###autoload
+(defcustom custom-file-load-p t
+  "Load `custom-file' if it is not nil.
+Set this variable to `nil' if you want to define `custom-file' but not load it.
+This was possible. As per the old definition,someone could just define the variable
+and not load the file."
+  :type 'boolean)
+
 ;;;###autoload
 (defcustom custom-file nil
   "File used for storing customization information.
@@ -4722,10 +4730,12 @@ custom-file
 something like the following in your init file:
 
 (setq custom-file \"~/.config/emacs-custom.el\")
-(load custom-file)
 
-Note that both lines are necessary: the first line tells Custom to
-save all customizations in this file, but does not load it.
+This will load `custom-file' after the `user-init-file' if
+a) the file exists,
+b) `custom-file-load-p' is `t', and
+c) it was not loaded before explicitly with
+  (load-file custom-file).
 
 When you change this variable outside Custom, look in the
 previous custom file (usually your init file) for the
diff --git a/lisp/startup.el b/lisp/startup.el
index 9f0b23c904..472e5f7ebd 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1494,6 +1494,17 @@ command-line
     (when (featurep 'native-compile)
       (startup--update-eln-cache))
 
+    ;; Load the `custom-file' if it was not loaded before (see documentation)
+
+    ;; if the user defined the custom-file and didn't reset `custom-file-load-p'
+    (when (and custom-file custom-file-load-p)
+      ;; make sure that you get the expanded custom-file name
+      ;; because that's what appears in `load-history'
+      (let ((real-custom-file (expand-file-name custom-file)))
+        ;; if it was loaded, assoc will return non-nil
+        (unless (assoc real-custom-file load-history)
+          (load real-custom-file))))
+
     (when (and deactivate-mark transient-mark-mode)
       (with-current-buffer (window-buffer)
         (deactivate-mark)))

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

* bug#54381: Handling a corner case
  2022-03-17  6:38 ` bug#54381: Handling a corner case Pedro Andres Aranda Gutierrez
@ 2022-03-17  7:09   ` Pedro Andres Aranda Gutierrez
  0 siblings, 0 replies; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-03-17  7:09 UTC (permalink / raw)
  To: 54381


[-- Attachment #1.1: Type: text/plain, Size: 562 bytes --]

Attached the wrong file
/PA

On Thu, 17 Mar 2022 at 07:38, Pedro Andres Aranda Gutierrez <
paaguti@gmail.com> wrote:

> Hi,
>
> just updating the patch for reference. Now handles the green-field
> deployment, i.e. I create a new init.el file and decide where I want to
> store the custom-file, but custom-file doesn't exist yet.
>
> Best, /PA
>
> --
> Fragen sind nicht da um beantwortet zu werden,
> Fragen sind da um gestellt zu werden
> Georg Kreisler
>


-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

[-- Attachment #1.2: Type: text/html, Size: 1203 bytes --]

[-- Attachment #2: 003-auto-load-custom.diff --]
[-- Type: text/x-patch, Size: 2128 bytes --]

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 7932031397..4d4daeb6cb 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -4710,6 +4710,14 @@ custom-group-state-update
 \f
 ;;; Reading and writing the custom file.

+;;;###autoload
+(defcustom custom-file-load-p t
+  "Load `custom-file' if it is not nil.
+Set this variable to `nil' if you want to define `custom-file' but not load it.
+This was possible. As per the old definition,someone could just define the variable
+and not load the file."
+  :type 'boolean)
+
 ;;;###autoload
 (defcustom custom-file nil
   "File used for storing customization information.
@@ -4722,10 +4730,12 @@ custom-file
 something like the following in your init file:

 (setq custom-file \"~/.config/emacs-custom.el\")
-(load custom-file)

-Note that both lines are necessary: the first line tells Custom to
-save all customizations in this file, but does not load it.
+This will load `custom-file' after the `user-init-file' if
+a) the file exists,
+b) `custom-file-load-p' is `t', and
+c) it was not loaded before explicitly with
+  (load-file custom-file).

 When you change this variable outside Custom, look in the
 previous custom file (usually your init file) for the
diff --git a/lisp/startup.el b/lisp/startup.el
index 9f0b23c904..472e5f7ebd 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1494,6 +1494,17 @@ command-line
     (when (featurep 'native-compile)
       (startup--update-eln-cache))

+    ;; Load the `custom-file' if it was not loaded before (see documentation)
+
+    ;; if the user defined the custom-file and didn't reset `custom-file-load-p'
+    (when (and custom-file custom-file-load-p)
+      ;; make sure that you get the expanded custom-file name
+      ;; because that's what appears in `load-history'
+      (let ((real-custom-file (expand-file-name custom-file)))
+        ;; if it was loaded, assoc will return non-nil
+        (unless (assoc real-custom-file load-history)
+          (load real-custom-file t))))
+
     (when (and deactivate-mark transient-mark-mode)
       (with-current-buffer (window-buffer)
         (deactivate-mark)))

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

* bug#54381: 29.0.50; Automatically load custom-file
  2022-03-14 13:58   ` Robert Pluim
@ 2022-04-14 14:05     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-14 14:05 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 54381, Pedro Andres Aranda Gutierrez

Robert Pluim <rpluim@gmail.com> writes:

> I think the long thread on emacs-devel ended with the Montagues and
> the Capulets deciding that now was not the time for war.

So I think the conclusion here is that we don't want to change anything
here, and I'm therefore closing this bug report.

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





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

end of thread, other threads:[~2022-04-14 14:05 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14  8:21 bug#54381: 29.0.50; Automatically load custom-file Pedro Andres Aranda Gutierrez
2022-03-14  9:47 ` Lars Ingebrigtsen
2022-03-14  9:48   ` Lars Ingebrigtsen
2022-03-14 15:14     ` bug#54381: [External] : " Drew Adams
2022-03-14 13:15   ` Eli Zaretskii
2022-03-14 15:26     ` Robert Pluim
2022-03-14 16:19       ` Pedro Andres Aranda Gutierrez
2022-03-14 16:36         ` Robert Pluim
2022-03-14 16:47           ` Pedro Andres Aranda Gutierrez
2022-03-14 17:53             ` Robert Pluim
2022-03-15  7:51               ` Pedro Andres Aranda Gutierrez
2022-03-14 13:58   ` Robert Pluim
2022-04-14 14:05     ` Lars Ingebrigtsen
2022-03-17  6:38 ` bug#54381: Handling a corner case Pedro Andres Aranda Gutierrez
2022-03-17  7:09   ` Pedro Andres Aranda Gutierrez

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