Subject: bug#78637: 30.1.90; Calling setopt during init loads cus-start over and over

From: Stefan Monnier <[email-masked]>
Date: Fri, 27 Jun 2025 17:44:38 -0400

>> IIUC on Android, the first time the users run their Emacs, you run
>> a special session started from `temacs` with `dump-mode=nil` but where
>> you do perform a dump at the end of `loadup` and then continue on to
>> a normal GUI startup?
>>
>> In that case, I'd expect that this first GUI session works correctly
>> (w.r.t `custom-reevaluate-setting`), but indeed the subsequent runs
>> (which presumably make use of the generated pdmp file) will fail to
>> reevaluate the settings.
>>
>> Is that what you saw?
>
> I believe so, yes, though there is no `temacs' binary, just a shared
> object that is loaded into `/system/bin/app_process' and which is used
> to load dumped and undumped sessions alike.

Then I suggest the patch below.

        Stefan

diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 5057ab93161..79c23d9328b 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -949,7 +949,7 @@ minibuffer-prompt-properties--setter
       ;; If this is NOT while dumping Emacs, set up the rest of the
       ;; customization info.  This is the stuff that is not needed
       ;; until someone does M-x customize etc.
-      (if (or dump-mode (and (featurep 'android) (not after-init-time)))
+      (if (bound-and-true-p cus-start--preload)
 	  ;; Don't re-add to custom-delayed-init-variables post-startup.
 	  ;; Note this is the _only_ initialize property we handle.
 	  (if (eq (cadr (memq :initialize rest)) #'custom-initialize-delay)
diff --git a/lisp/loadup.el b/lisp/loadup.el
index 6748c0a0750..c6cfc5690e2 100644
--- a/lisp/loadup.el
+++ b/lisp/loadup.el
@@ -392,7 +392,8 @@
            (compiled-function-p (symbol-function 'macroexpand-all)))
   (setq internal-make-interpreted-closure-function
         #'cconv-make-interpreted-closure))
-(load "cus-start") ;Late to reduce customize-rogue (needs loaddefs.el anyway)
+(dlet ((cus-start--preload t))
+  (load "cus-start")) ;Late to reduce customize-rogue (needs loaddefs.el anyway)
 (load "tooltip")
 (load "international/iso-transl") ; Binds Alt-[ and friends.