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

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

[nongnu] elpa/gnosis a783b56772 10/19: New function: Add validate-custom


From: ELPA Syncer
Subject: [nongnu] elpa/gnosis a783b56772 10/19: New function: Add validate-custom-values.
Date: Thu, 5 Sep 2024 13:00:31 -0400 (EDT)

branch: elpa/gnosis
commit a783b56772fe44111395e3045cfebbf986259495
Author: Thanos Apollo <public@thanosapollo.org>
Commit: Thanos Apollo <public@thanosapollo.org>

    New function: Add validate-custom-values.
    
    * Function to be used with a variable watcher to validate custom
    gnosis values.
---
 gnosis.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/gnosis.el b/gnosis.el
index 2e8af51275..61ab5db0cb 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -2017,6 +2017,35 @@ SUSPEND: Suspend note, 0 for unsuspend, 1 for suspend"
                     (gnosis-update 'notes `(= ,field ',value) `(= id ,id)))
                    (t (gnosis-update 'notes `(= ,field ,value) `(= id ,id))))))
 
+(defun gnosis-validate-custom-values (new-value)
+  "Validate the structure and values of NEW-VALUE for gnosis-custom-values."
+  (unless (listp new-value)
+    (error "GNOSIS-CUSTOM-VALUES should be a list of entries"))
+  (dolist (entry new-value)
+    (unless (and (listp entry) (= (length entry) 3)
+                 (memq (nth 0 entry) '(:deck :tag))
+                 (stringp (nth 1 entry))
+                 (listp (nth 2 entry))) ; Ensure the third element is a plist
+      (error "Each entry should a :deck or :tag keyword, a string, and a plist 
of custom values"))
+    (let ((nested-plist (nth 2 entry))
+          (proto (plist-get (nth 2 entry) :proto))
+          (anagnosis (plist-get (nth 2 entry) :anagnosis))
+          (epignosis (plist-get (nth 2 entry) :epignosis))
+          (agnoia (plist-get (nth 2 entry) :agnoia))
+          (amnesia (plist-get (nth 2 entry) :amnesia))
+          (lethe (plist-get (nth 2 entry) :lethe)))
+      (unless (listp proto)
+        (error "Proto must be a list of interval integer values"))
+      (unless (or (null anagnosis) (integerp anagnosis))
+        (error "Anagnosis should be an integer"))
+      (unless (or (null epignosis) (numberp epignosis))
+        (error "Epignosis should be a number"))
+      (unless (or (null agnoia) (numberp agnoia))
+        (error "Agnoia should be a number"))
+      (unless (or (null amnesia) (and (numberp amnesia) (<= amnesia 1) (>= 
amnesia 0)))
+        (error "Amnesia should be a number between 0 and 1"))
+      (unless (or (null lethe) (and (integerp lethe) (> lethe 0)))
+        (error "Lethe should be an integer greater than 0")))))
 (defun gnosis-get-custom-values--validate (plist valid-keywords)
   "Verify that PLIST consists of VALID-KEYWORDS."
   (let ((keys (let (ks)



reply via email to

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