emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ef-themes 4465f117ca 3/4: Define ef-themes-rotate comma


From: ELPA Syncer
Subject: [elpa] externals/ef-themes 4465f117ca 3/4: Define ef-themes-rotate command and corresponding user option
Date: Fri, 25 Oct 2024 03:57:57 -0400 (EDT)

branch: externals/ef-themes
commit 4465f117caa73f1e412d227a683f92018fb88a6d
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Define ef-themes-rotate command and corresponding user option
---
 README.org   | 27 +++++++++++++++++++++++++--
 ef-themes.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/README.org b/README.org
index 0bac42fff1..c9f2c01985 100644
--- a/README.org
+++ b/README.org
@@ -247,6 +247,26 @@ command).
 This command 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]]).
 
+** Rotate among a list of Ef themes
+:PROPERTIES:
+:CUSTOM_ID: h:96bc23ed-40b2-43b4-ba47-b6a5c350563d
+:END:
+
+[ This is part of {{{development-version}}}. ]
+
+#+vindex: ef-themes-to-rotate
+#+findex: ef-themes-rotate
+The user option ~ef-themes-to-rotate~ defines a list of Ef themes that
+can be used in rotation. The command ~ef-themes-rotate~ reads from
+that list and switches to the next item. If the next item is the
+current one, it moves to the one after.
+
+Possible values for ~ef-themes-to-rotate~ are any of the themes
+specified in value of the variable ~ef-themes-items~.
+
+This command 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]]).
+
 ** Enable mixed fonts
 :PROPERTIES:
 :CUSTOM_ID: h:621d3bb9-5967-4f97-b253-7470bba9168c
@@ -713,9 +733,12 @@ example:
 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]]).  The same goes
-for ~ef-themes-toggle~ ([[#h:a58b8e21-0f8f-4763-9b47-185bf7e10043][Toggle 
between two Ef themes]]).
+for ~ef-themes-toggle~ and ~ef-themes-rotate~ [ The ~ef-themes-rotate~
+is part of {{{development-version}}} ].
 
-[[#h:1dbea3c9-de9a-4bb4-b540-654bea70ba4d][A theme-agnostic hook for theme 
loading]].
+- [[#h:a58b8e21-0f8f-4763-9b47-185bf7e10043][Toggle between two Ef themes]]
+- [[#h:96bc23ed-40b2-43b4-ba47-b6a5c350563d][Rotate among a list of Ef themes]]
+- [[#h:1dbea3c9-de9a-4bb4-b540-654bea70ba4d][A theme-agnostic hook for theme 
loading]].
 
 #+findex: ef-themes-select
 The themes can also be loaded interactively.  The command
diff --git a/ef-themes.el b/ef-themes.el
index e07f02e0fc..5001d99799 100644
--- a/ef-themes.el
+++ b/ef-themes.el
@@ -150,6 +150,14 @@ themes that form part of this collection."
   :package-version '(ef-themes . "0.3.0")
   :group 'ef-themes)
 
+(defcustom ef-themes-to-rotate ef-themes-items
+  "List of Ef themes to rotate among, per `modus-themes-rotate'."
+  :type `(repeat (choice
+                  :tag "A theme among the `ef-themes-items'"
+                  ,@(mapcar (lambda (theme) (list 'const theme)) 
ef-themes-items)))
+  :package-version '(modus-themes . "1.9.0")
+  :group 'ef-themes)
+
 (defconst ef-themes-weights
   '( thin ultralight extralight light semilight regular medium
      semibold bold heavy extrabold ultrabold)
@@ -526,6 +534,10 @@ overrides."
         `(metadata (category . ,category))
       (complete-with-action action candidates string pred))))
 
+(defun ef-themes--ef-p (theme)
+  "Return non-nil if THEME name has an ef- prefix."
+  (string-prefix-p "ef-" (symbol-name theme)))
+
 (defvar ef-themes--select-theme-history nil
   "Minibuffer history of `ef-themes--select-prompt'.")
 
@@ -706,6 +718,41 @@ symbol."
     (ef-themes-load-theme loaded)
     (message "Loaded `%s'" loaded)))
 
+;;;; Rotate through a list of themes
+
+(defun ef-themes--rotate (themes)
+  "Rotate THEMES rightward such that the car is moved to the end."
+  (if (proper-list-p themes)
+      (let* ((index (seq-position themes (ef-themes--current-theme)))
+             (offset (1+ index)))
+        (append (nthcdr offset themes) (take offset themes)))
+    (error "The `%s' is not a list" themes)))
+
+(defun ef-themes--rotate-p (themes)
+  "Return a new theme among THEMES if it is possible to rotate to it."
+  (if-let* ((new-theme (car (ef-themes--rotate themes))))
+      (if (eq new-theme (ef-themes--current-theme))
+          (car (ef-themes--rotate-p (ef-themes--rotate themes)))
+        new-theme)
+    (error "Cannot determine a theme among `%s'" themes)))
+
+;;;###autoload
+(defun ef-themes-rotate (themes)
+  "Rotate to the next theme among THEMES.
+When called interactively THEMES is the value of `ef-themes-to-rotate'.
+
+If the current theme is already the next in line, then move to the one
+after.  Perform the rotation rightwards, such that the first element in
+the list becomes the last.  Do not modify THEMES in the process."
+  (interactive (list ef-themes-to-rotate))
+  (unless (proper-list-p themes)
+    "This is not a list of themes: `%s'" themes)
+  (let ((candidate (ef-themes--rotate-p themes)))
+    (if (ef-themes--ef-p candidate)
+        (progn
+          (message "Rotating to `%s'" (propertize (symbol-name candidate) 
'face 'success))
+          (ef-themes-load-theme candidate))
+      (user-error "`%s' is not part of the Ef collection" candidate))))
 
 ;;;; Preview a theme palette
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]