Skip to content

Instantly share code, notes, and snippets.

@karls
Created November 29, 2015 12:41
Show Gist options
  • Save karls/9d0d5e25cd72d633893f to your computer and use it in GitHub Desktop.
Save karls/9d0d5e25cd72d633893f to your computer and use it in GitHub Desktop.
Quick hack for cycling themes in Emacs
;; Theme cycling.
;; NOTE: themes have to exist somewhere on disk, e.g in ~/.emacs.d/themes/
;; Set it with (setq custom-theme-directory "~/.emacs.d/themes/")
(defvar current-theme-index 0)
(defvar theme-list
'(solarized-dark solarized-light)
"List of themes to cycle through.")
(defun get-theme-name (idx)
(nth idx theme-list))
(defun cycle-themes ()
(interactive)
(let* ((theme (get-theme-name current-theme-index))
(next-theme-index (mod (+ 1 current-theme-index) (length theme-list)))
(next-theme (get-theme-name next-theme-index)))
(disable-theme theme)
(setq current-theme-index next-theme-index)
(load-theme next-theme)))
(when window-system
(global-set-key (kbd "<f5>") 'cycle-themes)
(load-theme (get-theme-name 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment