From 511a4fa54ca7c7ef38a2e9c923b9de194029fd72 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 3 Jan 2024 06:59:23 +0200 Subject: Add gnosis-replace-item-at-index Used to change/edit values at gnosis-db, that are represented as lists, such as ef --- gnosis.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gnosis.el') diff --git a/gnosis.el b/gnosis.el index c7c3fa5..d114ddc 100644 --- a/gnosis.el +++ b/gnosis.el @@ -85,8 +85,9 @@ WARNING: Do not change this value!") (cl-defun gnosis-update (table value where) "Update records in TABLE with to new VALUE based on the given WHERE condition. + Example: - (gnosis-update `''notes `''(= main \"NEW VALUE\") `''(= id 12))" + (gnosis-update ='notes ='(= main \"NEW VALUE\") ='(= id 12))" (emacsql gnosis-db `[:update ,table :set ,value :where ,where])) (cl-defun gnosis-get (value table &optional (restrictions '1=1)) @@ -130,6 +131,12 @@ FACE-FOR-INFO is the face used to display info for option." (cdr (assoc (completing-read prompt formatted-choices nil t) formatted-choices)))) +(defun gnosis-replace-item-at-index (index new-item list) + "Replace item at INDEX in LIST with NEW-ITEM." + (cl-loop for i from 0 for item in list + if (= i index) collect new-item + else collect item)) + (defun gnosis-display--question (id) "Display main row for note ID." (let ((question (gnosis-get 'main 'notes `(= id ,id)))) -- cgit v1.2.3