diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-12 10:12:31 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-12 10:13:28 -0500 |
| commit | 914d4ea036f56518876396ff1aec75d1edb6cf3d (patch) | |
| tree | 79f7842927a6f2e6ef560356d1479f7fd91bbef7 | |
| parent | 936c9fd236024d15c317e2a7fdea419e7eff514e (diff) | |
| download | dotemacs-914d4ea036f56518876396ff1aec75d1edb6cf3d.tar.gz dotemacs-914d4ea036f56518876396ff1aec75d1edb6cf3d.zip | |
fix(org-drill): let-bind org-refile-targets and target real drill files
cj/drill-refile used setq, permanently replacing the session-wide org-refile-targets so every refile anywhere offered only drill targets until restart; and its (drill-dir :maxlevel . 1) entry named a bound variable, which org reads as a directory string rather than a file list, so the drill side yielded nothing. Let-bind org-refile-targets and supply (directory-files drill-dir t "\\.org$") as the file list. The stale test (which asserted the buggy drill-dir spec) is rewritten into two: file-list targets and no global clobber.
| -rw-r--r-- | modules/org-drill-config.el | 7 | ||||
| -rw-r--r-- | tests/test-org-drill-config-commands.el | 27 |
2 files changed, 24 insertions, 10 deletions
diff --git a/modules/org-drill-config.el b/modules/org-drill-config.el index 296b0550a..b2d2a5099 100644 --- a/modules/org-drill-config.el +++ b/modules/org-drill-config.el @@ -95,9 +95,10 @@ With a prefix arg OTHER-DIR, prompt for the directory instead of `drill-dir'." (defun cj/drill-refile () "Refile to a drill file." (interactive) - (setq org-refile-targets '((nil :maxlevel . 1) - (drill-dir :maxlevel . 1))) - (call-interactively 'org-refile)) + (let ((org-refile-targets + `((nil :maxlevel . 1) + (,(directory-files drill-dir t "\\.org$") :maxlevel . 1)))) + (call-interactively 'org-refile))) ;; ------------------------------- Drill Keymap -------------------------------- diff --git a/tests/test-org-drill-config-commands.el b/tests/test-org-drill-config-commands.el index 7d1976164..37d1f5c46 100644 --- a/tests/test-org-drill-config-commands.el +++ b/tests/test-org-drill-config-commands.el @@ -71,21 +71,34 @@ ;;; cj/drill-refile -(ert-deftest test-org-drill-refile-sets-targets-and-delegates () - "Normal: drill-refile narrows `org-refile-targets' to current buffer + -`drill-dir', then dispatches to `org-refile' via `call-interactively'." +(ert-deftest test-org-drill-refile-delegates-with-file-targets () + "Normal: drill-refile dispatches to `org-refile' with current buffer + +the list of drill .org files (not the `drill-dir' variable symbol)." (let (seen-targets called-fn) - (cl-letf (((symbol-function 'call-interactively) + (cl-letf (((symbol-function 'directory-files) + (lambda (&rest _) '("/tmp/cj-drill/a.org" "/tmp/cj-drill/b.org"))) + ((symbol-function 'call-interactively) (lambda (fn) (setq called-fn fn seen-targets org-refile-targets)))) (cj/drill-refile)) (should (eq called-fn 'org-refile)) - (should seen-targets) - ;; Two entries: (nil :maxlevel . 1) and (drill-dir :maxlevel . 1). (should (= 2 (length seen-targets))) (should (assoc nil seen-targets)) - (should (assoc 'drill-dir seen-targets)))) + ;; The drill entry's car is a real list of .org files, never the + ;; `drill-dir' symbol (org reads a bound symbol as the directory string). + (let ((files (car (nth 1 seen-targets)))) + (should (equal files '("/tmp/cj-drill/a.org" "/tmp/cj-drill/b.org"))) + (should-not (eq files 'drill-dir))))) + +(ert-deftest test-org-drill-refile-does-not-clobber-global-targets () + "Error: drill-refile let-binds `org-refile-targets'; the session-wide value +survives the call instead of being permanently replaced." + (let ((org-refile-targets '((sentinel :maxlevel . 9)))) + (cl-letf (((symbol-function 'directory-files) (lambda (&rest _) nil)) + ((symbol-function 'call-interactively) (lambda (_fn) nil))) + (cj/drill-refile)) + (should (equal org-refile-targets '((sentinel :maxlevel . 9)))))) (provide 'test-org-drill-config-commands) ;;; test-org-drill-config-commands.el ends here |
