summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-08-07 14:48:39 +0300
committerThanos Apollo <[email protected]>2024-08-07 14:48:39 +0300
commitedbfadfec50cefcd956414f96e0be87e7ffde80e (patch)
tree6f44c8c8d4acb23c7df713a51bbb2270a26da2f1
parentdb19024b19fa25ad4211a7fdb2ee5f9e60439af9 (diff)
New function: get-custom-values--validate.
* Validate custom keyword values for gnosis. * Update error messages.
-rw-r--r--gnosis.el15
1 files changed, 14 insertions, 1 deletions
diff --git a/gnosis.el b/gnosis.el
index 2860464..926c033 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -1981,18 +1981,31 @@ 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-get-custom-values--validate (plist valid-keywords)
+ "Verify that PLIST consists of VALID-KEYWORDS."
+ (let ((keys (let (ks)
+ (while plist
+ (setq ks (cons (car plist) ks))
+ (setq plist (cddr plist)))
+ ks)))
+ (let ((invalid-key (cl-find-if (lambda (key) (not (member key valid-keywords))) keys)))
+ (if invalid-key
+ (error "Invalid custom keyword found in: %s" invalid-key)
+ t))))
+
(defun gnosis-get-custom-values (key search-value &optional values)
"Return SEARCH-VALUE for KEY from VALUES.
VALUES: Defaults to `gnosis-custom-values'."
(cl-assert (or (eq key :deck) (eq key :tag)) nil "Key value must be either :tag or :deck")
- (cl-assert (stringp search-value) nil "Search-value must be a string, the name of tag or deck.")
+ (cl-assert (stringp search-value) nil "Search-value must be the name of tag or deck as a string.")
(let ((results)
(values (or values gnosis-custom-values)))
(dolist (rule values)
(when (and (plist-get rule key)
(equal (plist-get rule key) search-value))
(setq results (append results (nth 2 rule)))))
+ (gnosis-get-custom-values--validate results gnosis-custom--valid-values)
results))
(defun gnosis-get-custom-deck-value (deck value &optional values)