bug#81499: 30.2; Truncation of custom settings when custom-safe-themes changes
Brad Howes via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]> Mon, 3 Aug 2026 10:30:36 +0200
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_C09ACAB4-6395-4674-B58A-E3ABB548F70E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jul 31, 2026, at 12:23=E2=80=AFPM, Sean Whitton = <[email protected]> wrote: >=20 > [ please reply-all so your message reaches the bug tracker ] >=20 > Brad Howes [30/Jul 3:12pm +02] wrote: >> Correct. However, as reported I have `custom-file` set and I have = only >> noticed the changes there. Unclear if same behavior exits when >> `custom-file` is not set. >=20 > Thanks for confirming that. It looks like we have a straightforward = bug > in the code for modifying/writing custom files. Sean, I did some additional investigation into this bug. I created a minimal = reproducible case as follows: Create an empty directory to serve as Emacs init directory =E2=80=94 = `mkdir ~/emacs.d.bug` Create `elpa` subdirectory =E2=80=94 `mkdir ~/emacs.d.bug/elpa` Add `modus-themes-5.3.0` to `~/emacs.d.bug/elpa/` =E2=80=94 `cp -r = ~/.emacs.d/elpa/modus-themes-5.3.0 ~/emacs.d.bug/elpa/` Create an `init.el` file in `~/emacs.d.bug` with the following contents: ``` (setq custom-file (file-truename (locate-user-emacs-file "custom.el")) use-hook nil) (message "custom-file: %s" custom-file) (if use-hook (add-hook 'after-init-hook (lambda () (when (file-exists-p custom-file) (message "after-init-hook loading custom-file '%s'" = custom-file) (load custom-file 'noerror)))) (message "init.el loading custom-file '%s'" custom-file) (load custom-file 'noerror)) ``` Create a `custom.el` file in `~/emacs.d.bug/` with the following = contents: ``` (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(custom-enabled-themes '(modus-vivendi)) '(custom-safe-themes '(default)) '(dired-dwim-target t) '(dired-isearch-filenames t)) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(show-paren-match ((t (:background "#0d0d0d" :foreground "spring = green" :underline nil :weight ultra-bold))))) ``` Start Emacs with the option `=E2=80=94init-directory ~/emacs.d.bug` Emacs frame should appear with `Loading a theme can run Lisp code. = Really load? (y or n)` Answer with `y` A new prompt should appear with `Treat this theme as safe in future = sessions? (y or n)` Answer with `y` At this point, if `use-hook` is set to `t` in the `init.el` file, the = `custom.el` file is truncated after the `custom-safe-themes` setting and = the `custom-set-faces` will be empty. If the `use-hook` variable is set to `nil`, no truncation takes place in = the `custom.el` file and the `custom-safe-themes` value contains the = hash of the theme. So, it appears that changing performing the `load-file` from the = `after-init-hook` is the source of the corruption. Regards, Brad --Apple-Mail=_C09ACAB4-6395-4674-B58A-E3ABB548F70E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" = content=3D"text/html; charset=3Dutf-8"></head><body = style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; = line-break: after-white-space;"><br><div><blockquote type=3D"cite"><div>On= Jul 31, 2026, at 12:23=E2=80=AFPM, Sean Whitton = <[email protected]> wrote:</div><br = class=3D"Apple-interchange-newline"><div><div>[ please reply-all so your = message reaches the bug tracker ]<br><br>Brad Howes [30/Jul 3:12pm = +02] wrote:<br><blockquote type=3D"cite">Correct. However, as reported I = have `custom-file` set and I have only<br>noticed the changes there. = Unclear if same behavior exits when<br>`custom-file` is not = set.<br></blockquote><br>Thanks for confirming that. It looks like = we have a straightforward bug<br>in the code for modifying/writing = custom = files.<br></div></div></blockquote><div><br></div><div>Sean,</div><div><br= ></div><div>I did some additional investigation into this bug. I created = a minimal reproducible case as follows:</div><div><br></div><div = style=3D"text-align: left;"><ul class=3D"MailOutline"><li>Create an = empty directory to serve as Emacs init directory =E2=80=94 `mkdir = ~/emacs.d.bug`</li><li>Create `elpa` subdirectory =E2=80=94 `mkdir = ~/emacs.d.bug/elpa`</li><li>Add `modus-themes-5.3.0` to = `~/emacs.d.bug/elpa/` =E2=80=94 `cp -r = ~/.emacs.d/elpa/modus-themes-5.3.0 ~/emacs.d.bug/elpa/`</li><li>Create = an `init.el` file in `~/emacs.d.bug` with the following = contents:</li></ul><div><br></div><div>```</div><div><div>(setq = custom-file (file-truename (locate-user-emacs-file = "custom.el"))</div><div> use-hook = nil)</div><div>(message "custom-file: %s" = custom-file)</div><div><br></div><div>(if use-hook</div><div> = (add-hook 'after-init-hook</div><div> = (lambda ()</div><div> = (when (file-exists-p custom-file)</div><div> = (message = "after-init-hook loading custom-file '%s'" custom-file)</div><div> = (load custom-file = 'noerror))))</div><div> (message "init.el loading custom-file = '%s'" custom-file)</div><div> (load custom-file = 'noerror))</div><div>```</div></div><div><br></div><div><ul = class=3D"MailOutline"><li>Create a `custom.el` file in `~/emacs.d.bug/` = with the following = contents:</li></ul><div><br></div></div><div>```</div><div><div>(custom-se= t-variables</div><div> ;; custom-set-variables was added by = Custom.</div><div> ;; If you edit it by hand, you could mess it up, = so be careful.</div><div> ;; Your init file should contain only one = such instance.</div><div> ;; If there is more than one, they won't = work right.</div><div> '(custom-enabled-themes = '(modus-vivendi))</div><div> '(custom-safe-themes</div><div> = '(default))</div><div> '(dired-dwim-target = t)</div><div> '(dired-isearch-filenames = t))</div><div><br></div><div>(custom-set-faces</div><div> ;; = custom-set-faces was added by Custom.</div><div> ;; If you edit it = by hand, you could mess it up, so be careful.</div><div> ;; Your = init file should contain only one such instance.</div><div> ;; If = there is more than one, they won't work = right.</div><div> '(show-paren-match ((t (:background "#0d0d0d" = :foreground "spring green" :underline nil :weight = ultra-bold)))))</div><div>```</div></div><div><br></div><div><ul = class=3D"MailOutline"><li>Start Emacs with the option `=E2=80=94init-direc= tory ~/emacs.d.bug`</li><li>Emacs frame should appear with `Loading a = theme can run Lisp code. Really load? (y or n)`</li><li>Answer with = `y`</li><li>A new prompt should appear with `Treat this theme as safe in = future sessions? (y or n)`</li><li>Answer with = `y`</li></ul><div><br></div></div><div>At this point, if `use-hook` is = set to `t` in the `init.el` file, the `custom.el` file is truncated = after the `custom-safe-themes` setting and the `custom-set-faces` will = be empty.</div><div>If the `use-hook` variable is set to `nil`, no = truncation takes place in the `custom.el` file and the = `custom-safe-themes` value contains the hash of the = theme.</div><div><br></div><div>So, it appears that changing performing = the `load-file` from the `after-init-hook` is the source of the = corruption.</div><div><br></div><div>Regards,</div><div><br></div><div>Bra= d</div><div><br></div></div></div></body></html>= --Apple-Mail=_C09ACAB4-6395-4674-B58A-E3ABB548F70E--