From b2cc4d1645b378043a971906b5ebc34d3c92b544 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 5 May 2026 04:29:28 -0500 Subject: fix: guard org-drill-smart-reschedule cond against nil days-ahead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function takes `days-ahead' as &optional, but the schedule cond called `(= 0 days-ahead)' and `(cl-minusp days-ahead)' before any type-guard, so passing nil crashed with a wrong-type-argument error. Today's two callers (the rating-confirmation flow and the org-drill-relearn-item helper) always pass a number, so this was latent — but a third caller relying on the documented &optional shape would hit it immediately. Switched the cond to require numberp before the value comparisons, and the default branch now falls back to the algorithm-computed next-interval when days-ahead is nil. That matches the intent implied by the optional signature and the docstring. --- org-drill.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/org-drill.el b/org-drill.el index dd210a2..fe99a3f 100644 --- a/org-drill.el +++ b/org-drill.el @@ -1429,15 +1429,20 @@ item will be scheduled exactly this many days into the future." (if (eql 'sm5 org-drill-spaced-repetition-algorithm) (setq org-drill-sm5-optimal-factor-matrix new-ofmatrix)) + ;; Pick the schedule based on days-ahead. The optional arg may be + ;; nil (callers omit it to mean "use the algorithm-computed + ;; next-interval"). The original cond compared `(= 0 days-ahead)' + ;; before any type guard, which crashed on nil. (cond - ((= 0 days-ahead) + ((and (numberp days-ahead) (= 0 days-ahead)) (org-schedule '(4))) - ((cl-minusp days-ahead) + ((and (numberp days-ahead) (cl-minusp days-ahead)) (org-schedule nil (current-time))) (t - (org-schedule nil (time-add (current-time) - (days-to-time - (round next-interval)))))))))) + (let ((interval (if (numberp days-ahead) days-ahead next-interval))) + (org-schedule nil (time-add (current-time) + (days-to-time + (round interval))))))))))) (defun org-drill-hypothetical-next-review-date (quality) "Returns an integer representing the number of days into the future -- cgit v1.2.3