From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#57639: [PATCH] Add new command 'toggle-theme' Date: Wed, 07 Sep 2022 07:19:30 +0000 Message-ID: <875yhzmz25.fsf@posteo.net> 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="27168"; mail-complaints-to="usenet@ciao.gmane.io" To: 57639@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 07 09:21:00 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1oVpMp-0006nx-S5 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Sep 2022 09:21:00 +0200 Original-Received: from localhost ([::1]:38858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVpMn-0000Do-Ty for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Sep 2022 03:20:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVpLy-0000B6-0b for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2022 03:20:13 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVpLt-000660-Vz for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2022 03:20:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oVpLt-0008W5-Ol for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2022 03:20:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Sep 2022 07:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57639 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166253519032709 (code B ref -1); Wed, 07 Sep 2022 07:20:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Sep 2022 07:19:50 +0000 Original-Received: from localhost ([127.0.0.1]:53243 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oVpLi-0008VT-12 for submit@debbugs.gnu.org; Wed, 07 Sep 2022 03:19:50 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:59402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oVpLf-0008VE-FG for submit@debbugs.gnu.org; Wed, 07 Sep 2022 03:19:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVpLa-00004w-CV for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2022 03:19:45 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:33363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVpLX-000639-Lz for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2022 03:19:42 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 16E8824002A for ; Wed, 7 Sep 2022 09:19:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1662535177; bh=pZbeE2viNzs3FrR+80kOAyAzmB1HZjj2cYOO4rFTB0o=; h=From:To:Subject:Autocrypt:Date:From; b=mUxSt2LWxr5K+KGX5FgtRF1vauHd+9uAJV+hen20iU7CDz3Dw73/XNDFaO6PMIOSw dsQreAiRbVbi0hyhV1R+P3d4xHvQVNBzAbn1MYxeFEQarOtkQZdMwu12q635CDYrqg TVvCOF2aM2f2T9WT56afyurjm7aJ0sAHB/PgX1SHu7CUyrxT7iup+JrKvEU2TY+LQA 34zUxQC7qu3jmBO3g9Ubss2XLNhvT0tZtAAUN4lJscuOfFaTu5g36Q7ZhtmnCHiL5c 2xmw6zUZI79kx8Bq1YVWvmAHnKCewqhl3rVA8VY5niL8JTm9N+O0OnwoNI2ZowZqV5 kX5UPJXYrCSlA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MMttJ3P7Bz6tm9 for ; Wed, 7 Sep 2022 09:19:36 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:241728 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Find below a patch for a command that a lot of custom themes re-implement, whenever there exists a light and dark variant. In GNU Emacs 29.0.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.17.6) of 2022-09-03 built on rhea Repository revision: 2763a516a048c2cbabb10a5bbe22dc3bbde561f3 Repository branch: master System Description: Fedora Linux 36 (Workstation Edition) Configured using: 'configure --with-pgtk --with-native-compilation --with-imagemagick' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-new-command-toggle-theme.patch >From 2f27885460095a247421431faca14bf35fae3995 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 6 Sep 2022 20:53:35 +0200 Subject: [PATCH 1/2] Add new command 'toggle-theme' * doc/emacs/custom.texi (Custom Themes): Mention it. * etc/themes/leuven-dark-theme.el (leuven-dark): Add dual theme. * etc/themes/leuven-theme.el (leuven): Add dual theme. * etc/themes/tango-dark-theme.el (tango-dark): Add dual theme. * etc/themes/tango-theme.el (tango): Add dual theme. * etc/themes/tsdh-dark-theme.el (tsdh-dark): Add dual theme. * etc/themes/tsdh-light-theme.el (tsdh-light): Add dual theme. * lisp/cus-theme.el (describe-theme-1): Say if a theme has a dual. * lisp/custom.el (toggle-theme): Add new command. --- doc/emacs/custom.texi | 5 +++++ etc/themes/leuven-dark-theme.el | 4 +++- etc/themes/leuven-theme.el | 4 +++- etc/themes/tango-dark-theme.el | 2 ++ etc/themes/tango-theme.el | 2 ++ etc/themes/tsdh-dark-theme.el | 2 ++ etc/themes/tsdh-light-theme.el | 2 ++ lisp/cus-theme.el | 2 ++ lisp/custom.el | 19 +++++++++++++++++++ 9 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index ff7ab83190..3dabba9d2f 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -667,6 +667,11 @@ Custom Themes the @file{*Custom Themes*} buffer; or type @kbd{M-x describe-theme} anywhere in Emacs and enter the theme name. +@findex toggle-theme + Some themes have dual variants (most often these are light and dark +pairs). You can switch between these by typing @kbd{M-x +toggle-theme}. Note that this only works if only one theme is active. + @node Creating Custom Themes @subsection Creating Custom Themes @cindex custom themes, creating diff --git a/etc/themes/leuven-dark-theme.el b/etc/themes/leuven-dark-theme.el index 0e162c8bab..cef40782c1 100644 --- a/etc/themes/leuven-dark-theme.el +++ b/etc/themes/leuven-dark-theme.el @@ -5,7 +5,7 @@ ;; Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")> ;; Contributor: Thibault Polge <(concat "thibault" at-sign "thb.lt")> ;; URL: https://github.com/fniessen/emacs-leuven-dark-theme -;; Version: 20220202.1126 +;; Version: 20220906.2016 ;; Keywords: color theme ;; This file is part of GNU Emacs. @@ -1083,6 +1083,8 @@ leuven-dark (add-to-list 'custom-theme-load-path (file-name-as-directory (file-name-directory load-file-name)))) +(put 'leuven-dark 'dual-theme 'leuven) ;see `toggle-theme' + (provide-theme 'leuven-dark) ;; This is for the sake of Emacs. diff --git a/etc/themes/leuven-theme.el b/etc/themes/leuven-theme.el index d9a8d5391a..73ac96d28d 100644 --- a/etc/themes/leuven-theme.el +++ b/etc/themes/leuven-theme.el @@ -4,7 +4,7 @@ ;; Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")> ;; URL: https://github.com/fniessen/emacs-leuven-theme -;; Version: 20200513.1928 +;; Version: 20220906.2016 ;; Keywords: color theme ;; This file is part of GNU Emacs. @@ -1065,6 +1065,8 @@ leuven (add-to-list 'custom-theme-load-path (file-name-as-directory (file-name-directory load-file-name)))) +(put 'leuven 'dual-theme 'leuven-dark) ;see `toggle-theme' + (provide-theme 'leuven) ;; This is for the sake of Emacs. diff --git a/etc/themes/tango-dark-theme.el b/etc/themes/tango-dark-theme.el index ef00d2ac49..f9f2692ac5 100644 --- a/etc/themes/tango-dark-theme.el +++ b/etc/themes/tango-dark-theme.el @@ -190,6 +190,8 @@ tango-dark `(ansi-color-bright-white ((,class (:background ,alum-1 :foreground ,alum-1)))))) +(put 'tango-dark 'dual-theme 'tango) ;see `toggle-theme' + (provide-theme 'tango-dark) ;;; tango-dark-theme.el ends here diff --git a/etc/themes/tango-theme.el b/etc/themes/tango-theme.el index ecbbf03753..8d1686f05e 100644 --- a/etc/themes/tango-theme.el +++ b/etc/themes/tango-theme.el @@ -173,6 +173,8 @@ tango `(ansi-color-bright-white ((,class (:background ,alum-1 :foreground ,alum-1)))))) +(put 'tango 'dual-theme 'tango-dark) ;see `toggle-theme' + (provide-theme 'tango) ;;; tango-theme.el ends here diff --git a/etc/themes/tsdh-dark-theme.el b/etc/themes/tsdh-dark-theme.el index a88ad75520..ad54eb3df0 100644 --- a/etc/themes/tsdh-dark-theme.el +++ b/etc/themes/tsdh-dark-theme.el @@ -142,6 +142,8 @@ tsdh-dark '(widget-field ((t (:box (:line-width 2 :color "grey75" :style pressed-button))))) '(window-number-face ((t (:foreground "red" :weight bold))))) +(put 'tsdh-dark 'dual-theme 'tsdh-light) ;see `toggle-theme' + (provide-theme 'tsdh-dark) ;;; tsdh-dark-theme.el ends here diff --git a/etc/themes/tsdh-light-theme.el b/etc/themes/tsdh-light-theme.el index d9d09b702b..64c048f7e5 100644 --- a/etc/themes/tsdh-light-theme.el +++ b/etc/themes/tsdh-light-theme.el @@ -104,6 +104,8 @@ tsdh-light '(show-paren-mismatch ((t (:background "deep pink" :weight bold)))) '(window-number-face ((t (:foreground "red" :weight bold))))) +(put 'tsdh-light 'dual-theme 'tsdh-dark) ;see `toggle-theme' + (provide-theme 'tsdh-light) ;;; tsdh-light-theme.el ends here diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el index 69ec837db8..04d9ed0004 100644 --- a/lisp/cus-theme.el +++ b/lisp/cus-theme.el @@ -515,6 +515,8 @@ describe-theme-1 (end-of-file nil))))) (and (eq (car-safe sexp) 'deftheme) (setq doc (nth 2 sexp))))))) + (when-let ((dual (get theme 'dual-theme))) + (princ (format " The dual theme is `%s'" dual))) (princ "\n\nDocumentation:\n") (princ (if (stringp doc) (substitute-command-keys doc) diff --git a/lisp/custom.el b/lisp/custom.el index 96dfb37d86..ec15267c62 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -1374,6 +1374,25 @@ load-theme (enable-theme theme)) t) +(defun toggle-theme (&optional no-confirm no-enable) + "Toggle the current active theme by enabling its dual pair. +The current theme will be immediately disabled before the dual +theme has been enabled. If THEME is not active an error will be +raised. If theme is nil For NO-CONFIRM and NO-ENABLE, see +`load-theme'." + (interactive) + (cond + ((length= custom-enabled-themes 0) + (user-error "No theme is active, cannot toggle")) + ((length> custom-enabled-themes 1) + (user-error "More than one theme active, cannot unambiguously toggle"))) + (let* ((theme (car custom-enabled-themes)) + (dual (get theme 'dual-theme))) + (unless dual + (error "`%s' has no dual theme to toggle between" theme)) + (disable-theme theme) + (load-theme dual no-confirm no-enable))) + (defun custom-theme-load-confirm (hash) "Query the user about loading a Custom theme that may not be safe. The theme should be in the current buffer. If the user agrees, -- 2.37.2 --=-=-=--