diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-12 12:45:40 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-12 12:45:40 -0500 |
| commit | 162d52dfc5a401c95dcbb6f5630d4373568a70e6 (patch) | |
| tree | 2a4cbc2822f614a7e6a4a517cfad76125e3e036e /modules | |
| parent | f49a863a0cb75beeb2dbed6ae9b3df245d2336e8 (diff) | |
| download | dotemacs-162d52dfc5a401c95dcbb6f5630d4373568a70e6.tar.gz dotemacs-162d52dfc5a401c95dcbb6f5630d4373568a70e6.zip | |
feat(org-drill): drill any Org file from anywhere
`org-drill` has no fixed home — with `org-drill-scope` left at its default it just drills the current buffer. So the only thing in my config tied to a location was `cj/drill-start`, which forced a pick from `drill-dir`.
`C-; D f` (`cj/drill-this-file`) drills whatever Org buffer is current, so a drill file living anywhere works. It `user-error`s when the buffer isn't an Org buffer.
`C-u C-; D s` (and `C-u C-; D e`) now prompts for the directory to pick from instead of always using `drill-dir`. Bare `C-; D s` is unchanged. I pulled the picking logic into `cj/--drill-files-in`, `cj/--drill-pick-dir`, and `cj/--drill-pick-file` so it's unit-testable. New `tests/test-org-drill-config.el`: 12 ERT tests over those helpers, `cj/drill-this-file`, `cj/drill-start`, and the keymap.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/org-drill-config.el | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/modules/org-drill-config.el b/modules/org-drill-config.el index 2fe49a37..8555d30f 100644 --- a/modules/org-drill-config.el +++ b/modules/org-drill-config.el @@ -3,7 +3,9 @@ ;;; Commentary: ;; ;; Notes: Org-Drill -;; Start out your org-drill with C-d s, then select your file. +;; `C-; D s' picks a flashcard file from `drill-dir' and starts a session; +;; `C-u C-; D s' lets you pick the directory first. `C-; D f' drills +;; whatever Org file is current, so any drill file anywhere works. ;; Capture templates: ;; - "d" for web/EPUB drill captures (uses %i for selected text, %:link for source) @@ -42,20 +44,42 @@ (setq org-drill-use-variable-pitch t) ;; use variable-pitch font for readability (setq org-drill-hide-modeline-during-session t) ;; hide modeline for cleaner display - (defun cj/drill-start () - "Prompt user to pick a drill org file, then start an org-drill session." + (defun cj/--drill-files-in (dir) + "Return the drill Org file names directly inside DIR (no leading dots)." + (directory-files dir nil "^[^.].*\\.org$")) + + (defun cj/--drill-pick-file (dir) + "Prompt for one of the drill Org files in DIR; return its absolute path." + (expand-file-name + (completing-read "Choose flashcard file: " (cj/--drill-files-in dir) nil t) + dir)) + + (defun cj/--drill-pick-dir (other-dir) + "Return the directory to pick drill files from. +With OTHER-DIR non-nil, prompt for one; otherwise use `drill-dir'." + (if other-dir (read-directory-name "Drill files in: ") drill-dir)) + + (defun cj/drill-start (&optional other-dir) + "Pick a drill Org file and start an `org-drill' session. +With a prefix arg OTHER-DIR, prompt for the directory to choose from +instead of the default `drill-dir'." + (interactive "P") + (find-file (cj/--drill-pick-file (cj/--drill-pick-dir other-dir))) + (org-drill)) + + (defun cj/drill-this-file () + "Start an `org-drill' session on the current Org buffer. +Use this to drill any drill file you have open, wherever it lives." (interactive) - (let* ((choices (directory-files drill-dir nil "^[^.].*\\.org$")) - (chosen-drill-file (completing-read "Choose Flashcard File:" choices))) - (find-file (concat drill-dir chosen-drill-file)) - (org-drill))) + (unless (derived-mode-p 'org-mode) + (user-error "Not an Org buffer -- visit a `.org' file first")) + (org-drill)) - (defun cj/drill-edit () - "Prompts the user to pick a drill org file, then opens it for editing." - (interactive) - (let* ((choices (directory-files drill-dir nil "^[^.].*\\.org$")) - (chosen-drill-file (completing-read "Choose Flashcard File:" choices))) - (find-file (concat drill-dir chosen-drill-file)))) + (defun cj/drill-edit (&optional other-dir) + "Pick a drill Org file and open it for editing. +With a prefix arg OTHER-DIR, prompt for the directory instead of `drill-dir'." + (interactive "P") + (find-file (cj/--drill-pick-file (cj/--drill-pick-dir other-dir)))) (defun cj/drill-capture () "Quickly capture a drill question." @@ -75,6 +99,7 @@ (defvar-keymap cj/drill-map :doc "Keymap for org-drill" "s" #'cj/drill-start + "f" #'cj/drill-this-file "e" #'cj/drill-edit "c" #'cj/drill-capture "r" #'cj/drill-refile @@ -84,8 +109,9 @@ (with-eval-after-load 'which-key (which-key-add-key-based-replacements "C-; D" "org-drill menu" - "C-; D s" "start drill" - "C-; D e" "edit drill file" + "C-; D s" "start drill (C-u: pick dir)" + "C-; D f" "drill current file" + "C-; D e" "edit drill file (C-u: pick dir)" "C-; D c" "capture question" "C-; D r" "refile to drill" "C-; D R" "resume drill"))) |
