Function: load-theme
load-theme is an interactive and byte-compiled function defined in
custom.el.gz.
Signature
(load-theme THEME &optional NO-CONFIRM NO-ENABLE)
Documentation
Load Custom theme named THEME from its file and possibly enable it.
The theme file is named THEME-theme.el, in one of the directories
specified by custom-theme-load-path.
If the theme is not considered safe by custom-safe-themes,
prompt the user for confirmation before loading it. But if
optional arg NO-CONFIRM is non-nil, load the theme without
prompting.
Normally, this function also enables THEME. If optional arg NO-ENABLE is non-nil, load the theme but don't enable it, unless the theme was already enabled.
Note that enabling THEME does not disable any other
already-enabled themes. If THEME is enabled, it has the highest
precedence (after user) among enabled themes. To disable other
themes, use disable-theme.
This function is normally called through Customize when setting
custom-enabled-themes. If used directly in your init file, it
should be called with a non-nil NO-CONFIRM argument, or after
custom-safe-themes has been loaded.
Return t if THEME was successfully loaded, nil otherwise.
Probably introduced at or before Emacs version 22.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/custom.el.gz
(defun load-theme (theme &optional no-confirm no-enable)
"Load Custom theme named THEME from its file and possibly enable it.
The theme file is named THEME-theme.el, in one of the directories
specified by `custom-theme-load-path'.
If the theme is not considered safe by `custom-safe-themes',
prompt the user for confirmation before loading it. But if
optional arg NO-CONFIRM is non-nil, load the theme without
prompting.
Normally, this function also enables THEME. If optional arg
NO-ENABLE is non-nil, load the theme but don't enable it, unless
the theme was already enabled.
Note that enabling THEME does not disable any other
already-enabled themes. If THEME is enabled, it has the highest
precedence (after `user') among enabled themes. To disable other
themes, use `disable-theme'.
This function is normally called through Customize when setting
`custom-enabled-themes'. If used directly in your init file, it
should be called with a non-nil NO-CONFIRM argument, or after
`custom-safe-themes' has been loaded.
Return t if THEME was successfully loaded, nil otherwise."
(interactive
(list
(intern (completing-read "Load custom theme: "
(mapcar #'symbol-name
(custom-available-themes))))
nil nil))
(unless (custom-theme-name-valid-p theme)
(error "Invalid theme name `%s'" theme))
;; If THEME is already enabled, re-enable it after loading, even if
;; NO-ENABLE is t.
(if no-enable
(setq no-enable (not (custom-theme-enabled-p theme))))
;; If reloading, clear out the old theme settings.
(when (custom-theme-p theme)
(disable-theme theme)
(put theme 'theme-settings nil)
(put theme 'theme-feature nil)
(put theme 'theme-documentation nil))
(let ((file (locate-file (concat (symbol-name theme) "-theme.el")
(custom-theme--load-path)
'("" "c")))
(custom--inhibit-theme-enable t))
;; Check file safety with `custom-safe-themes', prompting the
;; user if necessary.
(cond ((not file)
(error "Unable to find theme file for `%s'" theme))
((or no-confirm
(eq custom-safe-themes t)
(and (memq 'default custom-safe-themes)
(equal (file-name-directory file)
(expand-file-name "themes/" data-directory))))
;; Theme is safe; load byte-compiled version if available.
(load (file-name-sans-extension file) nil t nil t))
((with-temp-buffer
(insert-file-contents file)
(let ((hash (secure-hash 'sha256 (current-buffer))))
(when (or (member hash custom-safe-themes)
(custom-theme-load-confirm hash))
(eval-buffer nil nil file)
t))))
(t
(error "Unable to load theme `%s'" theme))))
(when-let ((obs (get theme 'byte-obsolete-info)))
(display-warning 'initialization
(format "The `%s' theme is obsolete%s"
theme
(if (nth 2 obs)
(format " since Emacs %s" (nth 2 obs))
""))))
;; Optimization: if the theme changes the `default' face, put that
;; entry first. This avoids some `frame-set-background-mode' rigmarole
;; by assigning the new background immediately.
(let* ((settings (get theme 'theme-settings))
(tail settings)
found)
(while (and tail (not found))
(and (eq (nth 0 (car tail)) 'theme-face)
(eq (nth 1 (car tail)) 'default)
(setq found (car tail)))
(setq tail (cdr tail)))
(when found
(put theme 'theme-settings (cons found (delq found settings)))))
;; Finally, enable the theme.
(unless no-enable
(enable-theme theme))
t)