Complete example of a custom theme with its own palette (Modus themes for GNU Emacs)

Next: , Previous: , Up: Complete example of a Modus derivative theme [Index]


8.1.3 Complete example of a custom theme with its own palette

It is a good idea for a derivative theme to use as its core palette one of those defined in the modus-themes, such as modus-operandi-palette. This guarantees that all core palette definitions are inherited by the derivative theme.

The derivative may then add its own colors to the user palette, which will override the core palette in such of a conflict (Preview theme colors).

The core and user palettes are among the arguments passed to the modus-themes-theme functions, as explained elsewhere in this manual (Build on top of the Modus themes).

In the following example, we are defining the prot-light theme in the ‘prot-light-theme.el’ file. This theme declares itself as belonging to the ‘prot-themes’ family. It is based on the modus-operandi-palette but then defines its own palette, the prot-light-palette with entries that take precedence over whatever equivalent is in the modus-operandi-palette.

(defvar prot-light-palette
 '((cursor "#ff0000")
 (bg-main "#f0e0d0")
 (fg-main "#202020"))
 "Like `modus-operandi-palette'.")
(modus-themes-theme
 'prot-light
 'prot-themes
 "My demo `prot-light' theme."
 'light
 'modus-operandi-palette
 'prot-light-palette
 nil)

The above is a complete theme which is like modus-operandi except for those three color definitions specified in the prot-light-palette. There is no limit to how comprehensive the user palette is.

Depending on the requirements, this theme can make itself further customizable by the end user via theme-specific palette overrides. In this case, we have the addition of a user option, which we could call anything though it makes sense to name it consistently like prot-light-palette-overrides.

(defvar prot-light-palette
 '((cursor "#ff0000")
 (bg-main "#f0e0d0")
 (fg-main "#202020"))
 "Like `modus-operandi-palette'.")
(defcustom prot-light-palette-overrides nil
 "Overrides for the `prot-light' theme."
 :type '(repeat (list symbol (choice symbol string)))
 :link '(info-link "(modus-themes) Palette overrides"))
(modus-themes-theme
 'prot-light
 'prot-themes
 "My demo `prot-light' theme."
 'light
 'modus-operandi-palette
 'prot-light-palette
 'prot-light-palette-overrides)

In the above example, we have our prot-light theme which is like modus-operandi except three colors and which can now be customized further by the user via the prot-light-palette-overrides (Option for palette overrides).

Finally, a derivative theme can specify its own settings for custom faces and variables. This is generally not needed, but is provided as an option for maximum flexibility. In the following example, the prot-light theme has its own face definitions in addition to all the aforementioned:

(defvar prot-light-palette
 '((cursor "#ff0000")
 (bg-main "#f0e0d0")
 (fg-main "#202020"))
 "Like `modus-operandi-palette'.")
(defcustom prot-light-palette-overrides nil
 "Overrides for the `prot-light' theme."
 :type '(repeat (list symbol (choice symbol string)))
 :link '(info-link "(modus-themes) Palette overrides"))
(defvar prot-light-custom-faces
 '(
 `(region ((,c :background ,bg-ochre :foreground ,unspecified :extend nil)))
 `(font-lock-keyword-face ((,c :inherit italic :foreground ,keyword))))
 "Custom faces that deviate from---or complement---those in the Modus themes.")
(modus-themes-theme
 'prot-light
 'prot-themes
 "My demo `prot-light' theme."
 'light
 'modus-operandi-palette
 'prot-light-palette
 'prot-light-palette-overrides
 'prot-light-custom-faces)

The custom faces can name a color from the given theme’s palette. In this example, ‘bg-ochre’ comes from the modus-operandi-palette though it would work the same way if, say, prot-light-palette defined bg-soil and then referenced it in prot-light-custom-faces.

Arrange to activate your derivative themes.


Next: Complete example that also uses modus-themes-generate-palette, Previous: Complete example of a private theme derived from Modus, Up: Complete example of a Modus derivative theme [Index]

AltStyle によって変換されたページ (->オリジナル) /