From: Caio Henrique <caiohcs0@gmail.com>
To: ams@gnu.org (Alfred M. Szmidt)
Cc: spacibba@aol.com, casouri@gmail.com, emacs-devel@gnu.org,
monnier@iro.umontreal.ca, ghe@sdf.org,
Caio Henrique <caio.hcs0@gmail.com>,
tecosaur@gmail.com
Subject: Re: toggle-light-dark-mode
Date: Tue, 15 Sep 2020 14:51:05 -0300 [thread overview]
Message-ID: <871rj30vzq.fsf@gmail.com> (raw)
In-Reply-To: <E1kI4rQ-0006po-0Y@fencepost.gnu.org> (Alfred M. Szmidt's message of "Tue, 15 Sep 2020 02:54:40 -0400")
[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]
ams@gnu.org (Alfred M. Szmidt) writes:
> [Tip, it is a good idea to change the subject!]
>
> I like using a light theme during the day and a dark theme during the
> night when I'm in a dark room. I use a function to toggle between those
> two different themes. Here is some code based on my personal
> configuration:
>
> _____
> [ ... ]
> _____
>
> Maybe we could use something like this and then add buttons to the menu
> and the tool bar? The tool bar could use an icon like the image
> attached (the image is just illustrative, it probably has copyright).
>
> This looks like a good idea.
>
> I think something in the tool-bar is a bit much, I don't think it is
> the most used option that should that have such a high visibility --
> rather I think users would like to toggle it once, so the menu-bar
> would be a better place where the user would also be prompt to save
> their settings if they quit emacs.
>
> Would you like to purpose a patch for this?
Ok, I tried to improve that code, a patch is attached.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Add toggle light dark theme --]
[-- Type: text/x-patch, Size: 3653 bytes --]
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 <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
next prev parent reply other threads:[~2020-09-15 17:51 UTC|newest]
Thread overview: 264+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-08 16:02 Changes for emacs 28 TEC
2020-09-08 17:01 ` Yuan Fu
2020-09-08 17:45 ` TEC
2020-09-08 18:15 ` TEC
2020-09-08 19:28 ` tomas
2020-09-08 20:31 ` Ergus
2020-09-08 21:01 ` Stefan Kangas
2020-09-08 21:45 ` Ergus
2020-09-08 22:14 ` Stefan Kangas
2020-09-08 22:26 ` Ergus
2020-09-08 21:35 ` Daniel Martín
2020-09-09 16:05 ` Stefan Monnier
2020-09-09 16:22 ` T.V Raman
2020-09-09 16:45 ` TEC
2020-09-09 18:35 ` Stefan Monnier
2020-09-10 10:47 ` Göktuğ Kayaalp
2020-09-10 17:39 ` Drew Adams
2020-09-10 17:56 ` Yuri Khan
2020-09-10 18:21 ` Eli Zaretskii
2020-09-10 19:48 ` Ricardo Wurmus
2020-09-11 5:43 ` Eli Zaretskii
2020-09-10 21:01 ` Göktuğ Kayaalp
2020-09-10 21:21 ` Gregory Heytings via Emacs development discussions.
2020-09-10 21:34 ` Ricardo Wurmus
2020-09-10 21:36 ` Gregory Heytings via Emacs development discussions.
2020-09-10 22:19 ` Drew Adams
2020-09-10 21:46 ` Stefan Kangas
2020-09-11 4:16 ` Richard Stallman
2020-09-11 7:04 ` Philip K.
2020-09-11 7:12 ` Eli Zaretskii
2020-09-11 7:44 ` tomas
2020-09-11 10:27 ` Arthur Miller
2020-09-11 12:26 ` tomas
2020-09-11 15:19 ` Arthur Miller
2020-09-11 10:50 ` Göktuğ Kayaalp
2020-09-13 8:41 ` Juri Linkov
2020-09-13 10:30 ` tomas
2020-09-13 10:59 ` Göktuğ Kayaalp
2020-09-13 11:38 ` tomas
2020-09-13 12:53 ` Ergus
2020-09-13 15:05 ` Göktuğ Kayaalp
2020-09-13 16:17 ` Ergus
2020-09-13 16:38 ` Göktuğ Kayaalp
2020-09-13 12:15 ` Arthur Miller
2020-09-13 12:40 ` tomas
2020-09-14 18:45 ` chad
2020-09-15 8:12 ` tomas
2020-09-15 18:27 ` Dmitry Gutov
2020-09-15 21:17 ` tomas
2020-09-15 20:45 ` Gregory Heytings via Emacs development discussions.
2020-09-15 21:22 ` tomas
2020-09-15 23:32 ` Alan Third
2020-09-13 14:29 ` Eli Zaretskii
2020-09-13 18:05 ` Juri Linkov
2020-09-13 18:26 ` Eli Zaretskii
2020-09-13 19:17 ` Juri Linkov
2020-09-13 19:28 ` Eli Zaretskii
2020-09-11 10:30 ` Ergus
2020-09-12 3:21 ` Richard Stallman
2020-09-12 3:36 ` Ergus
2020-09-13 8:45 ` Juri Linkov
2020-09-11 19:17 ` Drew Adams
2020-09-12 3:21 ` Richard Stallman
2020-09-11 8:59 ` Dmitry Gutov
2020-09-11 11:00 ` Arthur Miller
2020-09-11 12:50 ` Dmitry Gutov
2020-09-11 13:23 ` Ergus
2020-09-11 18:29 ` Drew Adams
2020-09-11 19:12 ` Ergus
2020-09-11 19:23 ` Drew Adams
2020-09-11 20:07 ` Ergus
2020-09-11 20:37 ` Drew Adams
2020-09-13 3:59 ` Richard Stallman
2020-09-11 21:07 ` Dmitry Gutov
2020-09-12 12:40 ` Arthur Miller
2020-09-12 16:28 ` Drew Adams
2020-09-12 12:24 ` Arthur Miller
2020-09-10 22:48 ` Caio Henrique
2020-09-12 3:20 ` Richard Stallman
2020-09-12 4:07 ` Caio Henrique
2020-09-11 4:16 ` Richard Stallman
2020-09-11 9:49 ` Göktuğ Kayaalp
2020-09-11 9:53 ` Lars Ingebrigtsen
2020-09-11 21:51 ` Stefan Kangas
2020-09-11 17:53 ` Drew Adams
2020-09-11 19:09 ` Stefan Kangas
2020-09-11 21:05 ` Göktuğ Kayaalp
2020-09-11 21:40 ` Stefan Kangas
2020-09-12 7:54 ` Göktuğ Kayaalp
2020-09-11 6:01 ` Eli Zaretskii
2020-09-11 9:04 ` Dmitry Gutov
2020-09-11 9:19 ` Gregory Heytings via Emacs development discussions.
2020-09-11 13:52 ` Robert Pluim
2020-09-11 14:10 ` Gregory Heytings via Emacs development discussions.
2020-09-11 14:26 ` Robert Pluim
2020-09-11 10:36 ` Arthur Miller
2020-09-11 10:39 ` Göktuğ Kayaalp
2020-09-11 11:20 ` Arthur Miller
2020-09-12 3:21 ` Richard Stallman
2020-09-12 7:49 ` Göktuğ Kayaalp
2020-09-13 4:07 ` Richard Stallman
2020-09-11 20:24 ` Dmitry Gutov
2020-09-11 19:17 ` Drew Adams
2020-09-10 18:44 ` Drew Adams
2020-09-10 19:34 ` Yuri Khan
2020-09-11 4:16 ` Richard Stallman
2020-09-11 5:11 ` Yuri Khan
2020-09-11 5:40 ` Eli Zaretskii
2020-09-11 4:16 ` Richard Stallman
2020-09-10 18:12 ` Juri Linkov
2020-09-09 19:28 ` tomas
2020-09-09 21:33 ` Howard Melman
2020-09-09 22:19 ` Drew Adams
2020-09-10 11:20 ` Ricardo Wurmus
2020-09-10 11:27 ` Göktuğ Kayaalp
2020-09-10 11:57 ` Ricardo Wurmus
2020-09-11 4:16 ` Richard Stallman
2020-09-11 4:52 ` Ricardo Wurmus
2020-09-11 6:07 ` TEC
2020-09-12 3:21 ` Richard Stallman
2020-09-12 3:21 ` Richard Stallman
2020-09-11 4:13 ` Richard Stallman
2020-09-11 4:14 ` Richard Stallman
2020-09-09 16:57 ` Ergus
2020-09-09 17:08 ` Gregory Heytings via Emacs development discussions.
2020-09-09 17:16 ` Ergus
2020-09-09 17:25 ` Drew Adams
2020-09-09 17:34 ` Caio Henrique
2020-09-10 9:09 ` "modern" colors " Alfred M. Szmidt
2020-09-10 10:20 ` Ergus
2020-09-10 10:29 ` Alfred M. Szmidt
2020-09-10 10:43 ` Eli Zaretskii
2020-09-10 11:08 ` Ergus
2020-09-10 12:32 ` Eli Zaretskii
2020-09-10 13:17 ` Ergus
2020-09-10 13:55 ` Yuri Khan
2020-09-10 14:41 ` Eli Zaretskii
2020-09-10 18:40 ` Ergus
2020-09-10 18:50 ` Eli Zaretskii
2020-09-10 18:58 ` Ergus
2020-09-11 13:15 ` Alfred M. Szmidt
2020-09-11 13:42 ` Ergus
2020-09-11 14:13 ` Alfred M. Szmidt
2020-09-11 14:23 ` Stefan Monnier
2020-09-11 14:36 ` Iñigo Serna
2020-09-11 22:14 ` Ergus
2020-09-12 6:25 ` Eli Zaretskii
2020-09-12 9:03 ` Ergus
2020-09-12 9:25 ` Eli Zaretskii
2020-09-12 10:19 ` Ergus
2020-09-12 17:02 ` Alfred M. Szmidt
2020-09-13 5:51 ` Thibaut Verron
2020-09-13 14:21 ` Eli Zaretskii
2020-09-13 18:40 ` Thibaut Verron
2020-09-13 4:06 ` Richard Stallman
2020-09-12 11:24 ` Yuri Khan
2020-09-12 11:32 ` Eli Zaretskii
2020-09-12 12:41 ` Ergus
2020-09-12 16:29 ` Drew Adams
2020-09-12 15:36 ` Stefan Monnier
2020-09-12 15:43 ` Ergus
2020-09-12 17:25 ` Stefan Monnier
2020-09-13 4:06 ` Richard Stallman
2020-09-13 8:53 ` Göktuğ Kayaalp
2020-09-14 3:50 ` Richard Stallman
2020-09-14 8:08 ` Göktuğ Kayaalp
2020-09-14 9:46 ` Ergus
2020-09-14 15:14 ` Eli Zaretskii
2020-09-14 15:48 ` Drew Adams
2020-09-12 15:33 ` Stefan Monnier
2020-09-12 10:13 ` Iñigo Serna
2020-09-12 11:13 ` Yuri Khan
2020-09-12 12:26 ` Ergus
2020-09-12 16:27 ` Drew Adams
2020-09-12 14:52 ` Alfred M. Szmidt
2020-09-12 15:37 ` Ergus
2020-09-12 17:02 ` Alfred M. Szmidt
2020-09-12 17:26 ` TEC
[not found] ` <87o8maj1kh.fsf@gmail.com>
2020-09-12 18:27 ` TEC
2020-09-12 19:57 ` Ergus
2020-09-13 5:53 ` TEC
2020-09-12 21:22 ` Alfred M. Szmidt
2020-09-13 5:49 ` TEC
2020-09-15 6:54 ` Alfred M. Szmidt
2020-09-16 2:49 ` TEC
2020-09-13 8:00 ` Göktuğ Kayaalp
2020-09-13 9:04 ` Gregory Heytings via Emacs development discussions.
2020-09-13 10:17 ` Göktuğ Kayaalp
2020-09-13 14:26 ` Gregory Heytings via Emacs development discussions.
2020-09-13 14:43 ` Göktuğ Kayaalp
2020-09-13 15:22 ` Stefan Kangas
2020-09-13 9:16 ` Colin Baxter
2020-09-12 19:46 ` Ergus
2020-09-12 21:22 ` Drew Adams
2020-09-12 21:22 ` Alfred M. Szmidt
2020-09-13 1:14 ` Caio Henrique
2020-09-15 6:54 ` toggle-light-dark-mode (was: Re: "modern" colors Re: Changes for emacs 28) Alfred M. Szmidt
2020-09-15 17:51 ` Caio Henrique [this message]
2020-09-15 19:03 ` toggle-light-dark-mode Juri Linkov
2020-09-15 20:10 ` toggle-light-dark-mode Caio Henrique
2020-09-16 19:31 ` toggle-light-dark-mode Juri Linkov
2020-09-16 20:14 ` toggle-light-dark-mode Protesilaos Stavrou
2020-09-16 20:32 ` toggle-light-dark-mode Juri Linkov
2020-09-16 20:59 ` toggle-light-dark-mode Stefan Monnier
2020-09-17 14:34 ` toggle-light-dark-mode Arthur Miller
2020-09-12 17:43 ` "modern" colors Re: Changes for emacs 28 Ricardo Wurmus
2020-09-12 19:53 ` Ergus
2020-09-12 19:59 ` Caio Henrique
2020-09-12 20:09 ` Ergus
2020-09-13 8:07 ` Göktuğ Kayaalp
2020-09-12 20:13 ` Ricardo Wurmus
2020-09-13 15:09 ` Eli Zaretskii
2020-09-13 16:22 ` Ricardo Wurmus
2020-09-13 16:45 ` Eli Zaretskii
2020-09-13 19:49 ` Ricardo Wurmus
2020-09-13 20:16 ` Stefan Monnier
2020-09-13 21:43 ` Ricardo Wurmus
2020-09-13 21:45 ` Ergus
2020-09-13 22:18 ` Stefan Monnier
2020-09-13 22:26 ` Lars Ingebrigtsen
2020-09-13 21:45 ` Ergus
2020-09-13 22:16 ` Stefan Monnier
2020-09-13 22:24 ` Stefan Monnier
2020-09-14 14:44 ` Eli Zaretskii
2020-09-14 16:45 ` Ricardo Wurmus
2020-09-14 17:15 ` Stefan Monnier
2020-09-14 17:29 ` Eli Zaretskii
2020-09-14 19:47 ` Ricardo Wurmus
2020-09-14 20:20 ` Stefan Monnier
2020-09-15 7:40 ` Robert Pluim
2020-09-15 14:34 ` Eli Zaretskii
2020-09-15 14:50 ` Robert Pluim
2020-09-15 15:51 ` Yuri Khan
2020-09-15 16:01 ` Göktuğ Kayaalp
2020-09-15 16:30 ` Göktuğ Kayaalp
2020-09-15 16:05 ` Robert Pluim
2020-09-15 16:30 ` Yuri Khan
2020-09-15 16:11 ` Eli Zaretskii
2020-09-15 16:31 ` Yuri Khan
2020-09-15 14:18 ` Eli Zaretskii
2020-09-14 14:39 ` Eli Zaretskii
2020-09-14 14:47 ` Robert Pluim
2020-09-14 16:07 ` Eli Zaretskii
2020-09-14 16:35 ` Robert Pluim
2020-09-14 14:38 ` Eli Zaretskii
2020-09-14 16:46 ` Ricardo Wurmus
2020-09-13 3:57 ` Richard Stallman
2020-09-13 3:57 ` Richard Stallman
2020-09-13 14:16 ` Eli Zaretskii
2020-09-15 6:54 ` Alfred M. Szmidt
2020-09-11 23:29 ` Philip K.
2020-09-12 11:10 ` Göktuğ Kayaalp
2020-09-12 11:44 ` Dmitry Gutov
2020-09-12 12:46 ` Ergus
2020-09-12 16:24 ` Drew Adams
2020-09-12 13:16 ` Arthur Miller
2020-09-12 13:55 ` Ricardo Wurmus
2020-09-12 14:31 ` Arthur Miller
2020-09-13 0:17 ` Dmitry Gutov
2020-09-12 14:52 ` Alfred M. Szmidt
2020-09-13 0:44 ` Dmitry Gutov
2020-09-09 3:46 ` Richard Stallman
2020-09-09 6:26 ` TEC
2020-09-09 15:43 ` Göktuğ Kayaalp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871rj30vzq.fsf@gmail.com \
--to=caiohcs0@gmail.com \
--cc=ams@gnu.org \
--cc=caio.hcs0@gmail.com \
--cc=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=ghe@sdf.org \
--cc=monnier@iro.umontreal.ca \
--cc=spacibba@aol.com \
--cc=tecosaur@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).