[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-drill ef79a22735 111/251: Add explain support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/org-drill ef79a22735 111/251: Add explain support |
Date: |
Mon, 17 Jan 2022 18:59:06 -0500 (EST) |
branch: elpa/org-drill
commit ef79a22735d66c2f18b21ec4ad41109ad4675b8e
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Phillip Lord <phillip.lord@russet.org.uk>
Add explain support
It is now possible to add an :explain: tag to an item, which will
display the body of the entry above the current. This allows adding a
single explanation with any number of examples.
---
org-drill.el | 112 +++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 90 insertions(+), 22 deletions(-)
diff --git a/org-drill.el b/org-drill.el
index 9abe2108d6..bdafb4028a 100644
--- a/org-drill.el
+++ b/org-drill.el
@@ -331,6 +331,22 @@ even if their bodies are empty."
:value-type function))
+(defcustom org-drill-card-tags-alist
+ '(("explain" nil org-drill-explain-answer-presenter
+ org-drill-explain-cleaner))
+"Alist associating tags with presentation functions.
+
+The alist is of the form (TAG QUESTION-PRESENTER ANSWER-PRESENTER CLEANER).
+
+When a card with the relevant TAG is tested, QUESTION-PRESENTER
+will be called when the card is displayed to the user,
+ANSWER-PRESENTER will be called with point in the entry when the
+answer is displayed to the user and CLEANER will be called when
+the answer is accepted. In all cases, point will be in the card
+in question when the function is called. All values may be nil in
+which case no function will be called.")
+
+
(defcustom org-drill-scope
'file
"The scope in which to search for drill items when conducting a
@@ -2444,7 +2460,12 @@ later using `org-drill-resume'.
See `org-drill' for more details."
(org-drill-entry-f #'org-drill-reschedule))
-(defun org-drill-entry-f(complete-func)
+(defun org-drill-card-tag-caller (item tag)
+ (funcall
+ (or (nth item (assoc tag org-drill-card-tags-alist))
+ 'ignore)))
+
+(defun org-drill-entry-f (complete-func)
(interactive)
(org-drill-goto-drill-entry-heading)
;;(unless (org-part-of-drill-entry-p)
@@ -2472,27 +2493,38 @@ See `org-drill' for more details."
'org-drill-present-default-answer)
present-empty-cards (third presentation-fn)
presentation-fn (first presentation-fn)))
- (prog1
- (cond
- ((null presentation-fn)
- (message "%s:%d: Unrecognised card type '%s', skipping..."
- (buffer-name) (point) card-type)
- (sit-for 0.5)
- 'skip)
- (t
- (setq cont (funcall presentation-fn))
- (cond
- ((not cont)
- (message "Quit")
- nil)
- ((eql cont 'edit)
- 'edit)
- ((eql cont 'skip)
- 'skip)
- (t
- (save-excursion
- (funcall answer-fn complete-func))))))
- (org-remove-latex-fragment-image-overlays)))))))
+ (let* ((tags (org-get-tags))
+ (rtn
+ (cond
+ ((null presentation-fn)
+ (message "%s:%d: Unrecognised card type '%s', skipping..."
+ (buffer-name) (point) card-type)
+ (sit-for 0.5)
+ 'skip)
+ (t
+ (mapc
+ (apply-partially 'org-drill-card-tag-caller 1)
+ (org-get-tags))
+ (setq cont (funcall presentation-fn))
+ (cond
+ ((not cont)
+ (message "Quit")
+ nil)
+ ((eql cont 'edit)
+ 'edit)
+ ((eql cont 'skip)
+ 'skip)
+ (t
+ (save-excursion
+ (mapc
+ (apply-partially 'org-drill-card-tag-caller 2)
+ (org-get-tags))
+ (funcall answer-fn complete-func))))))))
+ (mapc
+ (apply-partially 'org-drill-card-tag-caller 3)
+ (org-get-tags))
+ (org-remove-latex-fragment-image-overlays)
+ rtn))))))
(defun org-drill-entries-pending-p ()
@@ -3654,6 +3686,42 @@ returns its return value."
(org-drill-hide-subheadings-if 'org-drill-entry-p)))))))
+;; org-drill :explain: implementations
+(defun org-drill-get-parent-entry-text ()
+ "Fetch the text from the parent entry"
+ (save-excursion
+ (save-restriction
+ (widen)
+ (outline-up-heading 1 t)
+ (org-drill-get-entry-text))))
+
+(defvar org-drill-explain-overlay nil)
+
+(defun org-drill-explain-entry-p ()
+ "Returns non-nil if an entry is associated with explanation"
+ (member "explain" (org-get-tags nil t)))
+
+(defun org-drill-end-of-entry-pos ()
+ (save-excursion
+ (org-end-of-subtree)
+ (point)))
+
+(defun org-drill-explain-answer-presenter ()
+ (when org-drill-explain-overlay
+ (delete-overlay org-drill-explain-overlay))
+ (let* ((end (org-drill-end-of-entry-pos))
+ (ov (make-overlay
+ end end
+ (current-buffer))))
+ (overlay-put ov 'after-string
+ (concat "\n\nExplanation:\n\n"
+ (org-drill-get-parent-entry-text)))
+ (setq org-drill-explain-overlay ov)))
+
+(defun org-drill-explain-cleaner ()
+ (when org-drill-explain-overlay
+ (delete-overlay org-drill-explain-overlay)))
+
;;; Leitner Learning
(defvar org-drill-leitner-boxed-entries nil
"All leitner entries that are currently in an active box.")
- [nongnu] elpa/org-drill db7a9c7746 088/251: Added new variable 'org-drill-item-count-includes-failed-items-p'. Default is, (continued)
- [nongnu] elpa/org-drill db7a9c7746 088/251: Added new variable 'org-drill-item-count-includes-failed-items-p'. Default is, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 4f8543a95e 097/251: Added tag 2.5.1 for changeset 7a8df02a7ffc, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill cda03224dc 098/251: Added new card type, "simpletyped". Instead of just pressing space to reveal, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 738b956a16 099/251: Updated version number in header., ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 9c86731452 086/251: During drills, pressing keys for quit, edit and skip now works again., ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill fa03aa7696 087/251: Added tag 2.4.8 for changeset 080a526cc34a, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill a9d3447041 101/251: Reinstated dependency on 'org-learn' library., ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 562baba885 102/251: Added tag 2.6.1 for changeset 586920548547, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill d9ffa4b91f 104/251: Add support for typing in buffer input, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 45e92eca74 109/251: Add org-drill-cram-tree function, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill ef79a22735 111/251: Add explain support,
ELPA Syncer <=
- [nongnu] elpa/org-drill ef9bad812c 112/251: Explain tags now inherit, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 6959903b99 113/251: Explain status of fork, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 507daae5a2 128/251: Remove org-drill-session-qualities, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 0e89d9a638 134/251: Remove more variables, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill a803289de9 137/251: Remove last of earmuff variables, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill df13d89a4c 119/251: Add interactive test functions, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill d37519f54c 147/251: Clean up robot testing, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 9fa9b6eabf 148/251: Robot test all card types, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill 500d1475c3 120/251: Add count entries test, ELPA Syncer, 2022/01/17
- [nongnu] elpa/org-drill c1c57adea9 133/251: Remove dormant-entry-count, ELPA Syncer, 2022/01/17