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
| | ;;; toggle-light-dark-theme.el -- Toggle dark and light theme -*- lexical-binding: t -*-
;;
;; Copyright (C) 2020 Free Software Foundation, Inc.
;;
;; Author: Caio Henrique <caio.hcs0@gmail.com>
;; Maintainer: emacs-devel@gnu.org
;; Keywords: faces
;; Package: emacs
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides a function to toggle between a light and a dark
;; theme, the two themes can be specified with customize-option, the
;; function is added to the menu bar.
;;; Code:
(defgroup toggle-light-dark-theme nil
"Toggle light dark theme"
:group 'faces)
(defun toggle-light-dark-theme--custom-choices (theme)
"Used to create the choice widget options of the
toggle-light-dark-theme custom variables."
`(const :tag ,(symbol-name theme) ,theme))
(defcustom toggle-light-dark-theme-light-theme 'modus-operandi
"The light theme used by the function `toggle-light-dark-theme'."
:group 'toggle-light-dark-theme
:type `(choice ,@(mapcar #'toggle-light-dark-theme--custom-choices
(custom-available-themes))))
(defcustom toggle-light-dark-theme-dark-theme 'tango-dark
"The dark theme used by the function `toggle-light-dark-theme'."
:group 'toggle-light-dark-theme
:type `(choice ,@(mapcar #'toggle-light-dark-theme--custom-choices
(custom-available-themes))))
(defvar toggle-light-dark-theme--current-theme 'light)
;;;###autoload
(defun toggle-light-dark-theme ()
"Disables all custom enabled themes and then toggles between a
light and a dark theme, which are the values of the variables
`toggle-light-dark-theme-light-theme' and
`toggle-light-dark-theme-dark-theme'."
(interactive)
(mapc #'disable-theme custom-enabled-themes)
(cond ((eq toggle-light-dark-theme--current-theme 'light)
(load-theme toggle-light-dark-theme-dark-theme)
(setq toggle-light-dark-theme--current-theme 'dark))
(t
(load-theme toggle-light-dark-theme-light-theme)
(setq toggle-light-dark-theme--current-theme 'light))))
(provide 'toggle-light-dark-theme)
;;; toggle-light-dark-theme.el ends here
|