aboutsummaryrefslogtreecommitdiff
path: root/modules/org-drill-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-24 04:25:24 -0500
committerCraig Jennings <c@cjennings.net>2026-05-24 04:25:24 -0500
commit9c0fc70aa731b016b4805ff701686cebf49ffb96 (patch)
tree3fdc78ab79ad1dcf5ddd9a49a4f82dc9b65a06bc /modules/org-drill-config.el
parentb76c33845e30363187100ee22108946cbeb6a49c (diff)
downloaddotemacs-9c0fc70aa731b016b4805ff701686cebf49ffb96.tar.gz
dotemacs-9c0fc70aa731b016b4805ff701686cebf49ffb96.zip
refactor(org-drill): share one validated drill-file selector
org-capture-config.el and org-drill-config.el each scanned drill-dir with an inline directory-files call, so a missing, empty, or unreadable drill-dir surfaced as a low-level directory-files error or an empty completing-read, depending on which command ran. Added cj/--drill-files-or-error, the single validated entry point: it signals a clear user-error when the directory is missing, unreadable, or has no drill files, and otherwise returns the list. cj/--drill-pick-file and both drill capture templates now route through it. The pure cj/--drill-files-in primitive and its tests are unchanged. Tests cover missing dir, empty dir, a non-org-only dir, and a normal listing.
Diffstat (limited to 'modules/org-drill-config.el')
-rw-r--r--modules/org-drill-config.el15
1 files changed, 14 insertions, 1 deletions
diff --git a/modules/org-drill-config.el b/modules/org-drill-config.el
index 79fdb0276..c3852ed16 100644
--- a/modules/org-drill-config.el
+++ b/modules/org-drill-config.el
@@ -32,10 +32,23 @@
"Return the drill Org file names directly inside DIR (no leading dots)."
(directory-files dir nil "^[^.].*\\.org$"))
+(defun cj/--drill-files-or-error (dir)
+ "Return the drill Org files in DIR, or signal a clear `user-error'.
+Errors when DIR is missing, unreadable, or has no drill files, so callers
+fail with an actionable message instead of a low-level `directory-files'
+error or an empty `completing-read'. This is the single entry point the
+drill commands and the drill capture templates share."
+ (unless (and (file-directory-p dir) (file-readable-p dir))
+ (user-error "Drill directory missing or unreadable: %s" dir))
+ (let ((files (cj/--drill-files-in dir)))
+ (unless files
+ (user-error "No drill files (.org) found in %s" dir))
+ files))
+
(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)
+ (completing-read "Choose flashcard file: " (cj/--drill-files-or-error dir) nil t)
dir))
(defun cj/--drill-pick-dir (other-dir)