aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-05 09:25:30 -0500
committerCraig Jennings <c@cjennings.net>2026-05-05 09:25:30 -0500
commit2670384cb90392147054a896d297d808a021e7ce (patch)
treeeb0c8f83a59b515c214cc44f323aa485dfd66270
parent1a89ea4cae26d37f584aa8c4266cb4bb9aaa9a0f (diff)
downloadorg-drill-2670384cb90392147054a896d297d808a021e7ce.tar.gz
org-drill-2670384cb90392147054a896d297d808a021e7ce.zip
refactor: convert spanish-verb 6-way cl-case to alist dispatch
org-drill-present-spanish-verb had a 6-branch cl-case where each branch differed only in two values: which subheading to reveal (Infinitive or English) and which prompt string to show. Inlined into a 50-line block of nearly-identical setq calls. Extracted the (reveal . prompt) pairs into a defconst alist and reduced the dispatcher to a random-pick + apply-pair pattern. Function drops from 51 lines to 14. Existing branch tests still pass — they mock cl-random to a specific index, and the alist's order matches the previous case order.
-rw-r--r--org-drill.el66
1 files changed, 19 insertions, 47 deletions
diff --git a/org-drill.el b/org-drill.el
index 31d5ad8..05a3e8d 100644
--- a/org-drill.el
+++ b/org-drill.el
@@ -3656,54 +3656,26 @@ returns its return value."
;;; Not very interesting, but included to demonstrate how a presentation
;;; function can manipulate which subheading are hidden versus shown.
+(defconst org-drill--spanish-verb-prompts
+ '(("Infinitive" . "Translate this Spanish verb, and conjugate it for the *present* tense.")
+ ("English" . "For the *present* tense, conjugate the Spanish translation of this English verb.")
+ ("Infinitive" . "Translate this Spanish verb, and conjugate it for the *past* tense.")
+ ("English" . "For the *past* tense, conjugate the Spanish translation of this English verb.")
+ ("Infinitive" . "Translate this Spanish verb, and conjugate it for the *future perfect* tense.")
+ ("English" . "For the *future perfect* tense, conjugate the Spanish translation of this English verb."))
+ "Six (REVEAL . PROMPT) pairs for `org-drill-present-spanish-verb'.
+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)
- (let ((prompt nil))
- (org-drill-with-hidden-comments
- (org-drill-with-hidden-cloze-hints
- (org-drill-with-hidden-cloze-text
- (cl-case (cl-random 6)
- ;; PWL 2018-06-22
- ;; As far as I can tell, neither prompt nor reveal-headings
- ;; do anything here. They never seem to appear anyway. But
- ;; this might be because I broke things when cleaning up the
- ;; dynamic binding.
- (0
- (org-drill-hide-all-subheadings-except '("Infinitive"))
- (setq prompt
- (concat "Translate this Spanish verb, and conjugate it "
- "for the *present* tense.")
- ;;reveal-headings '("English" "Present Tense" "Notes")
- ))
- (1
- (org-drill-hide-all-subheadings-except '("English"))
- (setq prompt (concat "For the *present* tense, conjugate the "
- "Spanish translation of this English verb.")
- ;;reveal-headings '("Infinitive" "Present Tense" "Notes")
- ))
- (2
- (org-drill-hide-all-subheadings-except '("Infinitive"))
- (setq prompt (concat "Translate this Spanish verb, and "
- "conjugate it for the *past* tense.")
- ;;reveal-headings '("English" "Past Tense" "Notes")
- ))
- (3
- (org-drill-hide-all-subheadings-except '("English"))
- (setq prompt (concat "For the *past* tense, conjugate the "
- "Spanish translation of this English verb.")
- ;;reveal-headings '("Infinitive" "Past Tense" "Notes")
- ))
- (4
- (org-drill-hide-all-subheadings-except '("Infinitive"))
- (setq prompt (concat "Translate this Spanish verb, and "
- "conjugate it for the *future perfect* tense.")
- ;;reveal-headings '("English" "Future Perfect Tense" "Notes")
- ))
- (5
- (org-drill-hide-all-subheadings-except '("English"))
- (setq prompt (concat "For the *future perfect* tense, conjugate the "
- "Spanish translation of this English verb.")
- ;;reveal-headings '("Infinitive" "Future Perfect Tense" "Notes")
- )))
+ (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)))))))