Emacs - random color theme every hour?
Asked Answered
A

3

10

I know that to (funcall (car (nth (random (length color-themes)) color-themes))) gives me a random color theme on every Emacs startup; but I hardly restart Emacs. How do I cycle between random color themes, say, every hour?

Aruspex answered 13/8, 2010 at 23:37 Comment(1)
This sounds horrendous :) Is the idea to randomly select colour schemes until you stumble upon one that you want to keep?Leavings
A
9
(defun random-color-theme ()
  (interactive)
  (random t)
  (funcall (car (nth (random (length color-themes)) color-themes))))

(random-color-theme)

(run-with-timer 1 (* 60 60) 'random-color-theme)

Credit goes to ggole @ #emacs (freenode); and aecrvol (below) for the (random t) tip.

Aruspex answered 13/8, 2010 at 23:50 Comment(1)
I am getting an error void variable color-themes. What should I do as prerequisite?Intrastate
B
3

A little improvment: adding to the function (random t), otherwise generated sequence will be the same in each Emacs run ( from http://www.gnu.org/software/emacs/elisp/html_node/Random-Numbers.html).

(defun random-color-theme ()
  (interactive)
  (random t)  ; randomazing
  (funcall (car (nth (random (length color-themes)) color-themes))))
Badge answered 30/8, 2010 at 17:47 Comment(0)
C
1

Here is my update:

(setq color-themes (custom-available-themes))

(defun random-color-theme ()
  (interactive)
  (random t)
  (load-theme
   (nth (random (length color-themes)) color-themes)
   t))


(random-color-theme)

(run-with-timer 1 (* 60 60) 'random-color-theme)
Casavant answered 5/12, 2018 at 20:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.