From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Caio Henrique Newsgroups: gmane.emacs.devel Subject: Re: toggle-light-dark-mode Date: Tue, 15 Sep 2020 14:51:05 -0300 Message-ID: <871rj30vzq.fsf@gmail.com> References: <20200910102000.2t6tsju745xutg7u@Ergus> <20200910110832.ko66gqnqo4l664d6@Ergus> <20200911134225.zhnlq7cdhmu2iraj@Ergus> <20200911221435.go7b5kz2zcvxp2ft@Ergus> <20200912153723.ymnq3i5pugqf7lsy@Ergus> <20200912194652.nrcx2fjg7n4j54ns@Ergus> <87blia32b7.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8183"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: spacibba@aol.com, casouri@gmail.com, emacs-devel@gnu.org, monnier@iro.umontreal.ca, ghe@sdf.org, Caio Henrique , tecosaur@gmail.com To: ams@gnu.org (Alfred M. Szmidt) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 15 19:57:41 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIFD3-0001yY-JD for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Sep 2020 19:57:41 +0200 Original-Received: from localhost ([::1]:60834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIFD2-0001PO-LM for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Sep 2020 13:57:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIF75-0000q6-2e for emacs-devel@gnu.org; Tue, 15 Sep 2020 13:51:31 -0400 Original-Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:38142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kIF72-00085Q-QG; Tue, 15 Sep 2020 13:51:30 -0400 Original-Received: by mail-qv1-xf42.google.com with SMTP id p15so2146331qvk.5; Tue, 15 Sep 2020 10:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ezcdqOtydnnXqQieYnvuqgEdklXIYzcouFvBaZbGSSU=; b=adnLXBzgRenUU5t0D9PFaHZVcXsRuBAEK5U4TlerXtp4pO9JO4YUXx2nlLa68XnEA1 KDMxiWC+M7Z5c7FWd8wG7/H4wBkzV9JA1kC4FEQyNjrp4eMBLD4bb34Ee+tnxIDPkGfg TVUg7RqwRX29taV7fyfcAb0juTZZRQgnis1s3dZKwvIyRErjrCAQPXeYYZMB4Z1t7qfS nuy02gZW+1J+OQc4MnoRAkZQ+7yXvubePsJrKp9WW78avSc8Popc2hmrVkArRQx14G64 1nQsAMvVkyBG67fDGeY/5ipMtITy7VSfzWO0aN5aFXfioAbGfkeQ4yvwu8/ff5wCfPhd abZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=ezcdqOtydnnXqQieYnvuqgEdklXIYzcouFvBaZbGSSU=; b=RKkuBDWPu4E9VOVX9JPfvmzD7h1eajE6quJb+LMczXzfkFQqv8HcNdv2k+RAIO8BdD 0hr9Her3ODXoZfJ6Pa7bvUopZ37KpAlQx5UJIv1a5vZfXOEhsoTy1HCVH/LT8XtK5o+C XlXoVeI1n/3/+gaYTiETCMy3U76BKcVfuCmEoXwaK95Sukd7ZlxWYi9YeCAsUAVvbHAM sbrC4eT6YS6Nhc+vdEPWx0tF1iGanRz0uKtjJBIzEiAM1BXefGgMoa0ohTB9DZUDWBg7 KTUHeAqcKan1yQ7ui1p+WdIcT2/ski6owsyK4fvdGK73A7A9LhH5YrGJHYsm09J5c01S 7E1w== X-Gm-Message-State: AOAM531Zgs/RG3ELb/mGrmCWebaGYmHZPXWBDqOi25Uz7VAHLgAtKUWu 9plvjFA+yw3jgcGVUINCaWw= X-Google-Smtp-Source: ABdhPJxasGgvMSvRbjxk+Q3V5ZRh7R1o3gvUbcS9ISVSUbOK5nFITWBS2SJ1fRsPdxXx2v9YaV1hOQ== X-Received: by 2002:a0c:b251:: with SMTP id k17mr2988649qve.53.1600192286819; Tue, 15 Sep 2020 10:51:26 -0700 (PDT) Original-Received: from localhost.localdomain ([181.223.151.236]) by smtp.gmail.com with ESMTPSA id c70sm4407146qkg.4.2020.09.15.10.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 10:51:26 -0700 (PDT) X-Google-Original-From: Caio Henrique In-Reply-To: (Alfred M. Szmidt's message of "Tue, 15 Sep 2020 02:54:40 -0400") Received-SPF: pass client-ip=2607:f8b0:4864:20::f42; envelope-from=caiohcs0@gmail.com; helo=mail-qv1-xf42.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:255777 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=toggle-light-dark-theme.patch Content-Description: Add toggle light dark theme 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 --=-=-=--