;;; toggle-light-dark-theme.el -- Toggle dark and light theme -*- lexical-binding: t -*- ;; ;; Copyright (C) 2020 Free Software Foundation, Inc. ;; ;; Author: Caio Henrique ;; 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 . ;;; 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