From: Philip Kaludercic <philipk@posteo.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 57639@debbugs.gnu.org
Subject: bug#57639: [PATCH] Add new command 'toggle-theme'
Date: Sun, 11 Sep 2022 18:47:40 +0000 [thread overview]
Message-ID: <8735cxpx2r.fsf@posteo.net> (raw)
In-Reply-To: <87bkrmdt46.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 11 Sep 2022 13:54:01 +0200")
[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Philip Kaludercic <philipk@posteo.net> writes:
>
>>> Code exists for both Windows and Macos in the bug tracker somewhere, but
>>> haven't been integrated yet because nobody has sat down to make a
>>> consistent interface across all the platforms.
>>
>> What about GNU/Linux desktops?
>
> I thought we already had support for this under Gtk? But I may be
> misremembering.
Am I reading it correctly that `style_changed_cb' in gtkutils.c would be
a place to start looking for this functionality?
>> Stefans Gruvbox example had multiple dark and light variants. E.g.
>> Would the new command toggle from `gruvbox-dark-soft' to
>> `gruvbox-dark-light' or prompt the user to select from all the gruvbox
>> themes?
>
> Yes, but if you have the soft gruvbox active, you don't want to switch
> to the hard one when changing between dark/light, so there's no ambiguity.
So would gruvbox-soft-dark have all the other themes as variants or only
gruvbox-soft-dark?
>>> But now I see that you've pushed `toggle-theme'... *sigh*
>>
>> I'm very sorry about that, I've reverted those commits, since they were
>> accidentally pushed!
>
> *phew* Thanks. 😀
Here is an updated version:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-command-theme-choose-variant.patch --]
[-- Type: text/x-patch, Size: 7617 bytes --]
From 1c9f1d92d0ecc4c7b94772e3a15ebf5e577a7f3d Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 6 Sep 2022 20:53:35 +0200
Subject: [PATCH] Add new command 'theme-choose-variant'
* 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 (theme-choose-variant): Add new command.
(toggle-theme): Add an alias. (Bug#57639)
---
doc/emacs/custom.texi | 8 ++++++++
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 | 5 +++++
lisp/custom.el | 27 +++++++++++++++++++++++++++
9 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index ff7ab83190..f86c7e2dd9 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -667,6 +667,14 @@ Custom Themes
the @file{*Custom Themes*} buffer; or type @kbd{M-x describe-theme}
anywhere in Emacs and enter the theme name.
+@findex theme-choose-variant
+ Some themes have variants (most often these are light and dark
+pairs). You can switch between these by typing @kbd{M-x
+theme-choose-variant}. Note that this only works if only one theme is
+active. If a theme has only one alternative, it will toggle
+automatically. If there are more of them, it will query which one to
+use.
+
@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..dfcd64a11c 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: 20220911.1858
;; 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 'theme-variants '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..66a65bc0b3 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: 20220911.1858
;; 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 'theme-variants '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..81b7cbde13 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 'theme-variants '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..7f53a5cce2 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 'theme-variants '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..aef8cae3e0 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 'theme-variants '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..d0f11f272b 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 'theme-variants '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 90680ff68f..dcd562c6af 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -515,6 +515,11 @@ describe-theme-1
(end-of-file nil)))))
(and (eq (car-safe sexp) 'deftheme)
(setq doc (nth 2 sexp)))))))
+ (when-let ((variants (get theme 'theme-variants)))
+ (princ (concat " Variants of this theme are "
+ (mapconcat
+ (lambda (th) (concat "`" th "'"))
+ variants ", "))))
(princ "\n\nDocumentation:\n")
(princ (if (stringp doc)
(substitute-command-keys doc)
diff --git a/lisp/custom.el b/lisp/custom.el
index 352b5b0e16..58f8d05ec6 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1372,6 +1372,33 @@ load-theme
(enable-theme theme))
t)
+(defun theme-choose-variant (&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)) variants)
+ (dolist (variant (ensure-list (get theme 'theme-variants)))
+ (when (and (custom-theme-p theme) (not (eq variant theme)))
+ (push variant variants)))
+ (let ((choice (cond
+ ((null variants)
+ (error "`%s' has no variants" theme))
+ ((length= variants 1)
+ (car variants))
+ ((intern (completing-read "Load custom theme: " variants))))))
+ (disable-theme theme)
+ (load-theme choice no-confirm no-enable))))
+
+(defalias 'toggle-theme #'theme-choose-variant)
+
(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.3
next prev parent reply other threads:[~2022-09-11 18:47 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 7:19 bug#57639: [PATCH] Add new command 'toggle-theme' Philip Kaludercic
2022-09-07 8:06 ` Stefan Kangas
2022-09-07 8:33 ` Philip Kaludercic
2022-09-07 8:51 ` Stefan Kangas
2022-09-07 13:03 ` Lars Ingebrigtsen
2022-09-07 13:31 ` Philip Kaludercic
2022-09-08 11:46 ` Lars Ingebrigtsen
2022-09-11 8:26 ` Philip Kaludercic
2022-09-11 11:11 ` Lars Ingebrigtsen
2022-09-11 11:22 ` Lars Ingebrigtsen
2022-09-11 11:42 ` Philip Kaludercic
2022-09-11 11:54 ` Lars Ingebrigtsen
2022-09-11 18:47 ` Philip Kaludercic [this message]
2022-09-12 10:10 ` Lars Ingebrigtsen
2022-09-12 11:06 ` Philip Kaludercic
2022-09-12 11:12 ` Lars Ingebrigtsen
2022-09-12 13:11 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-12 14:51 ` Michael Albinus
2022-09-13 12:09 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-12 15:26 ` Philip Kaludercic
2022-09-13 2:25 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-13 11:10 ` Lars Ingebrigtsen
2022-09-14 11:38 ` Philip Kaludercic
2022-09-14 13:03 ` Lars Ingebrigtsen
2022-09-14 14:37 ` Philip Kaludercic
2022-09-14 15:21 ` Lars Ingebrigtsen
2022-09-17 18:13 ` Philip Kaludercic
2022-09-17 18:32 ` Eli Zaretskii
2022-09-17 21:33 ` Philip Kaludercic
2022-09-18 6:53 ` Eli Zaretskii
2022-09-18 9:38 ` Philip Kaludercic
2022-09-18 10:39 ` Lars Ingebrigtsen
2022-09-18 11:39 ` Philip Kaludercic
2022-09-19 7:58 ` Lars Ingebrigtsen
2022-09-19 8:05 ` Philip Kaludercic
2022-09-19 8:15 ` Lars Ingebrigtsen
2022-09-19 10:13 ` Philip Kaludercic
2022-09-20 21:08 ` Philip Kaludercic
2022-09-20 21:11 ` Lars Ingebrigtsen
2022-09-20 21:35 ` Philip Kaludercic
2022-09-21 11:02 ` Lars Ingebrigtsen
2022-09-21 11:30 ` Philip Kaludercic
2022-09-21 11:38 ` Lars Ingebrigtsen
2022-09-21 11:46 ` Philip Kaludercic
2022-09-21 12:06 ` Lars Ingebrigtsen
2022-09-21 12:26 ` Philip Kaludercic
2022-10-09 12:58 ` Philip Kaludercic
2022-10-09 14:26 ` Lars Ingebrigtsen
2022-10-09 15:13 ` Philip Kaludercic
2022-10-09 20:32 ` Stefan Kangas
2022-10-09 21:02 ` Philip Kaludercic
2022-10-09 21:43 ` Philip Kaludercic
2022-10-10 0:56 ` Stefan Kangas
2022-10-10 1:17 ` Protesilaos Stavrou
2022-10-10 8:16 ` Philip Kaludercic
2022-10-10 8:14 ` Lars Ingebrigtsen
2022-10-10 11:02 ` Philip Kaludercic
2022-10-11 0:25 ` Lars Ingebrigtsen
2022-10-11 9:06 ` Philip Kaludercic
2022-10-11 19:43 ` Lars Ingebrigtsen
2022-10-11 19:51 ` Philip Kaludercic
2022-10-11 20:04 ` Lars Ingebrigtsen
2022-10-11 20:09 ` Philip Kaludercic
2022-10-11 20:49 ` Lars Ingebrigtsen
2022-10-13 8:50 ` Philip Kaludercic
2022-10-13 9:10 ` Philip Kaludercic
2022-10-13 10:34 ` Eli Zaretskii
2022-10-13 10:35 ` Philip Kaludercic
2022-10-13 14:03 ` Stefan Kangas
2022-10-13 14:07 ` Philip Kaludercic
2022-10-19 2:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-19 7:16 ` Philip Kaludercic
2022-10-19 12:21 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <87a65qla8d.fsf@posteo.net>
2022-10-20 17:04 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-20 17:42 ` Philip Kaludercic
2022-10-20 20:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-19 2:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-19 7:20 ` Philip Kaludercic
2022-10-19 10:59 ` Eli Zaretskii
2022-10-19 12:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-13 19:12 ` Lars Ingebrigtsen
2022-10-13 20:21 ` Philip Kaludercic
2022-09-21 13:08 ` Protesilaos Stavrou
2022-09-21 13:13 ` Philip Kaludercic
2022-09-21 13:21 ` Protesilaos Stavrou
2022-09-21 13:05 ` Protesilaos Stavrou
2022-09-18 12:52 ` Eli Zaretskii
2022-09-18 12:56 ` Philip Kaludercic
2022-09-20 3:40 ` bug#57639: Toggling, in general Richard Stallman
2022-09-20 8:07 ` Philip Kaludercic
2022-09-21 2:47 ` Richard Stallman
2022-09-21 9:22 ` Robert Pluim
2022-09-20 12:20 ` Visuwesh
2022-10-13 20:46 ` bug#57639: [PATCH] Add new command 'toggle-theme' Mauro Aranda
2022-10-13 22:19 ` Philip Kaludercic
2022-10-13 22:53 ` Mauro Aranda
2022-10-14 7:28 ` Philip Kaludercic
2022-10-14 11:22 ` Mauro Aranda
2022-10-14 15:21 ` Philip Kaludercic
2022-10-14 18:20 ` Philip Kaludercic
2022-10-15 15:24 ` Philip Kaludercic
2022-10-14 6:11 ` Eli Zaretskii
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8735cxpx2r.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=57639@debbugs.gnu.org \
--cc=larsi@gnus.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.