Make the modus-themes-theme a defun instead of a defmacro

I have been facing issues with the macro where certain palette entries
are not known at compile time. I want to experiment with the defun, as
it is always going to be called at runtime.
This commit is contained in:
Protesilaos Stavrou 2025-10-20 07:26:37 +03:00
parent c2aa51f495
commit 085ee06c57
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
9 changed files with 80 additions and 91 deletions

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,8 +74,8 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-operandi-deuteranopia
modus-themes
'modus-operandi-deuteranopia
'modus-themes
"Deuteranopia-optimized theme with a white background.
This variant is optimized for users with red-green color
deficiency (deuteranopia). It conforms with the highest
@ -84,9 +83,9 @@ legibility standard for color contrast between background and
foreground in any given piece of text, which corresponds to a
minimum contrast in relative luminance of 7:1 (WCAG AAA
standard)."
light
modus-themes-operandi-deuteranopia-palette
modus-operandi-deuteranopia-palette-user
modus-operandi-deuteranopia-palette-overrides))
'light
'modus-themes-operandi-deuteranopia-palette
'modus-operandi-deuteranopia-palette-user
'modus-operandi-deuteranopia-palette-overrides)
;;; modus-operandi-deuteranopia-theme.el ends here

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,16 +74,16 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-operandi
modus-themes
'modus-operandi
'modus-themes
"Elegant, highly legible theme with a white background.
Conforms with the highest legibility standard for color contrast
between background and foreground in any given piece of text,
which corresponds to a minimum contrast in relative luminance of
7:1 (WCAG AAA standard)."
light
modus-themes-operandi-palette
modus-operandi-palette-user
modus-operandi-palette-overrides))
'light
'modus-themes-operandi-palette
'modus-operandi-palette-user
'modus-operandi-palette-overrides)
;;; modus-operandi-theme.el ends here

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,16 +74,16 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-operandi-tinted
modus-themes
'modus-operandi-tinted
'modus-themes
"Elegant, highly legible theme with a light ochre background.
Conforms with the highest legibility standard for color contrast
between background and foreground in any given piece of text,
which corresponds to a minimum contrast in relative luminance of
7:1 (WCAG AAA standard)."
light
modus-themes-operandi-tinted-palette
modus-operandi-tinted-palette-user
modus-operandi-tinted-palette-overrides))
'light
'modus-themes-operandi-tinted-palette
'modus-operandi-tinted-palette-user
'modus-operandi-tinted-palette-overrides)
;;; modus-operandi-tinted-theme.el ends here

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,8 +74,8 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-operandi-tritanopia
modus-themes
'modus-operandi-tritanopia
'modus-themes
"Tritanopia-optimized theme with a white background.
This variant is optimized for users with blue-yellow color
deficiency (tritanopia). It conforms with the highest
@ -84,9 +83,9 @@ legibility standard for color contrast between background and
foreground in any given piece of text, which corresponds to a
minimum contrast in relative luminance of 7:1 (WCAG AAA
standard)."
light
modus-themes-operandi-tritanopia-palette
modus-operandi-tritanopia-palette-user
modus-operandi-tritanopia-palette-overrides))
'light
'modus-themes-operandi-tritanopia-palette
'modus-operandi-tritanopia-palette-user
'modus-operandi-tritanopia-palette-overrides)
;;; modus-operandi-tritanopia-theme.el ends here

View file

@ -7270,7 +7270,7 @@ properties, use `modus-themes-declare'."
(add-to-list 'modus-themes-registered-items name))
;;;###autoload
(defmacro modus-themes-theme (name family description background-mode core-palette user-palette overrides-palette &optional custom-faces custom-variables)
(defun modus-themes-theme (name family description background-mode core-palette user-palette overrides-palette &optional custom-faces custom-variables)
"Define a Modus theme or derivative thereof.
NAME is the name of the new theme. FAMILY is the collection of themes
it belongs to. DESCRIPTION is its documentation string.
@ -7286,40 +7286,37 @@ the Modus themess have by default.
Consult the manual for details on how to build a theme on top of the
`modus-themes': Info node `(modus-themes) Build on top of the Modus themes'."
(declare (indent 0))
(let ((sym (gensym))
(colors (mapcar #'car (symbol-value core-palette)))
(theme-exists-p (custom-theme-p name)))
`(progn
,@(unless theme-exists-p
(list
`(modus-themes-declare
',name ',family
,description ',background-mode
',core-palette ',user-palette ',overrides-palette)))
,@(unless (eq family 'modus-themes)
(list
`(modus-themes-register ',name)))
(let* ((c '((class color) (min-colors 256)))
(,sym (modus-themes--get-theme-palette-subr ',name :with-overrides :with-user-palette))
,@(mapcar
(lambda (color)
(list color `(modus-themes--retrieve-palette-value ',color ,sym)))
colors))
(ignore c ,@colors) ; Silence unused variable warnings
(custom-theme-set-faces
',name
,@(append
(symbol-value custom-faces)
modus-themes-faces))
(custom-theme-set-variables
',name
,@(append
modus-themes-custom-variables
(symbol-value custom-variables)
(list `'(frame-background-mode ',background-mode))))
,@(unless theme-exists-p
(list `(provide-theme ',name)))))))
(let ((theme-exists-p (custom-theme-p name))
(faces (append
(symbol-value custom-faces)
modus-themes-faces))
(variables (append
modus-themes-custom-variables
(symbol-value custom-variables)
(list `'(frame-background-mode ',background-mode)))))
(unless theme-exists-p
(modus-themes-declare
name family
description background-mode
core-palette user-palette overrides-palette))
(let ((palette (modus-themes--get-theme-palette-subr name :with-overrides :with-user-palette)))
(eval
`(let* ((c '((class color) (min-colors 256)))
,@(mapcar
(pcase-lambda (`(,name ,value))
(pcase value
('unspecified (list name ''unspecified))
((pred symbolp) (list name `(modus-themes--retrieve-palette-value ',name ',palette)))
((pred stringp) (list name value))))
palette))
(custom-theme-set-faces
',name
,@faces)
(custom-theme-set-variables
',name
,@variables))))
(unless theme-exists-p
(provide-theme name))))
;;;; Use theme colors

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,8 +74,8 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-vivendi-deuteranopia
modus-themes
'modus-vivendi-deuteranopia
'modus-themes
"Deuteranopia-optimized theme with a black background.
This variant is optimized for users with red-green color
deficiency (deuteranopia). It conforms with the highest
@ -84,9 +83,9 @@ legibility standard for color contrast between background and
foreground in any given piece of text, which corresponds to a
minimum contrast in relative luminance of 7:1 (WCAG AAA
standard)."
dark
modus-themes-vivendi-deuteranopia-palette
modus-vivendi-deuteranopia-palette-user
modus-vivendi-deuteranopia-palette-overrides))
'dark
'modus-themes-vivendi-deuteranopia-palette
'modus-vivendi-deuteranopia-palette-user
'modus-vivendi-deuteranopia-palette-overrides)
;;; modus-vivendi-deuteranopia-theme.el ends here

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,16 +74,16 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-vivendi
modus-themes
'modus-vivendi
'modus-themes
"Elegant, highly legible theme with a black background.
Conforms with the highest legibility standard for color contrast
between background and foreground in any given piece of text,
which corresponds to a minimum contrast in relative luminance of
7:1 (WCAG AAA standard)."
dark
modus-themes-vivendi-palette
modus-vivendi-palette-user
modus-vivendi-palette-overrides))
'dark
'modus-themes-vivendi-palette
'modus-vivendi-palette-user
'modus-vivendi-palette-overrides)
;;; modus-vivendi-theme.el ends here

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,16 +74,16 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-vivendi-tinted
modus-themes
'modus-vivendi-tinted
'modus-themes
"Elegant, highly legible theme with a night sky background.
Conforms with the highest legibility standard for color contrast
between background and foreground in any given piece of text,
which corresponds to a minimum contrast in relative luminance of
7:1 (WCAG AAA standard)."
dark
modus-themes-vivendi-tinted-palette
modus-vivendi-tinted-palette-user
modus-vivendi-tinted-palette-overrides))
'dark
'modus-themes-vivendi-tinted-palette
'modus-vivendi-tinted-palette-user
'modus-vivendi-tinted-palette-overrides)
;;; modus-vivendi-tinted-theme.el ends here

View file

@ -34,7 +34,6 @@
(eval-and-compile
(unless (and (fboundp 'require-theme)
load-file-name
(equal (file-name-directory load-file-name)
@ -75,8 +74,8 @@ represents."
:link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
modus-vivendi-tritanopia
modus-themes
'modus-vivendi-tritanopia
'modus-themes
"Tritanopia-optimized theme with a black background.
This variant is optimized for users with blue-yellow color
deficiency (tritanopia). It conforms with the highest
@ -84,9 +83,9 @@ legibility standard for color contrast between background and
foreground in any given piece of text, which corresponds to a
minimum contrast in relative luminance of 7:1 (WCAG AAA
standard)."
dark
modus-themes-vivendi-tritanopia-palette
modus-vivendi-tritanopia-palette-user
modus-vivendi-tritanopia-palette-overrides))
'dark
'modus-themes-vivendi-tritanopia-palette
'modus-vivendi-tritanopia-palette-user
'modus-vivendi-tritanopia-palette-overrides)
;;; modus-vivendi-tritanopia-theme.el ends here