aboutsummaryrefslogtreecommitdiff
path: root/org-drill.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-05 04:13:01 -0500
committerCraig Jennings <c@cjennings.net>2026-05-05 04:13:01 -0500
commit326bffaa2f555f863abb7a9cc0887c86779ea97b (patch)
tree1ffb4dcac949ac70ada2b349559ac1506972d6f7 /org-drill.el
parent30d48a0fffb2e89a070a726c784d8544ae5043b9 (diff)
downloadorg-drill-326bffaa2f555f863abb7a9cc0887c86779ea97b.tar.gz
org-drill-326bffaa2f555f863abb7a9cc0887c86779ea97b.zip
fix: don't create zero-width overlay for hint-less clozes
org-drill-hide-cloze-hints checked (null (match-beginning 2)) to detect "no hint present," but the cloze regex's hint group is an empty-allowed alternation — the group always participates in the match, so match-beginning is always a position, never nil. For a card like "[Paris]" (no hint), the function fell through to org-drill-hide-region with start = end and made a zero-width overlay. Cosmetically harmless but accumulates one stray overlay per hint-less cloze. On a buffer with many such cards the tracking cost is real. Switched the guard to (= (match-beginning 2) (match-end 2)) — empty match. Found while writing tests; locked in by tests/test-org-drill-hide-show.el's test-org-drill-hide-cloze-hints-no-hint-no-overlay.
Diffstat (limited to 'org-drill.el')
-rw-r--r--org-drill.el10
1 files changed, 8 insertions, 2 deletions
diff --git a/org-drill.el b/org-drill.el
index c3a73eb..e2234e5 100644
--- a/org-drill.el
+++ b/org-drill.el
@@ -2043,13 +2043,19 @@ Saves current settings and applies drill-specific display preferences."
"")))))))
(defun org-drill-hide-cloze-hints ()
- "Hide cloze hints."
+ "Hide cloze hints.
+
+The cloze regex's hint group is `\\(\\|HINTSEP.+?\\)' — an empty
+alternation — so it always participates in the match. Check for an
+empty match (start = end) rather than nil match-beginning, otherwise
+this function creates a zero-width overlay for every hint-less cloze."
(save-excursion
(while (re-search-forward org-drill-cloze-regexp nil t)
(unless (or (save-match-data
(org-drill-pos-in-regexp (match-beginning 0)
org-link-bracket-re 1))
- (null (match-beginning 2))) ; hint subexpression matched
+ ;; Empty match → no hint present, nothing to hide.
+ (= (match-beginning 2) (match-end 2)))
(org-drill-hide-region (match-beginning 2) (match-end 2))))))
(defmacro org-drill-with-replaced-entry-text (text &rest body)