我知道每次启动Emacs时,(funcall (car (nth (random (length color-themes)) color-themes)))
会给我一个随机颜色主题;但我几乎不重启Emacs。我该如何在随机颜色主题之间循环,比如每小时更换一次?
我知道每次启动Emacs时,(funcall (car (nth (random (length color-themes)) color-themes)))
会给我一个随机颜色主题;但我几乎不重启Emacs。我该如何在随机颜色主题之间循环,比如每小时更换一次?
(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)
感谢 #emacs (freenode) 的 ggole
和下面的 aecrvol
提供了 (random t)
技巧。
void variable color-themes
。在此之前,我应该做些什么准备工作? - jdhao(random t)
中添加参数,否则生成的序列将在每次Emacs运行中相同(参考自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))))
(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)