~protesilaos/standard-themes

1

Bug? Cannot define a function that uses standard-themes-with-colors before loading any theme

Zack Weinberg <zack@owlfolio.org>
Details
Message ID
<0057b4d4-dbb2-4a5e-8b15-4a68c0c4a0c6@app.fastmail.com>
DKIM signature
missing
Download raw message
Suppose you are trying to define a post-load hook like it suggests in
the manual, e.g. you have something like this in your init file:

(require 'standard-themes)
(defun my-hook-standard-themes-post-load ()
  (standard-themes-with-colors
    (face-spec-set 'whitespace-tab `(,c . (:background ,bg-red-subtle)))))
(add-hook 'standard-themes-post-load-hook #'my-hook-standard-themes-post-load)
(standard-themes-load-light)

Suppose also that no themes whatsoever have been loaded prior to this
point; custom-enabled-themes is nil.  Then macro expansion of the defun
will fail; in --debug-init mode I get this backtrace

Debugger entered--Lisp error: (error "Eager macro-expansion failure: (user-error \"No ena...")
error("Eager macro-expansion failure: %S" (user-error "No enabled Standard theme could be found"))
internal-macroexpand-for-load((defalias 'my-hook-standard-themes-post-load #'(...)) t)
load-with-code-conversion(".../init.el" ".../init.el" t t)
load(".../emacs/init" noerror nomessage)
startup--load-user-init-file(...)
command-line()
normal-top-level()

The problem seems to be that standard-themes-with-colors invokes
standard-themes--current-theme-palette *at macro expansion time*,
which is too early.  In fact I can reproduce the failure from
emacs -Q by evaluating

(package-initialize)
(require 'standard-themes)
(macroexpand '(standard-themes-with-colors))

in the *scratch* buffer, i.e. the body of the macro form doesn't come
into play at all.  (You won't see a backtrace if you do this, but the
third form will not evaluate to any value and "No enabled Standard
theme could be found" will be printed in the echo area.)

zw
Details
Message ID
<87jzpe7c9k.fsf@protesilaos.com>
In-Reply-To
<0057b4d4-dbb2-4a5e-8b15-4a68c0c4a0c6@app.fastmail.com> (view parent)
DKIM signature
missing
Download raw message
Hello Zack,

> From: "Zack Weinberg" <zack@owlfolio.org>
> Date: Tue, 28 Nov 2023 15:31:57 -0500

> [... 15 lines elided]

> Debugger entered--Lisp error: (error "Eager macro-expansion failure: (user-error \"No ena...")
> error("Eager macro-expansion failure: %S" (user-error "No enabled Standard theme could be found"))
> internal-macroexpand-for-load((defalias 'my-hook-standard-themes-post-load #'(...)) t)
> load-with-code-conversion(".../init.el" ".../init.el" t t)
> load(".../emacs/init" noerror nomessage)
> startup--load-user-init-file(...)
> command-line()
> normal-top-level()

I just pushed commit 4b9e539 which should fix this problem. Please let
me know if there are any further issues.

All the best,
Protesilaos (or simply "Prot")

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)