diff options
| -rw-r--r-- | org-drill.el | 24 | ||||
| -rw-r--r-- | tests/test-org-drill-prompt-and-misc.el | 53 |
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 |
