diff options
author | Thanos Apollo <[email protected]> | 2024-01-14 13:11:58 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-01-14 13:11:58 +0200 |
commit | 93c1b5c5048b36fc59b47f7a11412072c13b1b29 (patch) | |
tree | 15561af2c87b00f3df9e6fe92adf7e5f4f35f6ae | |
parent | f585d83f6df1498b9fa93eac7e4e37663bafb8f2 (diff) | |
parent | 4eb6c4cee963512777869aed0bd1e954b9898f1b (diff) |
Merge branch '#y-or-n' into testing
Adding note type of y-or-n and fixing issues with with
gnosis-edit-mode
y-or-n type note is one that has an answer value of char y or n.
-rw-r--r-- | gnosis.el | 68 |
1 files changed, 63 insertions, 5 deletions
@@ -237,6 +237,21 @@ When SUCCESS nil, display USER-INPUT as well" " " (propertize user-input 'face 'gnosis-face-false)))))) +(cl-defun gnosis-display-y-or-n-answer (&key answer success) + "Display y-or-n answer for note ID. + +ANSWER is the correct answer, either y or n. Answer is either 121 or +110, which are the char values for y & n respectively +SUCCESS is t when user-input is correct, else nil" + (let ((answer (if (equal answer 121) "y" "n"))) + (with-gnosis-buffer + (insert + (concat "\n\n" + (propertize "Answer:" 'face 'gnosis-face-directions) + " " + (propertize answer 'face (if success 'gnosis-face-correct 'gnosis-face-false))))))) + + (defun gnosis-display--hint (hint) "Display HINT." (with-gnosis-buffer @@ -535,6 +550,35 @@ Refer to `gnosis-add-note--double' for more." :extra (read-string "Extra: ") :tags (gnosis-tag-prompt))))) +(cl-defun gnosis-add-note--y-or-n (&key deck question hint answer extra (image nil) tags (suspend 0) (second-image nil)) + "Add y-or-n type note. + +DECK: Deck name for note. +QUESTION: Quesiton to display for note. +ANSWER: Answer for QUESTION, either `121' (char value for yes) or `110' + (char value for no). +HINT: Hint to display during review, before user-input. +EXTRA: Extra information to display after user-input/giving an answer. +IMAGE: Image to display before user-input. +TAGS: Tags used to organize notes +SUSSPEND: Binary value of 0 & 1, when 1 note will be ignored. +SECOND-IMAGE: Image to display after user-input." + (gnosis-add-note-fields deck "y-or-n" question hint answer extra tags suspend image second-image)) + +(defun gnosis-add-note-y-or-n () + "Add note(s) of type `y-or-n' interactively to selected deck. + +refer to `gnosis-add-note--y-or-n' for more information about keyword values." + (let ((deck (gnosis--get-deck-name))) + (while (y-or-n-p (format "Add note of type `y-or-n' to `%s' deck? " deck)) + (gnosis-add-note--y-or-n :deck deck + :question (read-string "Question: ") + :answer (read-char-choice "Answer: [y] or [n]? " '(?y ?n)) + :hint (read-string "Hint: ") + :extra (read-string "Extra: ") + :tags (gnosis-tag-prompt))))) + + (cl-defun gnosis-add-note--cloze (&key deck note hint tags (suspend 0) extra (image nil) (second-image nil)) "Add cloze type note. @@ -609,7 +653,7 @@ See `gnosis-add-note--cloze' for more reference." ;;;###autoload (defun gnosis-add-note (type) "Create note(s) as TYPE interactively." - (interactive (list (completing-read "Type: " '(MCQ Cloze Basic Double) nil t))) + (interactive (list (completing-read "Type: " '(MCQ Cloze Basic Double y-or-n) nil t))) (when gnosis-testing (unless (y-or-n-p "You are using a testing environment! Continue?") (error "Aborted"))) @@ -618,6 +662,7 @@ See `gnosis-add-note--cloze' for more reference." ("Cloze" (gnosis-add-note-cloze)) ("Basic" (gnosis-add-note-basic)) ("Double" (gnosis-add-note-double)) + ("y-or-n" (gnosis-add-note-y-or-n)) (_ (message "No such type.")))) (defun gnosis-mcq-answer (id) @@ -888,6 +933,19 @@ SUCCESS is a binary value, 1 is for successful review." (gnosis-review--update id (if success 1 0)) (gnosis-display--next-review id))) +(defun gnosis-review-y-or-p (id) + "Review y-or-n type note for ID." + (gnosis-display--image id) + (gnosis-display--question id) + (gnosis-display--hint (gnosis-get 'options 'notes `(= id ,id))) + (let* ((answer (gnosis-get 'answer 'notes `(= id ,id))) + (user-input (read-char-choice "[y]es or [n]o: " '(?y ?n))) + (success (equal answer user-input))) + (gnosis-display-y-or-n-answer :answer answer :success success :user-input user-input) + (gnosis-display--extra id) + (gnosis-review--update id (if success 1 0)) + (gnosis-display--next-review id))) + (defun gnosis-review-cloze--input (cloze) "Prompt for user input during cloze review. @@ -941,6 +999,7 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." ("mcq" (gnosis-review-mcq id)) ("basic" (gnosis-review-basic id)) ("cloze" (gnosis-review-cloze id)) + ("y-or-n" (gnosis-review-y-or-p id)) (_ (error "Malformed note type"))))))) (defun gnosis-review-commit (note-num) @@ -1073,6 +1132,9 @@ changes." (kill-buffer) (exit-recursive-edit)) +(defvar-keymap gnosis-edit-mode-map + :doc "gnosis-edit keymap" + "C-c C-c" #'gnosis-edit-save-exit) (define-derived-mode gnosis-edit-mode emacs-lisp-mode "Gnosis EDIT" "Gnosis Edit Mode." @@ -1080,10 +1142,6 @@ changes." :lighter " gnosis-edit-mode" :keymap gnosis-edit-mode-map) -(defvar-keymap gnosis-edit-mode-map - :doc "gnosis-edit keymap" - "C-c C-c" #'gnosis-edit-save-exit) - (cl-defun gnosis-edit-update-note (&key id main options answer tags (extra-notes nil) (image nil) (second-image nil)) "Update note with id value of ID. |