Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs - random color theme every hour?

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?

like image 706
Sridhar Ratnakumar Avatar asked Aug 13 '10 23:08

Sridhar Ratnakumar


3 Answers

(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.

like image 186
Sridhar Ratnakumar Avatar answered Oct 07 '22 15:10

Sridhar Ratnakumar


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))))
like image 31
aecrvol Avatar answered Oct 07 '22 13:10

aecrvol


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)
like image 37
Terrence Brannon Avatar answered Oct 07 '22 14:10

Terrence Brannon