Add ef-themes-load-random command

This commit is contained in:
Protesilaos Stavrou 2022-08-17 06:01:05 +03:00
parent 23b342f06a
commit e15123e1dc
No known key found for this signature in database
GPG Key ID: 99BD6459CD5CA3EA
2 changed files with 18 additions and 0 deletions

View File

@ -139,6 +139,7 @@ Everything is in place to set up the package.
;; We also provide these commands, but do not assign them to any key:
;;
;; - `ef-themes-select'
;; - `ef-themes-load-random'
;; - `ef-themes-preview-colors'
;; - `ef-themes-preview-colors-current'
#+end_src

View File

@ -97,6 +97,23 @@ When called from Lisp, THEME is a symbol."
(mapc #'disable-theme (ef-themes--list-known-themes))
(load-theme theme :no-confirm))
(defun ef-themes--minus-current ()
"Return list of Ef themes minus the current one."
(let* ((themes (copy-sequence (ef-themes--list-known-themes))))
(delete (ef-themes--current-theme) themes)))
;;;###autoload
(defun ef-themes-load-random ()
"Load an Ef theme at random, excluding the current one."
(interactive)
(let* ((themes (ef-themes--minus-current))
(n (random (length themes)))
(pick (nth n themes)))
(mapc #'disable-theme (ef-themes--list-known-themes))
(if (null pick)
(load-theme (car themes) :no-confim)
(load-theme pick :no-confim))))
(defun ef-themes--preview-colors-render (buffer theme &rest _)
"Render colors in BUFFER from THEME.
Routine for `ef-themes-preview-colors'."