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: Sun, 18 Sep 2022 09:38:02 +0000 Message-ID: <87h715dnut.fsf@posteo.net> References: <875yhzmz25.fsf@posteo.net> <875yhzmj50.fsf@gnus.org> <875yhzl3a1.fsf@posteo.net> <87fsh25bso.fsf@gnus.org> <871qsil3jm.fsf@posteo.net> <87fsgygo7c.fsf@gnus.org> <87a676jfx2.fsf@posteo.net> <87bkrmdt46.fsf@gnus.org> <8735cxpx2r.fsf@posteo.net> <87k066yyn0.fsf@posteo.net> <877d269kgv.fsf@gnus.org> <87bkriyqci.fsf@posteo.net> <874jxa6kyj.fsf@gnus.org> <87o7vdg97w.fsf@posteo.net> <831qs926np.fsf@gnu.org> <871qs9fzz5.fsf@posteo.net> <83h715yxz2.fsf@gnu.org> 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="12504"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 57639@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 18 11:39:13 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 1oZqlb-00034f-Nl for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 11:39:12 +0200 Original-Received: from localhost ([::1]:50936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZqla-0006qy-Fm for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 05:39:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZqlS-0006qZ-H3 for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 05:39:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZqlS-0005R7-7Q for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 05:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oZqlR-0002qB-TI for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 05:39: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: Sun, 18 Sep 2022 09:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57639 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 57639-submit@debbugs.gnu.org id=B57639.166349389610859 (code B ref 57639); Sun, 18 Sep 2022 09:39:01 +0000 Original-Received: (at 57639) by debbugs.gnu.org; 18 Sep 2022 09:38:16 +0000 Original-Received: from localhost ([127.0.0.1]:47790 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZqkh-0002p4-Jr for submit@debbugs.gnu.org; Sun, 18 Sep 2022 05:38:16 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:32931) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZqke-0002on-7Z for 57639@debbugs.gnu.org; Sun, 18 Sep 2022 05:38:13 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 0FDFE240026 for <57639@debbugs.gnu.org>; Sun, 18 Sep 2022 11:38:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1663493886; bh=Y5T2e7oo1+IVfkBjU9DOnkwIng89S63nt5+lX2wiXoA=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=myTxPUdl9DW2g0dts81ZA4RPkSNXQr4XOylSl+X/Ej1e94U0GN3RjrFddwVBuoSQg 1XmsnIWSYkpc/uivNWJ4DaGOjmzKelcoZaD3KqUkEkU94YG2mD3eOFpuU1lGxDBG0x lS9tVHb2RV4cdFkjnUVSEbl501kdJPhldTG+HwjpL+lp0x9xCUqrNzCjWLO/AYMaNK qKYFiLtVaQwdr9o3+AB4W9yS5WqxZebgRkOeTY7d1uueQ/P1l3QFvEiyLzXaxczIy3 9ho9+lzH//6wtajgMMiw1UNqb6jtpcJdZuDHDzKhFOQhSqz8e8rIZKP85LopjjQPQj W3hUw2HX2gEWw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MVjQz5yQbz9rxH; Sun, 18 Sep 2022 11:38:02 +0200 (CEST) In-Reply-To: <83h715yxz2.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 18 Sep 2022 09:53:53 +0300") 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 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:242939 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Philip Kaludercic >> Cc: larsi@gnus.org, 57639@debbugs.gnu.org >> Date: Sat, 17 Sep 2022 21:33:18 +0000 >> >> >> + (let* ((theme (car custom-enabled-themes)) >> >> + (family (plist-get (get theme 'theme-properties) :family))) >> >> + (unless family >> >> + (error "`%s' is not part of a family" theme)) >> > >> > "Family"? this terminology was never mentioned in the manual or the >> > doc string. How about >> > >> > Theme `%s' does not have any variants >> > >> > instead? >> >> Strictly speaking that error message would be wrong at this point, >> because we cannot say if a theme has no variants if it is not part of a >> family. This is because variants of a theme are all those that are part >> of the same family. I think it would be better to clarify this in the >> documentation. > > But the documentation doesn't explain what it means for a theme to be > part of a family. Specifically, how does one tell, by looking at a > theme, whether it is or isn't part of a family? > > An alternative for what I suggested above is to say > > Theme `%s' does not have any known variants I get what you mean... how about (error "Theme `%s' is not part of a family of variants" theme) ? >> +(defun theme-choose-variant (&optional no-confirm no-enable) >> + "Prompt to switch from the current theme to a variant. > ^^^^^^^^^^^^ > "to one of its variants" is more clear. Done. >> +Themes only have variants if they are part of a family of themes. > > This should explain what it means to be part of a family, otherwise > this sentence is not helpful. My intention was for this to be an explanation. The issue is that variants and family are mutually recursive concepts: - A variant of a theme are those which are part of the same family - A family of themes is the set of all variants of a theme. Perhaps it is just easier to collapse both concepts into either variant of family and just "expose" by documenting it. I've tried doing so below. >> +The current theme will be immediately disabled before variant is >> +enabled. > > The "immediately" part should probably be removed, as it doesn't seem > to convey anything of importance, does it? Come to think of it, what > exactly does this sentence try to say? isn't it obvious that the > current theme will be disabled and then the variant will be enabled? I guess it isn't necessary, the point was just to emphasise that nothing happens between disabling the previous theme and enabling the variant. There was something I had in mind when writing this initially, but I cannot recall it anymore. So I've removed it for now. >> In case the current theme has only one variant, it will >> +be toggled without prompting. > > "toggled" is wrong here. I suggest > > If the current theme has only one variant, switch to that variant > without prompting, otherwise prompt for the variant to select. Done. >> For NO-CONFIRM and NO-ENABLE, see >> +`load-theme'." > > I suggest to say this the other way around: > > See `load-theme' for the meaning of NO-CONFIRM and NO-ENABLE. Done. > Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Tag-themes-with-properties.patch >From 4aa11070669c4b7c802d54d7dd7dffbd41a1a409 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sat, 17 Sep 2022 20:11:42 +0200 Subject: [PATCH] Tag themes with properties * doc/emacs/custom.texi (Custom Themes): Document 'theme-choose-variant'. * doc/lispref/customize.texi (Custom Themes): Document the new optional argument to 'deftheme'. * etc/themes/leuven-dark-theme.el (leuven-dark): Add properties. * etc/themes/leuven-theme.el (leuven): Add properties. * etc/themes/tango-dark-theme.el (tango-dark): Add properties. * etc/themes/tango-theme.el (tango): Add properties. * etc/themes/tsdh-dark-theme.el (tsdh-dark): Add properties. * etc/themes/tsdh-light-theme.el (tsdh-light): Add properties. * lisp/custom.el (deftheme): Allow for optional arguments to set the property list. (custom-declare-theme): Accept the same optional arguments as 'deftheme'. (theme-list-variants): Add new function. (theme-choose-variant): Add new command for switching between members of a theme family. (toggle-theme): Add an alias for 'theme-choose-variant'. --- doc/emacs/custom.texi | 10 ++++++ doc/lispref/customize.texi | 5 +-- etc/themes/leuven-dark-theme.el | 6 ++-- etc/themes/leuven-theme.el | 6 ++-- etc/themes/tango-dark-theme.el | 4 ++- etc/themes/tango-theme.el | 4 ++- etc/themes/tsdh-dark-theme.el | 4 ++- etc/themes/tsdh-light-theme.el | 4 ++- lisp/custom.el | 61 +++++++++++++++++++++++++++++---- 9 files changed, 88 insertions(+), 16 deletions(-) diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index ff7ab83190..f98527bf9a 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -667,6 +667,16 @@ 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 just two: light and dark). You +can switch to another variant using @kbd{M-x theme-choose-variant}. +If the currently active theme has only one other variant, it will be +selected; if there are more variants, the command will prompt you +which one to switch to. + +Note that @code{theme-choose-variant} only works if a single theme +is active. + @node Creating Custom Themes @subsection Creating Custom Themes @cindex custom themes, creating diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi index 6ba35cffff..911b6c4d75 100644 --- a/doc/lispref/customize.texi +++ b/doc/lispref/customize.texi @@ -1428,12 +1428,13 @@ Custom Themes be a call to @code{deftheme}, and the last form should be a call to @code{provide-theme}. -@defmac deftheme theme &optional doc +@defmac deftheme theme &optional doc &rest properties This macro declares @var{theme} (a symbol) as the name of a Custom theme. The optional argument @var{doc} should be a string describing the theme; this is the description shown when the user invokes the @code{describe-theme} command or types @kbd{?} in the @samp{*Custom -Themes*} buffer. +Themes*} buffer. The remaining arguments @var{properties} are used +pass a property list with theme attributes. Two special theme names are disallowed (using them causes an error): @code{user} is a dummy theme that stores the user's direct diff --git a/etc/themes/leuven-dark-theme.el b/etc/themes/leuven-dark-theme.el index 0e162c8bab..42ebd7b2d6 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: 20220917.2332 ;; Keywords: color theme ;; This file is part of GNU Emacs. @@ -97,7 +97,9 @@ leuven-dark "Face colors with a light background. Basic, Font Lock, Isearch, Gnus, Message, Org mode, Diff, Ediff, Flyspell, Semantic, and Ansi-Color faces are included -- and much -more...") +more..." + :background-mode 'dark + :family 'leuven) (let ((class '((class color) (min-colors 89))) diff --git a/etc/themes/leuven-theme.el b/etc/themes/leuven-theme.el index d9a8d5391a..07c34e944c 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: 20220917.2332 ;; Keywords: color theme ;; This file is part of GNU Emacs. @@ -78,7 +78,9 @@ leuven "Face colors with a light background. Basic, Font Lock, Isearch, Gnus, Message, Org mode, Diff, Ediff, Flyspell, Semantic, and Ansi-Color faces are included -- and much -more...") +more..." + :background-mode 'light + :family 'leuven) (let ((class '((class color) (min-colors 89))) diff --git a/etc/themes/tango-dark-theme.el b/etc/themes/tango-dark-theme.el index ef00d2ac49..fb5a1b29eb 100644 --- a/etc/themes/tango-dark-theme.el +++ b/etc/themes/tango-dark-theme.el @@ -30,7 +30,9 @@ (deftheme tango-dark "Face colors using the Tango palette (dark background). Basic, Font Lock, Isearch, Gnus, Message, Ediff, Flyspell, -Semantic, and Ansi-Color faces are included.") +Semantic, and Ansi-Color faces are included." + :background-mode 'dark + :family 'tango) (let ((class '((class color) (min-colors 89))) ;; Tango palette colors. diff --git a/etc/themes/tango-theme.el b/etc/themes/tango-theme.el index ecbbf03753..026718bf38 100644 --- a/etc/themes/tango-theme.el +++ b/etc/themes/tango-theme.el @@ -30,7 +30,9 @@ (deftheme tango "Face colors using the Tango palette (light background). Basic, Font Lock, Isearch, Gnus, Message, Ediff, Flyspell, -Semantic, and Ansi-Color faces are included.") +Semantic, and Ansi-Color faces are included." + :background-mode 'light + :family 'tango) (let ((class '((class color) (min-colors 89))) ;; Tango palette colors. diff --git a/etc/themes/tsdh-dark-theme.el b/etc/themes/tsdh-dark-theme.el index a88ad75520..ddd710a16e 100644 --- a/etc/themes/tsdh-dark-theme.el +++ b/etc/themes/tsdh-dark-theme.el @@ -20,7 +20,9 @@ ;;; Code: (deftheme tsdh-dark - "A dark theme used and created by Tassilo Horn.") + "A dark theme used and created by Tassilo Horn." + :background-mode 'dark + :family 'tsdh) (custom-theme-set-faces 'tsdh-dark diff --git a/etc/themes/tsdh-light-theme.el b/etc/themes/tsdh-light-theme.el index d9d09b702b..724b081880 100644 --- a/etc/themes/tsdh-light-theme.el +++ b/etc/themes/tsdh-light-theme.el @@ -21,7 +21,9 @@ (deftheme tsdh-light "A light Emacs theme. -Used and created by Tassilo Horn.") +Used and created by Tassilo Horn." + :background-mode 'light + :family 'tsdh) (custom-theme-set-faces 'tsdh-light diff --git a/lisp/custom.el b/lisp/custom.el index 352b5b0e16..5a3d3b95e2 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -1152,9 +1152,11 @@ custom--sort-vars-1 ;; (provide-theme 'THEME) -(defmacro deftheme (theme &optional doc) +(defmacro deftheme (theme &optional doc &rest properties) "Declare THEME to be a Custom theme. The optional argument DOC is a doc string describing the theme. +PROPERTIES are interpreted as a property list that will be stored +in the `theme-properties' property for THEME. Any theme `foo' should be defined in a file called `foo-theme.el'; see `custom-make-theme-feature' for more information." @@ -1164,18 +1166,25 @@ deftheme ;; It is better not to use backquote in this file, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. - (list 'custom-declare-theme (list 'quote theme) (list 'quote feature) doc))) + (list 'custom-declare-theme (list 'quote theme) (list 'quote feature) doc + (cons 'list properties)))) -(defun custom-declare-theme (theme feature &optional doc) +(defun custom-declare-theme (theme feature &optional doc properties) "Like `deftheme', but THEME is evaluated as a normal argument. -FEATURE is the feature this theme provides. Normally, this is a symbol -created from THEME by `custom-make-theme-feature'." +FEATURE is the feature this theme provides. Normally, this is a +symbol created from THEME by `custom-make-theme-feature'. The +optional argument DOC may contain the documentation for THEME. +The optional argument PROPERTIES may contain a property list of +attributes associated with THEME." (unless (custom-theme-name-valid-p theme) (error "Custom theme cannot be named %S" theme)) (unless (memq theme custom-known-themes) (push theme custom-known-themes)) (put theme 'theme-feature feature) - (when doc (put theme 'theme-documentation doc))) + (when doc + (put theme 'theme-documentation doc)) + (when properties + (put theme 'theme-properties properties))) (defun custom-make-theme-feature (theme) "Given a symbol THEME, create a new symbol by appending \"-theme\". @@ -1372,6 +1381,46 @@ load-theme (enable-theme theme)) t) +(defun theme-list-variants (theme &rest list) + "Return a list of theme variants for THEME. +If the optional argument LIST is not given, " + (let* ((properties (get theme 'theme-properties)) + (family (plist-get properties :family))) + (seq-filter + (lambda (variant) + (and (eq (plist-get (get variant 'theme-properties) :family) + family) + (not (eq variant theme)))) + (or list (custom-available-themes))))) + +(defun theme-choose-variant (&optional no-confirm no-enable) + "Prompt to switch from the current theme to one of its a variants. +The current theme will be disabled before variant is enabled. If +the current theme has only one variant, switch to that variant +without prompting, otherwise prompt for the variant to select. +See `load-theme' for the meaning of NO-CONFIRM and NO-ENABLE." + (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)) + (family (plist-get (get theme 'theme-properties) :family))) + (unless family + (error "Theme `%s' does not have any known variants" theme)) + (let* ((variants (theme-list-variants theme)) + (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 --=-=-=--