aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-31 11:18:49 -0500
committerCraig Jennings <c@cjennings.net>2026-05-31 11:18:49 -0500
commite201ba696ed27e407d934321a5f4c5874ea4fee5 (patch)
tree19f2c14bf8ea125d79c4518c3af9ad714a841b5f
parent37df84a462378636f6528970e95187c3a86f8f3e (diff)
downloadorg-drill-e201ba696ed27e407d934321a5f4c5874ea4fee5.tar.gz
org-drill-e201ba696ed27e407d934321a5f4c5874ea4fee5.zip
feat: optionally show the card's outline path in the drill promptHEADmain
A new defcustom org-drill-show-outline-path-during-drill (default off) prepends the card's ancestor path to the mini-buffer prompt, for example [Spanish > Greetings], so during a drill you can see where the current card sits in the deck. With it off the prompt is byte-for-byte unchanged. I ported this from m.galimski's fork (commit c6d0c850) and gated it behind the defcustom rather than leaving it always on. The path comes from org-get-outline-path through a small org-drill--outline-path-string helper. Tests cover the helper (nested and top-level), the prompt with the switch on and off, and the default value.
-rw-r--r--org-drill.el24
-rw-r--r--tests/test-org-drill-prompt-and-misc.el53
2 files changed, 76 insertions, 1 deletions
diff --git a/org-drill.el b/org-drill.el
index 4a8262c..343009d 100644
--- a/org-drill.el
+++ b/org-drill.el
@@ -1986,6 +1986,26 @@ Consider reformulating the item to make it easier to remember.\n"
prompt)
prompt))
+(defcustom org-drill-show-outline-path-during-drill nil
+ "When non-nil, show the card's outline path in the drill prompt.
+The ancestor headings are joined with \" > \" and bracketed, e.g.
+\"[Spanish > Greetings]\", and prepended to the prompt so you can see
+where the current card sits in the deck. Off by default."
+ :group 'org-drill-display
+ :type 'boolean)
+
+(put 'org-drill-show-outline-path-during-drill 'safe-local-variable 'booleanp)
+
+(defun org-drill--outline-path-string ()
+ "Return the outline path of the entry at point, bracketed for the prompt.
+Joins the ancestor headings with \" > \" and wraps them in brackets with a
+trailing space, e.g. \"[Spanish > Greetings] \". Returns the empty string
+when the entry has no ancestors or point is not on a heading."
+ (let ((path (ignore-errors (org-get-outline-path))))
+ (if path
+ (concat "[" (mapconcat #'identity path " > ") "] ")
+ "")))
+
(defun org-drill--make-minibuffer-prompt (session prompt)
"Make a mini-buffer for the SESSION, with PROMPT."
(let ((status (cl-first (org-drill-entry-status session)))
@@ -2027,7 +2047,9 @@ Consider reformulating the item to make it easier to remember.\n"
'face `(:foreground ,org-drill-new-count-color)
'help-echo (concat "The number of new items that you "
"have never reviewed."))
- prompt)))
+ (if org-drill-show-outline-path-during-drill
+ (concat (org-drill--outline-path-string) prompt)
+ prompt))))
(defun org-drill-presentation-prompt (session &optional prompt)
"Create a card prompt with a timer and user-specified menu.
diff --git a/tests/test-org-drill-prompt-and-misc.el b/tests/test-org-drill-prompt-and-misc.el
index 968ad57..5b42f6b 100644
--- a/tests/test-org-drill-prompt-and-misc.el
+++ b/tests/test-org-drill-prompt-and-misc.el
@@ -140,6 +140,59 @@
(org-drill-progress-message 42 50)
(should (string-match-p "42" got-message)))))
+;;;; org-drill outline path in the drill prompt (m.galimski patch)
+
+(ert-deftest test-org-drill--outline-path-string-nested ()
+ "A nested entry yields its ancestor path, bracketed and arrow-joined."
+ (with-temp-buffer
+ (insert "* Spanish\n** Greetings\n*** Hola :drill:\nhola = hello\n")
+ (org-mode)
+ (goto-char (point-min))
+ (search-forward "Hola")
+ (should (equal (org-drill--outline-path-string) "[Spanish > Greetings] "))))
+
+(ert-deftest test-org-drill--outline-path-string-top-level-empty ()
+ "A top-level entry has no ancestors, so the path string is empty."
+ (with-temp-buffer
+ (insert "* Hola :drill:\nhola = hello\n")
+ (org-mode)
+ (goto-char (point-min))
+ (should (equal (org-drill--outline-path-string) ""))))
+
+(ert-deftest test-org-drill--make-minibuffer-prompt-omits-path-by-default ()
+ "With the defcustom off, the outline path is absent from the prompt."
+ (with-temp-buffer
+ (let ((org-startup-folded nil)
+ (org-drill-show-outline-path-during-drill nil))
+ (insert "* Spanish\n** Greetings\n*** Hola :drill:\nhola = hello\n")
+ (org-mode)
+ (goto-char (point-min))
+ (search-forward "Hola")
+ (with-fixed-now
+ (let* ((session (org-drill-session))
+ (prompt (substring-no-properties
+ (org-drill--make-minibuffer-prompt session "test"))))
+ (should-not (string-match-p "Greetings" prompt)))))))
+
+(ert-deftest test-org-drill--make-minibuffer-prompt-shows-path-when-on ()
+ "With the defcustom on, the prompt carries the bracketed outline path."
+ (with-temp-buffer
+ (let ((org-startup-folded nil)
+ (org-drill-show-outline-path-during-drill t))
+ (insert "* Spanish\n** Greetings\n*** Hola :drill:\nhola = hello\n")
+ (org-mode)
+ (goto-char (point-min))
+ (search-forward "Hola")
+ (with-fixed-now
+ (let* ((session (org-drill-session))
+ (prompt (substring-no-properties
+ (org-drill--make-minibuffer-prompt session "test"))))
+ (should (string-match-p "\\[Spanish > Greetings\\]" prompt)))))))
+
+(ert-deftest test-org-drill-show-outline-path-defaults-off ()
+ "The outline-path defcustom ships nil so the prompt is unchanged by default."
+ (should (eq nil (default-value 'org-drill-show-outline-path-during-drill))))
+
(provide 'test-org-drill-prompt-and-misc)
;;; test-org-drill-prompt-and-misc.el ends here