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

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