diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index ef04689f4c..243f0db151 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -645,6 +645,9 @@ menu-bar-custom-menu (bindings--define-key menu [customize] '(menu-item "Top-level Customization Group" customize :help "The master group called `Emacs'")) + (bindings--define-key menu [toggle-light-dark-theme] + '(menu-item "Toggle Light Dark Theme" toggle-light-dark-theme + :help "Toggle light dark theme")) (bindings--define-key menu [customize-themes] '(menu-item "Custom Themes" customize-themes :help "Choose a pre-defined customization theme")) diff --git a/lisp/toggle-light-dark-theme.el b/lisp/toggle-light-dark-theme.el new file mode 100644 index 0000000000..29966c7c9b --- /dev/null +++ b/lisp/toggle-light-dark-theme.el @@ -0,0 +1,73 @@ +;;; 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