summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-01-04 07:51:59 +0200
committerThanos Apollo <[email protected]>2024-01-04 07:51:59 +0200
commit1f41618eb14711bfbb758806c639f990d86626ff (patch)
tree28476790971c9efa8848d1b864b2b48adf29b680
parent845df83a4598d0998666a972244e2594a6e0ddf3 (diff)
gnosis-add-note-fields: Add condition-case & update docstring
-rw-r--r--gnosis.el21
1 files changed, 14 insertions, 7 deletions
diff --git a/gnosis.el b/gnosis.el
index abda991..bd3c078 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -371,9 +371,9 @@ When called with a prefix, unsuspends all notes for tag."
(defun gnosis-add-note-fields (deck type main options answer extra tags suspend image second-image)
- "Add fields for new note.
+ "Insert fields for new note.
-DECK: Deck for new note.
+DECK: Deck NAME, as a string, for new note.
TYPE: Note type e.g \"mcq\"
MAIN: Note's main part
OPTIONS: Note's options, e.g choices for mcq for OR hints for
@@ -384,11 +384,18 @@ EXTRA: Extra information to display after answering note
TAGS: Tags to organize notes
SUSPEND: Integer value of 1 or 0, where 1 suspends the card
IMAGE: Image to display during review.
-SECOND-IMAGE: Image to display after user-input."
- (gnosis--insert-into 'notes `([nil ,type ,main ,options ,answer ,tags ,(gnosis--get-deck-id deck)]))
- (gnosis--insert-into 'review `([nil ,gnosis-algorithm-ef ,gnosis-algorithm-ff ,gnosis-algorithm-interval]))
- (gnosis--insert-into 'review-log `([nil ,(gnosis-algorithm-date) ,(gnosis-algorithm-date) 0 0 0 0 ,suspend 0]))
- (gnosis--insert-into 'extras `([nil ,extra ,image ,second-image])))
+SECOND-IMAGE: Image to display after user-input.
+
+NOTE: If a gnosis--insert-into fails, the whole transaction will be
+ (or at least it should). Else there will be an error for foreign key
+ constraint."
+ (condition-case nil
+ (progn
+ (gnosis--insert-into 'notes `([nil ,type ,main ,options ,answer ,tags ,(gnosis--get-deck-id deck)]))
+ (gnosis--insert-into 'review `([nil ,gnosis-algorithm-ef ,gnosis-algorithm-ff ,gnosis-algorithm-interval]))
+ (gnosis--insert-into 'review-log `([nil ,(gnosis-algorithm-date) ,(gnosis-algorithm-date) 0 0 0 0 ,suspend 0]))
+ (gnosis--insert-into 'extras `([nil ,extra ,image ,second-image])))
+ (error (message "An error occurred during insertion"))))
;; Adding note(s) consists firstly of a hidden 'gnosis-add-note--TYPE'