Subject: Re: bug#66742: 30.0.50; transient-mark-mode is not enabled after re-dumping Emacs

From: Eli Zaretskii <[email-masked]>
Date: Thu, 26 Oct 2023 15:06:31 +0300

> Cc: [email-masked]
> From: Ihor Radchenko <[email-masked]>
> Date: Thu, 26 Oct 2023 11:42:57 +0000
> 
> Actually, I think that I will not be wrong to say that (defvar foo
> <value>. ..), (defcustom foo <value> ...), and similar expressions are
> often assumed to evaluated in the same Emacs session that will use the
> library.

There should be no such assumption, and so you will be wrong saying
that.  We actually try paying attention to this aspect when reviewing
patches where a defcustom has a default value that is not a constant,
precisely for this reason.

> For example, Org mode often calculated default variable values
> dynamically:
> 
> (defcustom org-clock-x11idle-program-name
>   (if (executable-find "xprintidle")
>       "xprintidle" "x11idle")
> ...)

That's a bug in Org, unless the rest of the code doesn't arrange for
this defcustom to be re-evaluated at startup.

> Things get worse when loading a library relies on side effects:
> 
> ----- org-persist.el ---------
> ;; Point to temp directory when `org-persist--disable-when-emacs-Q' is set.
> (when (and org-persist--disable-when-emacs-Q
>            ;; FIXME: This is relying on undocumented fact that
>            ;; Emacs sets `user-init-file' to nil when loaded with
>            ;; "-Q" argument.
>            (not user-init-file))
>   (setq org-persist-directory
>         (make-temp-file "org-persist-" 'dir)))
> ----------------------------

Which library does the above load, and how is it related to something
determined at dump time?

> I suspect that it is only truly safe to re-dump parts of the libraries
> that do not emit (byte-code ...) in the compiler output.
> 
> For example, the following is .elc part corresponding to the above
> defcustom:
> 
> (defvar org-x11idle-exists-p (byte-code "\302>?\205%17\303\304\305	\"!\306=\205%17\303	!\306=\207" [system-type org-clock-x11idle-program-name (windows-nt ms-dos) call-process-shell-command format "command -v %s" 0] 4))#@46 Return the current X11 idle time in seconds.
> 
> The variable itself can be defined, but its value is (byte-code ...) and
> thus should be evaluated during startup, and not dumped.
> 
> And the side-effect clause is a complete (byte-code ...):
> 
> (byte-code "\203%d	\204%d\303\304\305\"%12\306\307\n!!\310%1!\204%%0\211\306\311%3!!\211\262%3\232\203%12\312%1!\2044%0\313\314\n\"\266%2\202D%0\315\316\317\"\210\315\316\320\"\210\315\316\321\"\266%2\315\322\323\"\210\324\325!\207" [org-persist--disable-when-emacs-Q user-init-file org-persist-directory make-temp-file "org-persist-" dir directory-file-name file-name-as-directory file-exists-p file-name-directory file-writable-p message "Missing write access rights to org-persist-directory: %S" add-hook kill-emacs-hook org-persist-clear-storage-maybe org-persist-write-all org-persist-gc after-init-hook org-persist-load-all provide org-persist] 5)

You lost me here.