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

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

[elpa] externals/ef-themes fd1bd35100 1/2: Make 'ef-themes-toggle' usefu


From: ELPA Syncer
Subject: [elpa] externals/ef-themes fd1bd35100 1/2: Make 'ef-themes-toggle' useful out-of-the-box
Date: Tue, 6 Sep 2022 13:57:34 -0400 (EDT)

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

    Make 'ef-themes-toggle' useful out-of-the-box
    
    The previous behaviour was not intuitive.  The problem was that if the
    user had not yet set the 'ef-themes-to-toggle' user option, the command
    would do nothing helpful.
    
    By falling back to selecting a theme, we do something useful and also
    provide a prompt that mentions the 'ef-themes-to-toggle'.
    
    This is based on the discussion with Philip Kaludercic about revising
    the 'ef-themes-toggle' command to have a more Do-What-I-Mean behaviour:
    
<https://lists.sr.ht/~protesilaos/ef-themes/%3C878rmwfs0e.fsf%40posteo.net%3E>.
---
 README.org   | 11 +++++++++--
 ef-themes.el | 40 ++++++++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/README.org b/README.org
index 9e072ca905..c738cad848 100644
--- a/README.org
+++ b/README.org
@@ -213,8 +213,15 @@ 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]]).
+[ The fallback behaviour of selecting a theme is part of 
{{{development-version}}}. ]
+
+If ~ef-themes-to-toggle~ does not specify two Ef themes, inform the user
+about it while prompting with completion for a theme among our
+collection (this is practically the same as the ~ef-themes-select~
+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]]).
 
 ** Enable mixed fonts
 :PROPERTIES:
diff --git a/ef-themes.el b/ef-themes.el
index 2039ac3d3e..5a7d962ca6 100644
--- a/ef-themes.el
+++ b/ef-themes.el
@@ -336,12 +336,14 @@ sequence given SEQ-PRED, using SEQ-DEFAULT as a fallback."
 
 (defvar ef-themes--select-theme-history nil)
 
-(defun ef-themes--select-prompt ()
-  "Minibuffer prompt for `ef-themes-select'."
-  (completing-read "Select Ef Theme: "
-                   (ef-themes--list-known-themes)
-                   nil t nil
-                   'ef-themes--select-theme-history))
+(defun ef-themes--select-prompt (&optional prompt)
+  "Minibuffer prompt for `ef-themes-select'.
+With optional PROMPT string, use it.  Else use a generic prompt."
+  (intern
+   (completing-read (or prompt "Select Ef Theme: ")
+                    (ef-themes--list-known-themes)
+                    nil t nil
+                    'ef-themes--select-theme-history)))
 
 (defun ef-themes--load-theme (theme)
   "Load THEME while disabling other Ef themes.
@@ -354,7 +356,7 @@ Run `ef-themes-post-load-hook'."
 (defun ef-themes-select (theme)
   "Load an Ef THEME using minibuffer completion.
 When called from Lisp, THEME is a symbol."
-  (interactive (list (intern (ef-themes--select-prompt))))
+  (interactive (list (ef-themes--select-prompt)))
   (ef-themes--load-theme theme))
 
 (defun ef-themes--toggle-theme-p ()
@@ -367,16 +369,22 @@ When called from Lisp, THEME is a symbol."
 
 ;;;###autoload
 (defun ef-themes-toggle ()
-  "Toggle between the two `ef-themes-to-toggle'."
+  "Toggle between the two `ef-themes-to-toggle'.
+If `ef-themes-to-toggle' does not specify two Ef themes, inform
+the user about it while prompting with completion for a theme
+among our collection (this is practically the same as the
+`ef-themes-select' command)."
   (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))))
+  (if-let* ((themes (ef-themes--toggle-theme-p))
+            (one (car themes))
+            (two (cadr themes)))
+      (if (eq (car custom-enabled-themes) one)
+          (ef-themes--load-theme two)
+        (ef-themes--load-theme one))
+    (ef-themes--load-theme
+     (ef-themes--select-prompt
+      (concat (propertize "Set two `ef-themes-to-toggle';" 'face 'error)
+              " switching to theme selection for now: ")))))
 
 (defun ef-themes--minus-current (&optional variant)
   "Return list of Ef themes minus the current one.



reply via email to

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