From ffca04d90e94c5d4e40139282811630028d586ce Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 5 May 2026 09:29:01 -0500 Subject: refactor: extract LEECH-warning preamble helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The seven-line propertize+concat block that prepends a red leech warning to the prompt was inlined in three prompt builders: presentation-prompt-in-mini-buffer, presentation-prompt-in-buffer, and presentation-prompt-for-string. Extracted org-drill--maybe-prepend-leech-warning as a single helper the three call. 21 lines duplicated → one definition + three one-line call sites. --- org-drill.el | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/org-drill.el b/org-drill.el index e720d28..34cfe78 100644 --- a/org-drill.el +++ b/org-drill.el @@ -1591,6 +1591,22 @@ the current topic." (lambda () (let ((drill-heading (org-get-heading t))) (not (member drill-heading heading-list)))))) +(defun org-drill--maybe-prepend-leech-warning (prompt) + "Prepend the leech warning to PROMPT when applicable. +The warning appears when `org-drill-leech-method' is `warn' and the +entry at point is a leech. Otherwise PROMPT is returned unchanged. + +Used by the three prompt builders (mini-buffer prompt, in-buffer +prompt, prompt-for-string) to share the same preamble." + (if (and (eql 'warn org-drill-leech-method) + (org-drill-entry-leech-p)) + (concat (propertize "!!! LEECH ITEM !!! +You seem to be having a lot of trouble memorising this item. +Consider reformulating the item to make it easier to remember.\n" + 'face '(:foreground "red")) + prompt) + prompt)) + (defun org-drill--make-minibuffer-prompt (session prompt) "Make a mini-buffer for the SESSION, with PROMPT." (let ((status (cl-first (org-drill-entry-status session))) @@ -1677,14 +1693,7 @@ PROMPT: A string that overrides the standard prompt. org-drill--quit-key))) (full-prompt (org-drill--make-minibuffer-prompt session prompt))) - (if (and (eql 'warn org-drill-leech-method) - (org-drill-entry-leech-p)) - (setq full-prompt (concat - (propertize "!!! LEECH ITEM !!! -You seem to be having a lot of trouble memorising this item. -Consider reformulating the item to make it easier to remember.\n" - 'face '(:foreground "red")) - full-prompt))) + (setq full-prompt (org-drill--maybe-prepend-leech-warning full-prompt)) (while (memq ch '(nil org-drill--tags-key)) (setq ch nil) (while (not (input-pending-p)) @@ -1799,14 +1808,7 @@ one is actually active — otherwise `(set-input-method nil)' would clear (full-prompt (org-drill--make-minibuffer-prompt session prompt))) (setf (oref session drill-answer) nil) - (if (and (eql 'warn org-drill-leech-method) - (org-drill-entry-leech-p)) - (setq full-prompt (concat - (propertize "!!! LEECH ITEM !!! -You seem to be having a lot of trouble memorising this item. -Consider reformulating the item to make it easier to remember.\n" - 'face '(:foreground "red")) - full-prompt))) + (setq full-prompt (org-drill--maybe-prepend-leech-warning full-prompt)) (org-drill-presentation-timer-cancel) (setq org-drill-presentation-timer (run-with-idle-timer 1 t @@ -1844,14 +1846,7 @@ START-TIME: The time the card started to be displayed. This "Type your answer and press : ")) (full-prompt (org-drill--make-minibuffer-prompt session prompt))) - (if (and (eql 'warn org-drill-leech-method) - (org-drill-entry-leech-p)) - (setq full-prompt (concat - (propertize "!!! LEECH ITEM !!! -You seem to be having a lot of trouble memorising this item. -Consider reformulating the item to make it easier to remember.\n" - 'face '(:foreground "red")) - full-prompt))) + (setq full-prompt (org-drill--maybe-prepend-leech-warning full-prompt)) (setf (oref session drill-answer) (read-string full-prompt nil nil nil t)))) -- cgit v1.2.3