From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: toggle-light-dark-mode Date: Tue, 15 Sep 2020 22:03:20 +0300 Organization: LINKOV.NET Message-ID: <87d02mop87.fsf@mail.linkov.net> References: <20200910102000.2t6tsju745xutg7u@Ergus> <20200910110832.ko66gqnqo4l664d6@Ergus> <20200911134225.zhnlq7cdhmu2iraj@Ergus> <20200911221435.go7b5kz2zcvxp2ft@Ergus> <20200912153723.ymnq3i5pugqf7lsy@Ergus> <20200912194652.nrcx2fjg7n4j54ns@Ergus> <87blia32b7.fsf@gmail.com> <871rj30vzq.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6774"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: casouri@gmail.com, spacibba@aol.com, emacs-devel@gnu.org, "Alfred M. Szmidt" , monnier@iro.umontreal.ca, ghe@sdf.org, Caio Henrique , tecosaur@gmail.com To: Caio Henrique Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 15 21:33:52 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 1kIGi8-0001d7-1d for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Sep 2020 21:33:52 +0200 Original-Received: from localhost ([::1]:35680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIGi7-000671-0k for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Sep 2020 15:33:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIGhX-0005QW-Dy for emacs-devel@gnu.org; Tue, 15 Sep 2020 15:33:15 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:34561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIGhU-0004Q1-Rt; Tue, 15 Sep 2020 15:33:15 -0400 X-Originating-IP: 91.129.97.241 Original-Received: from mail.gandi.net (m91-129-97-241.cust.tele2.ee [91.129.97.241]) (Authenticated sender: juri@linkov.net) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 1C6551C0006; Tue, 15 Sep 2020 19:33:03 +0000 (UTC) In-Reply-To: <871rj30vzq.fsf@gmail.com> (Caio Henrique's message of "Tue, 15 Sep 2020 14:51:05 -0300") Received-SPF: pass client-ip=217.70.183.197; envelope-from=juri@linkov.net; helo=relay5-d.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 15:33:08 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001, 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:255784 Archived-At: >> [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. But the theme can be toggled from light to dark using the command line switch --reverse-video, -r, -rv, or with the frame parameter 'background-mode' that can be either 'dark' or 'light', and the user selected theme should support both modes. Then toggling can be automatic: (defvar my-sunset-timer nil) (defvar my-sunrise-timer nil) (defun toggle-light-dark-mode (&optional frame) "Automatically switch to dark background after sunset and to light background after sunrise. (Note that `calendar-latitude' and `calendar-longitude' should be set before calling the `solar-sunrise-sunset')." (interactive) (require 'solar) (if (and (bound-and-true-p calendar-latitude) (bound-and-true-p calendar-longitude) (bound-and-true-p calendar-time-zone)) (let* ((l (solar-sunrise-sunset (calendar-current-date))) (sunrise-string (apply 'solar-time-string (car l))) (sunset-string (apply 'solar-time-string (car (cdr l)))) (current-time-string (format-time-string "%H:%M"))) (if (or (string-lessp current-time-string sunrise-string) (string-lessp sunset-string current-time-string)) (toggle-dark-mode frame) (toggle-light-mode frame)) (if (and (boundp 'my-sunset-timer) (timerp my-sunset-timer)) (cancel-timer my-sunset-timer)) (if (and (boundp 'my-sunrise-timer) (timerp my-sunrise-timer)) (cancel-timer my-sunrise-timer)) (setq my-sunset-timer (run-at-time sunset-string (* 60 60 24) 'toggle-dark-mode)) (setq my-sunrise-timer (run-at-time sunrise-string (* 60 60 24) 'toggle-light-mode))))) (add-hook 'after-make-frame-functions 'toggle-light-dark-mode) (defun my-colors-light (&optional frame) "Set colors suitable for working in light environments, i.e. in daylight or under bright electric lamps." (interactive) (setq frame-background-mode 'light) (modify-frame-parameters nil (list (cons 'background-mode 'light))) ;; The color with minimal eye fatigue in light environments ;; is "AntiqueWhite3" (RGB: 205 192 176), ;; (set-background-color "AntiqueWhite3") ) (defun my-colors-dark (&optional frame) "Set colors suitable for working in the darkness without electricity." (interactive) (setq frame-background-mode 'dark) (modify-frame-parameters nil (list (cons 'background-mode 'dark))))