Skip to content

Get a single color from the palette with modus-themes-get-color-value

The function modus-themes-get-color-value can be called from Lisp to return the value of a color from the active Modus theme palette. It takea a ‘COLOR’ argument and an optional ‘OVERRIDES’. It also accepts a third ‘THEME’ argument, to get the color from the given theme.

COLOR’ is a symbol that represents a named color entry in the palette (Preview theme colors).

If the value is the name of another color entry in the palette (so a mapping), this function recurs until it finds the underlying color value.

With an optional ‘OVERRIDES’ argument as a non-nil value, it accounts for palette overrides. Else it reads only the default palette (Option for palette overrides)

With an optional ‘THEME’ as a symbol among the modus-themes-items (alias modus-themes-collection), it uses the palette of that theme. Else it uses the current Modus theme.

If ‘COLOR’ is not present in the palette, this function returns the unspecified symbol, which is safe when used as a face attribute’s value.

An example with modus-operandi to show how this function behaves with/without overrides and when recursive mappings are introduced.

emacs-lisp
;; Here we show the recursion of palette mappings.  In general, it is
;; better for the user to specify named colors to avoid possible
;; confusion with their configuration, though those still work as
;; expected.
(setq modus-themes-common-palette-overrides
      '((cursor red)
        (fg-mode-line-active cursor)
        (border-mode-line-active fg-mode-line-active)))

;; Ignore the overrides and get the original value.
(modus-themes-get-color-value 'border-mode-line-active)
;; => "#5a5a5a"

;; Read from the overrides and deal with any recursion to find the
;; underlying value.
(modus-themes-get-color-value 'border-mode-line-active :overrides)
;; => "#a60000"