diff options
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | doc/gnosis.info | 104 | ||||
-rw-r--r-- | doc/gnosis.org | 26 | ||||
-rw-r--r-- | doc/gnosis.texi | 54 | ||||
-rw-r--r-- | gnosis-algorithm.el | 2 | ||||
-rw-r--r-- | gnosis-dev.el | 6 | ||||
-rw-r--r-- | gnosis.el | 178 |
7 files changed, 241 insertions, 149 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ee28ad --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.POSIX: +.PHONY: all doc clean +.SUFFIXES: .el .elc + +EMACS = emacs +ORG := doc/gnosis.org +TEXI := doc/gnosis.texi +INFO := doc/gnosis.info + + +all: doc + +doc: $(ORG) + $(EMACS) --batch \ + --load org \ + --eval "(with-current-buffer (find-file \"$(ORG)\") (org-texinfo-export-to-texinfo) (org-texinfo-export-to-info) (save-buffer))" \ + --kill + +clean: + rm -f $(TEXI) $(INFO) diff --git a/doc/gnosis.info b/doc/gnosis.info index ddae27d..a96d4c1 100644 --- a/doc/gnosis.info +++ b/doc/gnosis.info @@ -15,7 +15,7 @@ Gnosis (γνῶσις), pronounced "noh-sis", _meaning knowledge in Greek_, is a spaced repetition system implementation for note taking and self testing. -This manual is written for Gnosis version 0.1.4, released on 2023-01-19. +This manual is written for Gnosis version 0.1.5, released on 2023-01-29. • Official manual: <https://thanosapollo.org/user-manual/gnosis> • Git repositories: @@ -28,7 +28,7 @@ This manual is written for Gnosis version 0.1.4, released on 2023-01-19. * Installation:: * Adding notes:: * Note Types:: -* Customization & Development:: +* Customization & Extension:: -- The Detailed Node Listing -- @@ -45,8 +45,9 @@ Note Types * MCQ (Multiple Choice Question):: * y-or-n:: -Customization & Development +Customization & Extension +* Adjust string comparison:: * Creating Custom Note Types:: * Customizing Gnosis Algorithm:: @@ -102,8 +103,8 @@ following emacs lisp snippet: (straight-use-package '(gnosis :type git - :host nil - :repo "https://git.thanosapollo.org/gnosis")) + :host nil + :repo "https://git.thanosapollo.org/gnosis")) File: gnosis.info, Node: Installing manually from source, Prev: Using straightel, Up: Installation @@ -138,13 +139,13 @@ gnosis-add-note’ Example: (gnosis-add-note--basic :deck "DECK-NAME" - :question "Your Question" - :answer "Answer" - :hint "hint" - :extra "Explanation" - :image "Image displayed before user-input" ;; Optional - :second-image "Image displayed after user-input" ;; Optional - :tags '("tag1" "tag2")) + :question "Your Question" + :answer "Answer" + :hint "hint" + :extra "Explanation" + :image "Image displayed before user-input" ;; Optional + :second-image "Image displayed after user-input" ;; Optional + :tags '("tag1" "tag2")) By default, the value of image and second image is nil. Their value must a string, the path of an image, from inside ‘gnosis-images-dir’. @@ -164,7 +165,7 @@ all the logic. to know when creating new notes. -File: gnosis.info, Node: Note Types, Next: Customization & Development, Prev: Adding notes, Up: Top +File: gnosis.info, Node: Note Types, Next: Customization & Extension, Prev: Adding notes, Up: Top 4 Note Types ************ @@ -254,10 +255,10 @@ the ANSWER must be either 121 (‘y’) or 110 (‘n’), as those correspond to the character values used to represent them. -File: gnosis.info, Node: Customization & Development, Prev: Note Types, Up: Top +File: gnosis.info, Node: Customization & Extension, Prev: Note Types, Up: Top -5 Customization & Development -***************************** +5 Customization & Extension +*************************** To make development and customization easier, gnosis comes with ‘gnosis-dev’ module, that should be used to create a custom database for @@ -272,13 +273,35 @@ enter ‘n’ (no) at the prompt "Start development env?" * Menu: +* Adjust string comparison:: * Creating Custom Note Types:: * Customizing Gnosis Algorithm:: -File: gnosis.info, Node: Creating Custom Note Types, Next: Customizing Gnosis Algorithm, Up: Customization & Development +File: gnosis.info, Node: Adjust string comparison, Next: Creating Custom Note Types, Up: Customization & Extension -5.1 Creating Custom Note Types +5.1 Adjust string comparison +============================ + +You may adjust ‘gnosis-string-difference’, this is a threshold value for +string comparison that determines the maximum acceptable Levenshtein +distance between two strings, which identifies their similarity + + Let's illustrate with an example: + (setf gnosis-string-difference 1) + + In this scenario, we set 'gnosis-string-difference' to 1. This +implies that two strings will be recognized as similar if they exhibit a +difference of at most one character edit. + + To demonstrate, 'example' and 'examples' will be recognized as +similar, considering that the latter involves just one additional +character." + + +File: gnosis.info, Node: Creating Custom Note Types, Next: Customizing Gnosis Algorithm, Prev: Adjust string comparison, Up: Customization & Extension + +5.2 Creating Custom Note Types ============================== Creating custom note types for gnosis is a fairly simple thing to do @@ -308,9 +331,9 @@ should be done. ‘gnosis-display’ functions -File: gnosis.info, Node: Customizing Gnosis Algorithm, Prev: Creating Custom Note Types, Up: Customization & Development +File: gnosis.info, Node: Customizing Gnosis Algorithm, Prev: Creating Custom Note Types, Up: Customization & Extension -5.2 Customizing Gnosis Algorithm +5.3 Customizing Gnosis Algorithm ================================ * Menu: @@ -322,7 +345,7 @@ File: gnosis.info, Node: Customizing Gnosis Algorithm, Prev: Creating Custom N File: gnosis.info, Node: Gnosis Algorithm Initial Interval, Next: Gnosis Algorithm Easiness Factor, Up: Customizing Gnosis Algorithm -5.2.1 Gnosis Algorithm Initial Interval +5.3.1 Gnosis Algorithm Initial Interval --------------------------------------- ‘gnosis-algorithm-interval’ is a list of 2 numbers, representing the @@ -339,7 +362,7 @@ again, the next review will be after 3 days. File: gnosis.info, Node: Gnosis Algorithm Easiness Factor, Next: Gnosis Algorithm Forgetting Factor, Prev: Gnosis Algorithm Initial Interval, Up: Customizing Gnosis Algorithm -5.2.2 Gnosis Algorithm Easiness Factor +5.3.2 Gnosis Algorithm Easiness Factor -------------------------------------- ‘gnosis-algorithm-ef’ is a list that consists of 3 items. @@ -366,7 +389,7 @@ increase-factor as well. File: gnosis.info, Node: Gnosis Algorithm Forgetting Factor, Prev: Gnosis Algorithm Easiness Factor, Up: Customizing Gnosis Algorithm -5.2.3 Gnosis Algorithm Forgetting Factor +5.3.3 Gnosis Algorithm Forgetting Factor ---------------------------------------- ‘gnosis-algorithm-ff’ is a floating number below 1. @@ -385,23 +408,24 @@ upon an unsuccessful review the next interval will be 6 * 0.5 Tag Table: Node: Top246 -Node: Introduction1372 -Node: Installation1852 -Node: Using straightel2221 -Node: Installing manually from source2737 -Node: Adding notes3426 -Node: Note Types4856 -Node: Cloze5082 -Node: Basic Type6055 -Node: Double6333 -Node: MCQ (Multiple Choice Question)6679 -Node: y-or-n7088 -Node: Customization & Development7514 -Node: Creating Custom Note Types8195 -Node: Customizing Gnosis Algorithm9299 -Node: Gnosis Algorithm Initial Interval9617 -Node: Gnosis Algorithm Easiness Factor10208 -Node: Gnosis Algorithm Forgetting Factor11212 +Node: Introduction1397 +Node: Installation1877 +Node: Using straightel2246 +Node: Installing manually from source2758 +Node: Adding notes3447 +Node: Note Types4863 +Node: Cloze5087 +Node: Basic Type6060 +Node: Double6338 +Node: MCQ (Multiple Choice Question)6684 +Node: y-or-n7093 +Node: Customization & Extension7519 +Node: Adjust string comparison8223 +Node: Creating Custom Note Types9019 +Node: Customizing Gnosis Algorithm10154 +Node: Gnosis Algorithm Initial Interval10470 +Node: Gnosis Algorithm Easiness Factor11061 +Node: Gnosis Algorithm Forgetting Factor12065 End Tag Table diff --git a/doc/gnosis.org b/doc/gnosis.org index 28b9cf9..29c4188 100644 --- a/doc/gnosis.org +++ b/doc/gnosis.org @@ -4,9 +4,9 @@ #+language: en #+options: ':t toc:nil author:t email:t num:t #+startup: content -#+macro: stable-version 0.1.4 -#+macro: release-date 2023-01-19 -#+macro: development-version 0.1.4-dev +#+macro: stable-version 0.1.5 +#+macro: release-date 2023-01-29 +#+macro: development-version 0.1.6-dev #+macro: file @@texinfo:@file{@@$1@@texinfo:}@@ #+macro: space @@texinfo:@: @@ #+macro: kbd @@texinfo:@kbd{@@$1@@texinfo:}@@ @@ -175,7 +175,7 @@ When using the hidden function =gnosis-add-note--y-or-n=, note that the ANSWER must be either 121 (~y~) or 110 (~n~), as those correspond to the character values used to represent them. -* Customization & Development +* Customization & Extension To make development and customization easier, gnosis comes with =gnosis-dev= module, that should be used to create a custom database for @@ -187,6 +187,24 @@ database. To exit the testing environment, rerun =M-x gnosis-dev-test= and then enter =n= (no) at the prompt "Start development env?" +** Adjust string comparison +You may adjust =gnosis-string-difference=, this is a threshold value +for string comparison that determines the maximum acceptable +Levenshtein distance between two strings, which identifies their +similarity + +Let's illustrate with an example: +#+begin_src emacs-lisp +(setf gnosis-string-difference 1) +#+end_src + +In this scenario, we set `gnosis-string-difference` to 1. This implies +that two strings will be recognized as similar if they exhibit a +difference of at most one character edit. + +To demonstrate, 'example' and 'examples' will be recognized as +similar, considering that the latter involves just one additional +character." ** Creating Custom Note Types Creating custom note types for gnosis is a fairly simple thing to do diff --git a/doc/gnosis.texi b/doc/gnosis.texi index 9054e3f..f2762af 100644 --- a/doc/gnosis.texi +++ b/doc/gnosis.texi @@ -30,7 +30,7 @@ a spaced repetition system implementation for note taking and self testing. @noindent -This manual is written for Gnosis version 0.1.4, released on 2023-01-19. +This manual is written for Gnosis version 0.1.5, released on 2023-01-29. @itemize @item @@ -46,7 +46,6 @@ sourcehut (mirror): @uref{https://git.sr.ht/~thanosapollo/gnosis} @end itemize @insertcopying - @end ifnottex @menu @@ -54,7 +53,7 @@ sourcehut (mirror): @uref{https://git.sr.ht/~thanosapollo/gnosis} * Installation:: * Adding notes:: * Note Types:: -* Customization & Development:: +* Customization & Extension:: @detailmenu --- The Detailed Node Listing --- @@ -72,8 +71,9 @@ Note Types * MCQ (Multiple Choice Question):: * y-or-n:: -Customization & Development +Customization & Extension +* Adjust string comparison:: * Creating Custom Note Types:: * Customizing Gnosis Algorithm:: @@ -123,8 +123,8 @@ following emacs lisp snippet: @lisp (straight-use-package '(gnosis :type git - :host nil - :repo "https://git.thanosapollo.org/gnosis")) + :host nil + :repo "https://git.thanosapollo.org/gnosis")) @end lisp @node Installing manually from source @@ -164,13 +164,13 @@ Example: @lisp (gnosis-add-note--basic :deck "DECK-NAME" - :question "Your Question" - :answer "Answer" - :hint "hint" - :extra "Explanation" - :image "Image displayed before user-input" ;; Optional - :second-image "Image displayed after user-input" ;; Optional - :tags '("tag1" "tag2")) + :question "Your Question" + :answer "Answer" + :hint "hint" + :extra "Explanation" + :image "Image displayed before user-input" ;; Optional + :second-image "Image displayed after user-input" ;; Optional + :tags '("tag1" "tag2")) @end lisp By default, the value of image and second image is nil. Their value @@ -270,8 +270,8 @@ When using the hidden function @samp{gnosis-add-note--y-or-n}, note that the ANSWER must be either 121 (@code{y}) or 110 (@code{n}), as those correspond to the character values used to represent them. -@node Customization & Development -@chapter Customization & Development +@node Customization & Extension +@chapter Customization & Extension To make development and customization easier, gnosis comes with @samp{gnosis-dev} module, that should be used to create a custom database for @@ -285,10 +285,32 @@ To exit the testing environment, rerun @samp{M-x gnosis-dev-test} and then enter @samp{n} (no) at the prompt ``Start development env?'' @menu +* Adjust string comparison:: * Creating Custom Note Types:: * Customizing Gnosis Algorithm:: @end menu +@node Adjust string comparison +@section Adjust string comparison + +You may adjust @samp{gnosis-string-difference}, this is a threshold value +for string comparison that determines the maximum acceptable +Levenshtein distance between two strings, which identifies their +similarity + +Let's illustrate with an example: +@lisp +(setf gnosis-string-difference 1) +@end lisp + +In this scenario, we set `gnosis-string-difference` to 1. This implies +that two strings will be recognized as similar if they exhibit a +difference of at most one character edit. + +To demonstrate, 'example' and 'examples' will be recognized as +similar, considering that the latter involves just one additional +character.`` + @node Creating Custom Note Types @section Creating Custom Note Types @@ -398,4 +420,4 @@ Example: For a note with a value of last-interval of 6 days and a ff of 0.5, upon an unsuccessful review the next interval will be 6 * 0.5 -@bye +@bye
\ No newline at end of file diff --git a/gnosis-algorithm.el b/gnosis-algorithm.el index 0dc2579..46a2abe 100644 --- a/gnosis-algorithm.el +++ b/gnosis-algorithm.el @@ -7,8 +7,6 @@ ;; URL: https://git.thanosapollo.org/gnosis ;; Version: 0.0.1 -;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2")) - ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or diff --git a/gnosis-dev.el b/gnosis-dev.el index 6801290..d93dc87 100644 --- a/gnosis-dev.el +++ b/gnosis-dev.el @@ -110,12 +110,12 @@ by the thoracodorsal nerve." If ask nil, leave development env" (interactive) (let ((ask (y-or-n-p "Start development env (n for exit)?")) - (testing-dir (concat gnosis-dir "/testing"))) + (testing-dir (concat gnosis-dir "testing"))) (if ask (progn (unless (file-exists-p testing-dir) (make-directory testing-dir)) - (setf gnosis-db (emacsql-sqlite (concat testing-dir "/testing.db"))) + (setf gnosis-db (emacsql-sqlite-open (expand-file-name "testing.db" testing-dir))) (setf gnosis-testing t) (dolist (table '(notes decks review review-log extras)) (condition-case nil @@ -125,7 +125,7 @@ If ask nil, leave development env" (gnosis-dev-add-fields) (message "Adding testing values...") (message "Development env is ready for testing.")) - (setf gnosis-db (emacsql-sqlite (concat (file-name-as-directory gnosis-dir) "gnosis.db"))) + (setf gnosis-db (emacsql-sqlite-open (expand-file-name "gnosis.db" gnosis-dir))) (setf gnosis-testing nil) (message "Exited development env.")))) @@ -5,7 +5,7 @@ ;; Author: Thanos Apollo <[email protected]> ;; Keywords: extensions ;; URL: https://git.thanosapollo.org/gnosis -;; Version: 0.1.0-alpha +;; Version: 0.1.5 ;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2") (emacsql "20230228")) @@ -66,6 +66,14 @@ :type 'string :group 'gnosis) +(defcustom gnosis-string-difference 1 + "Threshold value for string comparison in Gnosis. + +This variable determines the maximum acceptable Levenshtein distance +between two strings to consider them as similar." + :type 'integer + :group 'gnosis) + (defvar gnosis-images-dir (expand-file-name "images" gnosis-dir) "Gnosis images directory.") @@ -74,7 +82,7 @@ (make-directory gnosis-images-dir)) (defconst gnosis-db - (emacsql-sqlite (expand-file-name "gnosis.db" gnosis-dir)) + (emacsql-sqlite-open (expand-file-name "gnosis.db" gnosis-dir)) "Gnosis database file.") (defvar gnosis-testing nil @@ -174,7 +182,7 @@ Example: (emacsql gnosis-db `[:update ,table :set ,value :where ,where])) (cl-defun gnosis-get (value table &optional (restrictions '1=1)) - "Return VALUE from TABLE, optionally with where RESTRICTIONS." + "Return caar of VALUE from TABLE, optionally with where RESTRICTIONS." (caar (gnosis-select value table restrictions))) (defun gnosis-get-note-tags (id) @@ -196,7 +204,7 @@ OPTIONS is a list of strings. INFO is a list of strings, which will be displayed as additional info for option FACE-FOR-INFO is the face used to display info for option." (let* ((choices (cl-mapcar 'cons options info)) - (max-choice-length (apply 'max (mapcar 'length options))) + (max-choice-length (apply #'max (mapcar #'length options))) (formatted-choices (mapcar (lambda (choice) (cons (concat (format "%s" (car choice)) @@ -217,33 +225,30 @@ FACE-FOR-INFO is the face used to display info for option." (defun gnosis-display-question (id) "Display main row for note ID." (let ((question (gnosis-get 'main 'notes `(= id ,id)))) - (erase-buffer) - (fill-paragraph (insert (concat "\n" - (propertize question 'face 'gnosis-face-main)))))) + (erase-buffer) + (fill-paragraph (insert "\n" (propertize question 'face 'gnosis-face-main))))) (defun gnosis-display-cloze-sentence (sentence clozes) "Display cloze sentence for SENTENCE with CLOZES." (erase-buffer) (fill-paragraph - (insert - (concat "\n" - (gnosis-cloze-replace-words sentence clozes (propertize gnosis-cloze-string 'face 'gnosis-face-cloze)))))) + (insert "\n" + (gnosis-cloze-replace-words sentence clozes (propertize gnosis-cloze-string 'face 'gnosis-face-cloze))))) (defun gnosis-display-basic-answer (answer success user-input) "Display ANSWER. When SUCCESS nil, display USER-INPUT as well" - (insert - (concat "\n\n" - (propertize "Answer:" 'face 'gnosis-face-directions) + (insert "\n\n" + (propertize "Answer:" 'face 'gnosis-face-directions) + " " + (propertize answer 'face 'gnosis-face-correct)) + ;; Insert user wrong answer + (when (not success) + (insert "\n" + (propertize "Your answer:" 'face 'gnosis-face-directions) " " - (propertize answer 'face 'gnosis-face-correct))) - ;; Insert user wrong answer - (when (not success) - (insert (concat "\n" - (propertize "Your answer:" 'face 'gnosis-face-directions) - " " - (propertize user-input 'face 'gnosis-face-false))))) + (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. @@ -252,60 +257,60 @@ 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"))) - (insert - (concat "\n\n" - (propertize "Answer:" 'face 'gnosis-face-directions) - " " - (propertize answer 'face (if success 'gnosis-face-correct 'gnosis-face-false)))))) + (insert + "\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." - (goto-char (point-max)) - (insert (concat - (propertize "\n\n-----\n" 'face 'gnosis-face-seperator) - (propertize hint 'face 'gnosis-face-hint)))) + (goto-char (point-max)) + (insert + (propertize "\n\n-----\n" 'face 'gnosis-face-seperator) + (propertize hint 'face 'gnosis-face-hint))) (cl-defun gnosis-display-cloze-reveal (&key (cloze-char gnosis-cloze-string) replace (success t) (face nil)) "Replace CLOZE-CHAR with REPLACE. If FACE nil, propertize replace using `gnosis-face-correct', or `gnosis-face-false' when (not SUCCESS). Else use FACE value." - (goto-char (point-min)) - (search-forward cloze-char nil t) - (replace-match (propertize replace 'face (if (not face) - (if success 'gnosis-face-correct 'gnosis-face-false) - face)))) + (goto-char (point-min)) + (search-forward cloze-char nil t) + (replace-match (propertize replace 'face (if (not face) + (if success 'gnosis-face-correct 'gnosis-face-false) + face)))) (cl-defun gnosis-display-cloze-user-answer (user-input &optional (false t)) "Display USER-INPUT answer for cloze note upon failed review. If FALSE t, use gnosis-face-false face" - (goto-char (point-max)) - (insert (concat "\n\n" - (propertize "Your answer:" 'face 'gnosis-face-directions) - " " - (propertize user-input 'face (if false 'gnosis-face-false 'gnosis-face-correct))))) + (goto-char (point-max)) + (insert "\n\n" + (propertize "Your answer:" 'face 'gnosis-face-directions) + " " + (propertize user-input 'face (if false 'gnosis-face-false 'gnosis-face-correct)))) (defun gnosis-display-correct-answer-mcq (answer user-choice) "Display correct ANSWER & USER-CHOICE for MCQ note." - (insert (concat "\n\n" - (propertize "Correct Answer:" 'face 'gnosis-face-directions) - " " - (propertize answer 'face 'gnosis-face-correct) - "\n" - (propertize "Your answer:" 'face 'gnosis-face-directions) - " " - (propertize user-choice 'face (if (string= answer user-choice) - 'gnosis-face-correct - 'gnosis-face-false))))) + (insert "\n\n" + (propertize "Correct Answer:" 'face 'gnosis-face-directions) + " " + (propertize answer 'face 'gnosis-face-correct) + "\n" + (propertize "Your answer:" 'face 'gnosis-face-directions) + " " + (propertize user-choice 'face (if (string= answer user-choice) + 'gnosis-face-correct + 'gnosis-face-false)))) (defun gnosis-display-extra (id) "Display extra information for note ID." (let ((extras (gnosis-get 'extra-notes 'extras `(= id ,id)))) (goto-char (point-max)) (insert (propertize "\n\n-----\n" 'face 'gnosis-face-seperator)) - (fill-paragraph (insert (concat "\n" (propertize extras 'face 'gnosis-face-extra)))))) + (fill-paragraph (insert "\n" (propertize extras 'face 'gnosis-face-extra))))) (defun gnosis-display-image (id) "Display image for note ID." @@ -320,10 +325,10 @@ If FALSE t, use gnosis-face-false face" "Display next interval for note ID." (let ((interval (gnosis-get 'next-rev 'review-log `(= id ,id)))) (goto-char (point-max)) - (insert (concat "\n\n" - (propertize "Next review:" 'face 'gnosis-face-directions) - " " - (propertize (format "%s" interval) 'face 'gnosis-face-next-review))))) + (insert "\n\n" + (propertize "Next review:" 'face 'gnosis-face-directions) + " " + (propertize (format "%s" interval) 'face 'gnosis-face-next-review)))) (cl-defun gnosis--prompt (prompt &optional (downcase nil) (split nil)) "PROMPT user for input until `q' is given. @@ -713,8 +718,10 @@ Valid cloze formats include: "Compare STR1 and STR2. Compare 2 strings, ignoring case and whitespace." - (string= (downcase (replace-regexp-in-string "\\s-" "" str1)) - (downcase (replace-regexp-in-string "\\s-" "" str2)))) + (<= (string-distance (downcase (replace-regexp-in-string "\\s-" "" str1)) + (downcase (replace-regexp-in-string "\\s-" "" str2))) + gnosis-string-difference)) + (defun gnosis-directory-files (&optional dir regex) "Return a list of file paths, relative to DIR directory. @@ -904,20 +911,20 @@ SUCCESS is a binary value, 1 is for successful review." (defun gnosis-review-mcq (id) "Display multiple choice answers for question ID." - (gnosis-display-image id) - (gnosis-display-question id) - (let* ((choices (gnosis-get 'options 'notes `(= id ,id))) - (answer (nth (- (gnosis-get 'answer 'notes `(= id ,id)) 1) choices)) - (user-choice (gnosis-mcq-answer id))) - (if (string= answer user-choice) - (progn - (gnosis-review--update id 1) - (message "Correct!")) - (gnosis-review--update id 0) - (message "False")) - (gnosis-display-correct-answer-mcq answer user-choice) - (gnosis-display-extra id) - (gnosis-display-next-review id))) + (gnosis-display-image id) + (gnosis-display-question id) + (let* ((choices (gnosis-get 'options 'notes `(= id ,id))) + (answer (nth (- (gnosis-get 'answer 'notes `(= id ,id)) 1) choices)) + (user-choice (gnosis-mcq-answer id))) + (if (string= answer user-choice) + (progn + (gnosis-review--update id 1) + (message "Correct!")) + (gnosis-review--update id 0) + (message "False")) + (gnosis-display-correct-answer-mcq answer user-choice) + (gnosis-display-extra id) + (gnosis-display-next-review id))) (defun gnosis-review-basic (id) "Review basic type note for ID." @@ -934,16 +941,16 @@ SUCCESS is a binary value, 1 is for successful review." (defun gnosis-review-y-or-n (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) - (gnosis-display-extra id) - (gnosis-review--update id (if success 1 0)) - (gnosis-display-next-review 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) + (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. @@ -1024,7 +1031,9 @@ NOTE-NUM: The number of notes reviewed in the session." (message "Review session finished. %d notes reviewed." note-num))) (defun gnosis-review--session (notes) - "Start review session for NOTES." + "Start review session for NOTES. + +NOTES: List of note ids" (let ((note-count 0)) (if (null notes) (message "No notes for review.") @@ -1118,7 +1127,7 @@ changes." (image ,image) (second-image ,second-image)) do (cond ((eq field 'id) - (insert (format (concat ":%s " (propertize "%s" 'read-only t) "\n") field value))) + (insert (format ":id %s \n" (propertize (number-to-string value) 'read-only t)))) ((numberp value) (insert (format ":%s %s\n" field value))) ((and (listp value) @@ -1230,7 +1239,7 @@ to improve readability." (insert (format ":%s %s\n" field value))) ((listp value) (insert (format ":%s %s\n" field (format "%s" (cl-loop for item in value - collect (format "\"%s\"" item)))))) + collect (format "\"%s\"" item)))))) ((equal value nil) (insert (format ":%s %s\n" field 'nil))) (t (insert (format ":%s \"%s\"\n" field value)) @@ -1322,7 +1331,8 @@ review." (pcase review-type ("Due notes" (gnosis-review--session (gnosis-review-get-due-notes))) ("Due notes of deck" (gnosis-review--session (gnosis-get-deck-due-notes))) - ("Due notes of specified tag(s)" (gnosis-review--session (gnosis-select-by-tag (gnosis-tag-prompt :match t :due t)))) + ("Due notes of specified tag(s)" (gnosis-review--session + (gnosis-select-by-tag (gnosis-tag-prompt :match t :due t)))) ("All notes of tag(s)" (gnosis-review--session (gnosis-select-by-tag (gnosis-tag-prompt :match t))))))) ;;; Database Schemas |