diff options
author | Thanos Apollo <[email protected]> | 2025-01-03 19:53:53 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2025-01-03 19:53:53 +0200 |
commit | bfb708cc879d17296770a37ea251fba2d4f3841c (patch) | |
tree | 7a910bdb536f7d1fe6fb02b5c9ad246359086620 | |
parent | 86334d5800df55abfb0db563dca14fb7a85a92d0 (diff) |
cloze: Do not insert "nil" strings as hints.
-rw-r--r-- | gnosis.el | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -521,17 +521,20 @@ If FILL-PARAGRAPH-P, insert question using `fill-paragraph'." (buffer-string)))) (defun gnosis-cloze-add-hints (str hints &optional cloze-string) - "Replace CLOZE-STRING in STR with HINTS." + "Replace CLOZE-STRING in STR with HINTS, skipping empty hints." (cl-assert (listp hints) nil "Hints must be a list.") - (let ((cloze-string (or cloze-string gnosis-cloze-string)) - (count 0)) + (let ((cloze-string (or cloze-string gnosis-cloze-string))) (with-temp-buffer (insert str) (goto-char (point-min)) - (while (search-forward cloze-string nil t) - (when (and (nth count hints) (search-backward cloze-string nil t)) - (replace-match (propertize (format "[%s]" (nth count hints)) 'face 'gnosis-face-cloze))) - (setq count (1+ count))) + (cl-loop for hint in hints + while (search-forward cloze-string nil t) + do + (when (and hint (not (string-empty-p hint)) (not (string= hint "nil")) + (search-backward cloze-string nil t)) + (replace-match (propertize (format "[%s]" hint) 'face 'gnosis-face-cloze)) + (goto-char (match-end 0)))) ; Move point to end of match + (buffer-string)))) (defun gnosis-cloze-mark-answers (str answers face) |