summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el69
1 files changed, 47 insertions, 22 deletions
diff --git a/gnosis.el b/gnosis.el
index bbe2d6c..09405c2 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -907,7 +907,7 @@ Refer to `gnosis-add-note--mcq' & `gnosis-prompt-mcq-input' for more."
:correct-answer correct-choice
:extra (gnosis-read-string-from-buffer "Extra" "")
:images (gnosis-select-images)
- :tags (gnosis-prompt-tags--split gnosis-previous-note-tags))))
+ :tags (gnosis-tags-prompt))))
(cl-defun gnosis-add-note--basic (&key deck question hint answer
extra (images nil) (tags) (suspend 0))
@@ -940,7 +940,7 @@ Refer to `gnosis-add-note--basic' for more."
:hint (gnosis-hint-prompt gnosis-previous-note-hint)
:extra (gnosis-read-string-from-buffer "Extra: " "")
:images (gnosis-select-images)
- :tags (gnosis-prompt-tags--split gnosis-previous-note-tags)))
+ :tags (gnosis-tags-prompt)))
(cl-defun gnosis-add-note--double (&key deck question hint answer extra (images nil) tags (suspend 0))
"Add Double type note.
@@ -975,7 +975,7 @@ Refer to `gnosis-add-note--double' for more."
:hint (gnosis-hint-prompt gnosis-previous-note-hint)
:extra (gnosis-read-string-from-buffer "Extra" "")
:images (gnosis-select-images)
- :tags (gnosis-prompt-tags--split gnosis-previous-note-tags)))
+ :tags (gnosis-tags-prompt)))
(cl-defun gnosis-add-note--y-or-n (&key deck question hint answer extra (images nil) tags (suspend 0))
"Add y-or-n type note.
@@ -1011,7 +1011,7 @@ Refer to `gnosis-add-note--y-or-n' for more information about keyword values."
:hint (gnosis-hint-prompt gnosis-previous-note-hint)
:extra (gnosis-read-string-from-buffer "Extra" "")
:images (gnosis-select-images)
- :tags (gnosis-prompt-tags--split gnosis-previous-note-tags)))
+ :tags (gnosis-tags-prompt)))
(cl-defun gnosis-add-note--cloze (&key deck note tags (suspend 0) extra (images nil))
@@ -1094,7 +1094,7 @@ See `gnosis-add-note--cloze' for more reference."
(or (cdr gnosis-cloze-guidance) ""))
:extra (gnosis-read-string-from-buffer "Extra" "")
:images (gnosis-select-images)
- :tags (gnosis-prompt-tags--split gnosis-previous-note-tags)))
+ :tags (gnosis-tags-prompt)))
(cl-defun gnosis-mc-cloze-extract-options (str &optional (char gnosis-mc-cloze-separator))
"Extract options for MC-CLOZE note type from STR.
@@ -1294,12 +1294,14 @@ Optionally, add cusotm PROMPT."
(if (y-or-n-p "Include images?")
(let* ((prompt (or prompt "Select image: "))
(image (if (y-or-n-p "Add review image?")
- (gnosis-completing-read prompt
- (cons nil (gnosis-directory-files gnosis-images-dir)))
+ (gnosis-completing-read
+ prompt
+ (cons nil (gnosis-directory-files gnosis-images-dir)))
nil))
(extra-image (if (y-or-n-p "Add post review image?")
- (gnosis-completing-read prompt
- (cons nil (gnosis-directory-files gnosis-images-dir))))))
+ (gnosis-completing-read
+ prompt
+ (cons nil (gnosis-directory-files gnosis-images-dir))))))
(cons image extra-image))
nil))
@@ -1369,7 +1371,8 @@ MATCH: Require match, t or nil value
DUE: if t, return tags for due notes from `gnosis-due-tags'."
(let ((tags '()))
(cl-loop for tag = (completing-read
- (concat prompt (format " (%s) (q for quit): " (mapconcat #'identity tags " ")))
+ (concat prompt (format " (%s) (q for quit): "
+ (mapconcat #'identity tags " ")))
(cons "q" (if due (gnosis-review-get-due-tags)
(gnosis-get-tags--unique)))
nil t)
@@ -1424,15 +1427,37 @@ Return ((QUESTION CHOICES) CORRECT-CHOICE-INDEX)"
(choices (mapcar (lambda (string) (replace-regexp-in-string "{\\|}" "" string)) input)))
(list (cons stem choices) (+ correct-choice-index 1))))
-(defun gnosis-prompt-tags--split (&optional previous-note-tags)
- "Prompt user for tags, split string by space.
-
-Return a list of tags, split by space. If PREVIOUS-NOTE-TAGS is
-provided, use it as the default value."
- (let* ((previous-note-tags (or nil previous-note-tags))
- (tags (split-string (read-from-minibuffer "Tags: " (mapconcat #'identity previous-note-tags " ")) " ")))
- (setf gnosis-previous-note-tags tags)
- (if (equal tags '("")) '("untagged") tags)))
+(defun gnosis-tags--update (tags)
+ "Update db for TAGS."
+ (cl-loop for tag in tags
+ do (gnosis--insert-into 'tags `[,tag])))
+
+(cl-defun gnosis-tags--prompt (&key (prompt "Tags (seperated by ,): ")
+ (predicate nil)
+ (require-match nil)
+ (initial-input nil))
+ "Prompt user for tags.
+
+Outputs only unique tags."
+ (let* ((tags (gnosis-tags-get-all))
+ (input (delete-dups
+ (completing-read-multiple
+ prompt tags predicate require-match initial-input))))
+ input))
+
+(cl-defun gnosis-tags-prompt ()
+ "Tag prompt for adding notes.
+
+If you only require a tag prompt, refer to `gnosis-tags--prompt'."
+ (let ((input (gnosis-tags--prompt)))
+ (when input
+ (gnosis-tags--update input)
+ (setf gnosis-previous-note-tags input))
+ (or input '("untagged"))))
+
+(defun gnosis-tags-get-all ()
+ "Output all tags from database."
+ (gnosis-select '* 'tags '1=1 t))
;; Collecting note ids
@@ -1456,10 +1481,10 @@ QUERY: String value,"
(gnosis-review-get-due-notes))
;; All notes for tags
((and tags (null due) (null deck))
- (gnosis-select-by-tag (gnosis-tag-prompt)))
+ (gnosis-select-by-tag (gnosis-tags--prompt :require-match t)))
;; All due notes for tags
((and tags due (null deck))
- (gnosis-select-by-tag (gnosis-tag-prompt) t))
+ (gnosis-select-by-tag (gnosis-tags--prompt :require-match t) t))
;; All notes for deck
((and (null tags) (null due) deck)
(gnosis-get-deck-notes deck nil))
@@ -2479,7 +2504,7 @@ to improve readability."
"Update to databse version v4.
Add tags & links tables"
- ;; TODO: Add links
+ ;; TODO: Add links & adjust mcqs
(let ((tags (gnosis-get-tags--unique)))
(pcase-dolist (`(,table ,schema) (seq-filter (lambda (schema)
(member (car schema) '(tags links)))