[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ef-themes 274ca3863d 5/5: Add ef-themes-toggle cmd and
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ef-themes 274ca3863d 5/5: Add ef-themes-toggle cmd and ef-themes-toggle var |
Date: |
Fri, 19 Aug 2022 08:57:38 -0400 (EDT) |
branch: externals/ef-themes
commit 274ca3863d682d0431aa037a638f72aaf4647317
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add ef-themes-toggle cmd and ef-themes-toggle var
---
README.org | 31 ++++++++++++++++++++++++++++---
ef-themes.el | 28 ++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/README.org b/README.org
index 142c2b7bfc..8ee6ec8c05 100644
--- a/README.org
+++ b/README.org
@@ -124,8 +124,13 @@ Everything is in place to set up the package.
#+begin_src emacs-lisp
(require 'ef-themes)
-;; Make customisations BEFORE loading a theme (any change needs a theme
-;; re-load to take effect).
+;; If you like two specific themes and want to switch between them, you
+;; can specify them in `ef-themes-to-toggle' and then invoke the command
+;; `ef-themes-toggle':
+(setq ef-themes-to-toggle '(ef-summer ef-winter))
+
+;; Make customisations that affect Emacs faces BEFORE loading a theme
+;; (any change needs a theme re-load to take effect).
(setq ef-themes-headings ; read the manual's entry of the doc string
'((0 . (variable-pitch light 1.9))
@@ -154,6 +159,7 @@ Everything is in place to set up the package.
;; We also provide these commands, but do not assign them to any key:
;;
+;; - `ef-themes-toggle'
;; - `ef-themes-select'
;; - `ef-themes-load-random'
;; - `ef-themes-preview-colors'
@@ -312,7 +318,8 @@ as =init.el=.
#+vindex: ef-themes-post-load-hook
The commands mentioned herein call ~ef-themes-post-load-hook~ at the
end. This is for advanced users who want to trigger some code after an
-Ef theme is loaded ([[#h:5b74bd9e-e7f2-46b3-af2e-7c45b2e69245][Use colors from
the active Ef theme]]).
+Ef theme is loaded ([[#h:5b74bd9e-e7f2-46b3-af2e-7c45b2e69245][Use colors from
the active Ef theme]]). The same goes
+for ~ef-themes-toggle~ ([[#h:a58b8e21-0f8f-4763-9b47-185bf7e10043][Toggle
between two Ef themes]]).
#+findex: ef-themes-select
The themes can also be loaded interactively
([[#h:75d74aea-d17f-497f-a3b8-f0bf4c372de0][Loading a theme]]). The
@@ -370,6 +377,24 @@ light/dark theme and then loads an appropriate Ef theme at
random:
(ef-themes-load-random 'light))
#+end_src
+* Toggle between two Ef themes
+:PROPERTIES:
+:CUSTOM_ID: h:a58b8e21-0f8f-4763-9b47-185bf7e10043
+:END:
+
+[ Part of {{{development-version}}}. ]
+
+#+vindex: ef-themes-to-toggle
+#+findex: ef-themes-toggle
+The user option ~ef-themes-to-toggle~ expects two symbols that name
+items in the Ef themes collection. The variable ~ef-themes-collection~
+includes a list with all relevant symbols. The user can then switch
+between the two specified themes by invoking the ~ef-themes-toggle~
+command.
+
+This is in addition to the other ways of loading a theme, either with
+minibuffer completion or at random
([[#h:58345e8c-2bec-459c-872c-a85a29e9fe97][Commands to load an Ef theme]]).
+
* Preview theme colors
:PROPERTIES:
:CUSTOM_ID: h:8dd67bf5-879e-46e5-b277-5bac141f53d1
diff --git a/ef-themes.el b/ef-themes.el
index 3f9174f22d..cf079ed1db 100644
--- a/ef-themes.el
+++ b/ef-themes.el
@@ -76,6 +76,13 @@ This is used by the commands `ef-themes-select' and
:type 'hook
:group 'ef-themes)
+(defcustom ef-themes-to-toggle nil
+ "Specify two `ef-themes' for `ef-themes-toggle' command.
+The variable `ef-themes-collection' contains the symbols of all
+themes that form part of this collection."
+ :type '(repeat symbol) ; FIXME 2022-08-19: Replace `symbol' with specific
choices. How?
+ :group 'ef-themes)
+
(defconst ef-themes-weights
'( thin ultralight extralight light semilight regular medium
semibold bold heavy extrabold ultrabold)
@@ -299,6 +306,27 @@ When called from Lisp, THEME is a symbol."
(interactive (list (intern (ef-themes--select-prompt))))
(ef-themes--load-theme theme))
+(defun ef-themes--toggle-theme-p ()
+ "Return non-nil if `ef-themes-to-toggle' are valid."
+ (mapc (lambda (theme)
+ (if (memq theme ef-themes-collection)
+ theme
+ (user-error "`%s' is not part of `ef-themes-collection'" theme)))
+ ef-themes-to-toggle))
+
+;;;###autoload
+(defun ef-themes-toggle ()
+ "Toggle between the two `ef-themes-to-toggle'."
+ (interactive)
+ (when-let ((themes (ef-themes--toggle-theme-p))
+ (one (car themes))
+ (two (cadr themes)))
+ (unless (eq (length themes) 2)
+ (user-error "Can only toggle between two themes"))
+ (if (eq (car custom-enabled-themes) one)
+ (ef-themes--load-theme two)
+ (ef-themes--load-theme one))))
+
(defun ef-themes--minus-current (&optional variant)
"Return list of Ef themes minus the current one.
VARIANT is either `light' or `dark', which stand for