Next: Create convenience commands to load a derivative theme, Previous: Complete example of a Modus derivative theme, Up: Build on top of the Modus themes [Index]
[ NOTE: Users of many Modus derivatives do not need to do anything of
what is described herein. Just enable the modus-themes-include-derivatives-mode. ]
Once the theme is instantiated, it will be listed in the return value
of the function modus-themes-get-all-known-themes. This function
accepts an optional argument to filter themes by their given family,
as specified at the time of the theme’s reification (Build on top of the Modus themes).
The generic function modus-themes-get-themes is how developers/users
can affect what counts as a “Modus” theme. By default,
modus-themes-get-themes essentially calls the following, to only
return the themes whose family is ‘modus-themes’:
(modus-themes-get-all-known-themes 'modus-themes)
A new method can be declared with cl-defmethod to do something else
instead. When exactly should that method come into effect is up to the
developer/user. In the ef-themes, this is done via a minor mode,
that users must opt in to. Here is the complete example:
(define-minor-mode ef-themes-take-over-modus-themes-mode "When enabled, all Modus themes commands consider only Ef themes." :global t :init-value nil) (cl-defmethod modus-themes-get-themes (&context (ef-themes-take-over-modus-themes-mode (eql t))) (if-let* ((themes (modus-themes-get-all-known-themes 'ef-themes)) (sorted-themes (modus-themes-sort themes 'light))) sorted-themes ef-themes-items))
The define-minor-mode does not need to do anything else here. Its
corresponding function simply takes care to toggle the variable of the
same name (i.e. ef-themes-take-over-modus-themes-mode) between nil
and non-nil. The method will take effect when the minor mode is
enabled. In this scenario, “Modus” themes are only those whose family
is ‘ef-themes’. All the Modus commands that switch between themes will
thus only work with those Ef themes.
For our part, we define the modus-themes-include-derivatives-mode.
It is how users can opt in to the all-inclusive conception of “Modus”.
In this scenario, every theme that is declared with the aforementioned
modus-themes-theme will count as “Modus” and be available to all the
relevant commands for switching themes, previewing their palette, and
so on.
(define-minor-mode modus-themes-include-derivatives-mode "When enabled, all Modus themes commands cover derivatives as well. Otherwise, they only consider the `modus-themes-items'. Derivative theme projects can implement the equivalent of this minor mode plus a method for `modus-themes-get-themes' to filter themes accordingly." :global t :init-value nil) (cl-defmethod modus-themes-get-themes (&context (modus-themes-include-derivatives-mode (eql t))) (if-let* ((themes (modus-themes-get-all-known-themes nil)) (sorted-themes (modus-themes-sort themes 'light))) sorted-themes modus-themes-items))