-
Notifications
You must be signed in to change notification settings - Fork 2
/
heaven-and-hell.el
95 lines (82 loc) · 3.55 KB
/
heaven-and-hell.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;; heaven-and-hell.el --- easy toggle light/dark themes -*- lexical-binding: t; -*-
;; Copyright (C) 2018 by Valentin Ignatev and contributors
;; Author: Valentin Ignatev <valentignatev@gmail.com>
;; URL: https://github.com/valignatev/heaven-and-hell
;; Version: 0.0.1
;; Package-Requires: ((emacs "24.4"))
;; Keywords: faces
;;; Commentary:
;; Light themes are easier on the eyes when sun is up.
;; But when it's dark around - you better to use dark theme.
;; This package makes process of switching between light and dark
;; theme as easy as hitting single keystroke.
;; Features:
;; * Define your favorite light and dark themes
;; * Choose which one to run by default
;; * Switch between them with a single keypress
;; * Easily roll back to default Emacs theme in case of messed faces
;;
;; Example configuration:
;; Default is 'light
;; (setq heaven-and-hell-theme-type 'dark)
;;
;; Set preferred light and dark themes (it can be a list of themes as well)
;; Default light is Emacs default theme, default dark is wombat
;; (setq heaven-and-hell-themes
;; '((light . tsdh-light)
;; (dark . (tsdh-dark wombat))))
;; If you want to load themes without manually confirming them, you can do
;; (setq heaven-and-hell-load-theme-no-confirm t)
;;
;; Add init-hook so heaven-and-hell can load your theme
;; (add-hook 'after-init-hook 'heaven-and-hell-init-hook)
;;
;; Set keys to toggle theme and return to default Emacs theme
;; (global-set-key (kbd "C-c <f6>") 'heaven-and-hell-load-default-theme)
;; (global-set-key (kbd "<f6>") 'heaven-and-hell-toggle-theme)
;;; Code:
(defvar heaven-and-hell-themes
'((light . nil)
(dark . wombat))
"Associate light and dark theme with this variable.
Theme can be the list.")
(defvar heaven-and-hell-theme-type 'light
"Set default theme, either `light' or `dark'.")
(defvar heaven-and-hell-load-theme-no-confirm nil
"Call `'load-theme with NO-CONFIRM if non-nil.")
(defun heaven-and-hell-themes-switch-to ()
"Return themes which should be loaded according to current `heaven-and-hell-theme-type'."
(cdr (assoc heaven-and-hell-theme-type heaven-and-hell-themes)))
(defun heaven-and-hell-clean-load-themes (theme-or-themes)
"Load themes if they're not loaded yet and enable them cleanly.
Cleanly means that it disables all custom themes before enabling new ones.
THEME-OR-THEMES can be single theme or list of themes.
Themes will be loaded if they weren't loaded previously."
(heaven-and-hell-load-default-theme)
(when theme-or-themes
(let ((themes (if (listp theme-or-themes) theme-or-themes `(,theme-or-themes))))
(dolist (theme themes)
(when heaven-and-hell-load-theme-no-confirm
(load-theme theme t t)))
(custom-set-variables `(custom-enabled-themes (quote ,themes))))))
;;;###autoload
(defun heaven-and-hell-toggle-theme ()
"If `heaven-and-hell-theme-type' is `light' - load dark theme/s.
And vise-versa."
(interactive)
(if (eq heaven-and-hell-theme-type 'light)
(setq heaven-and-hell-theme-type 'dark)
(setq heaven-and-hell-theme-type 'light))
(heaven-and-hell-clean-load-themes (heaven-and-hell-themes-switch-to)))
;;;###autoload
(defun heaven-and-hell-load-default-theme ()
"Disable all custom themes e.g. load default Emacs theme."
(interactive)
(custom-set-variables '(custom-enabled-themes nil)))
;;;###autoload
(defun heaven-and-hell-init-hook ()
"Add this to `after-init-hook' so it can load your theme/s of choice correctly."
(interactive)
(heaven-and-hell-clean-load-themes (heaven-and-hell-themes-switch-to)))
(provide 'heaven-and-hell)
;;; heaven-and-hell.el ends here