From 7c9a1ad6f27c00f6882171ba17e67a18cb2d8b3a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 14 Jan 2024 13:00:23 +0200 Subject: Add gnosis-add-note--y-or-n & gnosis-add-note-y-or-n Functions to add note type y-or-n, gnosis-add-note--y-or-n is the hidden function that interacts with gnosis-add-note-fields & gnosis-add-note-y-or-n that passes values interactively --- gnosis.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gnosis.el b/gnosis.el index 2659a6e..33562d3 100644 --- a/gnosis.el +++ b/gnosis.el @@ -535,6 +535,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-p' 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. -- cgit v1.2.3 From 64e72d42dcb9db3a2a10b2b1f490eea987604f2d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 14 Jan 2024 13:03:37 +0200 Subject: Add gnosis-display-y-or-n-answer Display answer for note with face depending on the value of success --- gnosis.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gnosis.el b/gnosis.el index 33562d3..d901c24 100644 --- a/gnosis.el +++ b/gnosis.el @@ -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 -- cgit v1.2.3 From e968a3ec3a264ad928720d9f0c2c856604dcda79 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 14 Jan 2024 13:04:23 +0200 Subject: Add gnsois-review-y-or-n & update all other funcs for y-or-n type --- gnosis.el | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gnosis.el b/gnosis.el index d901c24..2ce038e 100644 --- a/gnosis.el +++ b/gnosis.el @@ -570,7 +570,7 @@ SECOND-IMAGE: Image to display after user-input." 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-p' to `%s' deck? " deck)) + (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)) @@ -653,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"))) @@ -662,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) @@ -932,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. @@ -985,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) -- cgit v1.2.3 From 4eb6c4cee963512777869aed0bd1e954b9898f1b Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 14 Jan 2024 13:11:00 +0200 Subject: [fix] Fix gnosis-edit-mode-map Having gnosis-edit-mode-map defined after gnosis-edit-mode does not work, it needs to be defined before --- gnosis.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gnosis.el b/gnosis.el index 2ce038e..f58e851 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1132,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." @@ -1139,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. -- cgit v1.2.3