diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 09:33:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 09:33:34 -0500 |
| commit | 072b59b07545c9fb076c9181d16f7b2971b65421 (patch) | |
| tree | 1471b4f35c42a533bd08e2df56bcb68858cfcce3 | |
| parent | 066cd82302f76f21b3409a00aabe0d8de1d9e34e (diff) | |
| download | org-drill-072b59b07545c9fb076c9181d16f7b2971b65421.tar.gz org-drill-072b59b07545c9fb076c9181d16f7b2971b65421.zip | |
refactor: introduce org-drill-with-card-display macro
Five presenters opened with the same three-deep wrap:
(org-drill-with-hidden-comments
(org-drill-with-hidden-cloze-hints
(org-drill-with-hidden-cloze-text
...body...)))
Combined into org-drill-with-card-display. Five sites
(present-simple-card, present-simple-card-with-typed-answer,
present-two-sided-card, present-multi-sided-card,
present-spanish-verb) lose 2-3 lines of nesting each.
Multicloze-hide-n / hide-nth use a different envelope (only two of
the three wraps; they hide specific clozes by index, not all of
them) so they keep their explicit nesting. Same for
present-card-using-text, which substitutes with-replaced-entry-text
for with-hidden-cloze-text.
| -rw-r--r-- | org-drill.el | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/org-drill.el b/org-drill.el index 4c2bab9..e2563e2 100644 --- a/org-drill.el +++ b/org-drill.el @@ -823,6 +823,16 @@ Returns scope as defined by `org-map-entries'" ,@body) (org-drill-unhide-text)))) +(defmacro org-drill-with-card-display (&rest body) + "Eval BODY in the standard card-display envelope. +Combines `with-hidden-comments', `with-hidden-cloze-hints', and +`with-hidden-cloze-text' — the wrap most card presenters open with." + (declare (debug t) (indent 0)) + `(org-drill-with-hidden-comments + (org-drill-with-hidden-cloze-hints + (org-drill-with-hidden-cloze-text + ,@body)))) + (defun org-drill-days-since-last-review () "Nil means a last review date has not yet been stored for the item. @@ -2170,16 +2180,14 @@ heading, which truncates the search range before the child's body." ;; recall, nil if they chose to quit. (defun org-drill-present-simple-card (session) "Present a simple card." - (org-drill-with-hidden-comments - (org-drill-with-hidden-cloze-hints - (org-drill-with-hidden-cloze-text - (org-drill-hide-all-subheadings-except nil) - (org-drill--show-latex-fragments) ; overlay all LaTeX fragments with images - (ignore-errors - (org-display-inline-images t)) - (org-drill-hide-drawers) - (prog1 (org-drill-presentation-prompt session) - (org-drill-hide-subheadings-if 'org-drill-entry-p)))))) + (org-drill-with-card-display + (org-drill-hide-all-subheadings-except nil) + (org-drill--show-latex-fragments) ; overlay all LaTeX fragments with images + (ignore-errors + (org-display-inline-images t)) + (org-drill-hide-drawers) + (prog1 (org-drill-presentation-prompt session) + (org-drill-hide-subheadings-if 'org-drill-entry-p)))) (defun org-drill-present-default-answer (session reschedule-fn) "Present a default answer. @@ -2214,16 +2222,14 @@ RESCHEDULE-FN is the function to reschedule." (defun org-drill-present-simple-card-with-typed-answer (session) "Present a simple card with a typed answer." - (org-drill-with-hidden-comments - (org-drill-with-hidden-cloze-hints - (org-drill-with-hidden-cloze-text - (org-drill-hide-all-subheadings-except nil) - (org-drill--show-latex-fragments) ; overlay all LaTeX fragments with images - (ignore-errors - (org-display-inline-images t)) - (org-drill-hide-drawers) - (prog1 (org-drill-presentation-prompt-for-string session nil) - (org-drill-hide-subheadings-if 'org-drill-entry-p)))))) + (org-drill-with-card-display + (org-drill-hide-all-subheadings-except nil) + (org-drill--show-latex-fragments) ; overlay all LaTeX fragments with images + (ignore-errors + (org-display-inline-images t)) + (org-drill-hide-drawers) + (prog1 (org-drill-presentation-prompt-for-string session nil) + (org-drill-hide-subheadings-if 'org-drill-entry-p)))) (defun org-drill--show-latex-fragments () "Show LaTeX fragments as inline images. @@ -2236,37 +2242,33 @@ which is the right behavior." (org-latex-preview '(16)))) (defun org-drill-present-two-sided-card (session) - (org-drill-with-hidden-comments - (org-drill-with-hidden-cloze-hints - (org-drill-with-hidden-cloze-text - (let ((drill-sections (org-drill-hide-all-subheadings-except nil))) - (when drill-sections - (save-excursion - (goto-char (nth (cl-random (min 2 (length drill-sections))) - drill-sections)) - (org-fold-show-subtree))) - (org-drill--show-latex-fragments) - (ignore-errors - (org-display-inline-images t)) - (org-drill-hide-drawers) - (prog1 (org-drill-presentation-prompt session) - (org-drill-hide-subheadings-if 'org-drill-entry-p))))))) + (org-drill-with-card-display + (let ((drill-sections (org-drill-hide-all-subheadings-except nil))) + (when drill-sections + (save-excursion + (goto-char (nth (cl-random (min 2 (length drill-sections))) + drill-sections)) + (org-fold-show-subtree))) + (org-drill--show-latex-fragments) + (ignore-errors + (org-display-inline-images t)) + (org-drill-hide-drawers) + (prog1 (org-drill-presentation-prompt session) + (org-drill-hide-subheadings-if 'org-drill-entry-p))))) (defun org-drill-present-multi-sided-card (session) - (org-drill-with-hidden-comments - (org-drill-with-hidden-cloze-hints - (org-drill-with-hidden-cloze-text - (let ((drill-sections (org-drill-hide-all-subheadings-except nil))) - (when drill-sections - (save-excursion - (goto-char (nth (cl-random (length drill-sections)) drill-sections)) - (org-fold-show-subtree))) - (org-drill--show-latex-fragments) - (ignore-errors - (org-display-inline-images t)) - (org-drill-hide-drawers) - (prog1 (org-drill-presentation-prompt session) - (org-drill-hide-subheadings-if 'org-drill-entry-p))))))) + (org-drill-with-card-display + (let ((drill-sections (org-drill-hide-all-subheadings-except nil))) + (when drill-sections + (save-excursion + (goto-char (nth (cl-random (length drill-sections)) drill-sections)) + (org-fold-show-subtree))) + (org-drill--show-latex-fragments) + (ignore-errors + (org-display-inline-images t)) + (org-drill-hide-drawers) + (prog1 (org-drill-presentation-prompt session) + (org-drill-hide-subheadings-if 'org-drill-entry-p))))) (defun org-drill-present-multicloze-hide-n (session number-to-hide @@ -3651,17 +3653,15 @@ Each card-presentation chooses one at random, hiding all subheadings except REVEAL and showing PROMPT in the rating prompt.") (defun org-drill-present-spanish-verb (session) - (org-drill-with-hidden-comments - (org-drill-with-hidden-cloze-hints - (org-drill-with-hidden-cloze-text - (let* ((choice (nth (cl-random (length org-drill--spanish-verb-prompts)) - org-drill--spanish-verb-prompts)) - (reveal (car choice)) - (prompt (cdr choice))) - (org-drill-hide-all-subheadings-except (list reveal)) - (org-drill-hide-drawers) - (prog1 (org-drill-presentation-prompt session prompt) - (org-drill-hide-subheadings-if 'org-drill-entry-p))))))) + (org-drill-with-card-display + (let* ((choice (nth (cl-random (length org-drill--spanish-verb-prompts)) + org-drill--spanish-verb-prompts)) + (reveal (car choice)) + (prompt (cdr choice))) + (org-drill-hide-all-subheadings-except (list reveal)) + (org-drill-hide-drawers) + (prog1 (org-drill-presentation-prompt session prompt) + (org-drill-hide-subheadings-if 'org-drill-entry-p))))) ;; org-drill :explain: implementations (defun org-drill-get-explain-text (&optional existing-text) |
