Function: theme-choose-variant

theme-choose-variant is an interactive and byte-compiled function defined in custom.el.gz.

Signature

(theme-choose-variant &optional NO-CONFIRM NO-ENABLE)

Documentation

Switch from the current theme to one of its variants.

The current theme will be disabled before variant is enabled. If the current theme has only one variant, switch to that variant without prompting, otherwise prompt for the variant to select. See load-theme for the meaning of NO-CONFIRM and NO-ENABLE.

View in manual

Key Bindings

Aliases

toggle-theme

Source Code

;; Defined in /usr/src/emacs/lisp/custom.el.gz
(defun theme-choose-variant (&optional no-confirm no-enable)
  "Switch from the current theme to one of its variants.
The current theme will be disabled before variant is enabled.  If
the current theme has only one variant, switch to that variant
without prompting, otherwise prompt for the variant to select.
See `load-theme' for the meaning of NO-CONFIRM and NO-ENABLE."
  (interactive)
  (let ((active-color-schemes
         (seq-filter
          (lambda (theme)
            ;; FIXME: As most themes currently do not have a `:kind'
            ;; tag, it is assumed that a theme is a color scheme by
            ;; default.  This should be reconsidered in the future.
            (memq (plist-get (get theme 'theme-properties) :kind)
                  '(color-scheme nil)))
          custom-enabled-themes)))
    (cond
     ((length= active-color-schemes 0)
      (user-error "No theme is active, cannot toggle"))
     ((length> active-color-schemes 1)
      (user-error "More than one theme active, cannot unambiguously toggle")))
    (let* ((theme (car active-color-schemes))
           (family (plist-get (get theme 'theme-properties) :family)))
      (unless family
        (error "Theme `%s' does not have any known variants" theme))
      (let* ((variants (theme-list-variants theme))
             (choice (cond
                      ((null variants)
                       (error "`%s' has no variants" theme))
                      ((length= variants 1)
                       (car variants))
                      ((intern (completing-read "Load custom theme: " variants))))))
        (disable-theme theme)
        (load-theme choice no-confirm no-enable)))))