From 4d9c9fa672ec57551fa8c9d2d25ea60b59dbef52 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 12 Jun 2026 10:12:31 -0500 Subject: 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. --- tests/test-org-drill-config-commands.el | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test-org-drill-config-commands.el b/tests/test-org-drill-config-commands.el index 7d197616..37d1f5c4 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 -- cgit v1.2.3