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

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

[nongnu] elpa/swsw 366972729f: Improve user option error checking and up


From: ELPA Syncer
Subject: [nongnu] elpa/swsw 366972729f: Improve user option error checking and updating
Date: Tue, 22 Nov 2022 15:59:46 -0500 (EST)

branch: elpa/swsw
commit 366972729ff2ee26cd1b8c21562b60f6385bee76
Author: Daniel Semyonov <daniel@dsemy.com>
Commit: Daniel Semyonov <daniel@dsemy.com>

    Improve user option error checking and updating
    
    * swsw.el (swsw--set-and-maybe-update): New function.
    (swsw-id-chars): Use the ':validate' type keyword for error checking,
    and set value using 'swsw--set-and-maybe-update'.
    (swsw-scope): Set value using 'swsw--set-and-maybe-update'.
    (swsw-display-lighter): If new value is a function, call it with the
    value of 'swsw-mode' as the argument instead of 't'.
---
 swsw.el | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/swsw.el b/swsw.el
index 55d588630b..8958230486 100644
--- a/swsw.el
+++ b/swsw.el
@@ -94,18 +94,25 @@
   :group 'convenience
   :prefix "swsw-")
 
+(defun swsw--set-and-maybe-update (sym val)
+  "Set SYM's variable cell to VAL and call `swsw--update' conditionally."
+  (set-default sym val)
+  (and (boundp swsw-mode) swsw-mode (swsw--update)))
+
 (defcustom swsw-id-chars '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
   "Base set of characters from which window IDs are constructed.
 This list should contain at least two characters."
   :link '(info-link "(swsw) Customization")
-  :type '(repeat character)
+  :type '( repeat :validate
+           (lambda (w)
+             (unless (nth 1 (widget-value w))
+               (widget-put
+                w :error
+                "`swsw-id-chars' should contain at least two characters")
+               w))
+           character)
   :initialize #'custom-initialize-changed
-  :set (lambda (sym chars)
-         (unless (nth 1 chars)
-           (user-error
-            "`swsw-id-chars' should contain at least two characters"))
-         (set-default sym chars)
-         (swsw--update))
+  :set #'swsw--set-and-maybe-update
   :risky t
   :package-version '(swsw . 1.0))
 
@@ -125,9 +132,7 @@ This list should contain at least two characters."
                  :tag "All windows on the currently selected frame"
                  current))
   :initialize #'custom-initialize-changed
-  :set (lambda (sym scope)
-         (set-default sym scope)
-         (swsw--update))
+  :set #'swsw--set-and-maybe-update
   :risky t
   :package-version '(swsw . 1.1))
 
@@ -159,8 +164,8 @@ compatibility (see `swsw-display-function')."
          (and (boundp sym) (functionp (symbol-value sym))
               (funcall (symbol-value sym) nil))
          (set-default sym fun)
-         (when (functionp fun)
-           (funcall fun t)))
+         (and (boundp swsw-mode) (functionp fun)
+              (funcall fun swsw-mode)))
   :package-version '(swsw . 2.2))
 
 (defcustom swsw-mode-hook nil



reply via email to

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