diff options
author | Thanos Apollo <[email protected]> | 2024-09-02 09:31:23 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-09-02 09:31:23 +0300 |
commit | a783b56772fe44111395e3045cfebbf986259495 (patch) | |
tree | 7fde8ab567c24029026c732861c970a8b9900981 | |
parent | 56ed928045f20bb7e9a6840774d852599489a585 (diff) |
New function: Add validate-custom-values.
* Function to be used with a variable watcher to validate custom
gnosis values.
-rw-r--r-- | gnosis.el | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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) |