From 3389e5c53ebd0122d1fd3fa7f303a26ab0b80298 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 16 Jul 2024 14:04:22 +0300 Subject: cloze: Add gnosis-cloze-add-hints. * Add hints to cloze string. --- gnosis.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gnosis.el b/gnosis.el index aa94660..f7bb550 100644 --- a/gnosis.el +++ b/gnosis.el @@ -464,6 +464,19 @@ Refer to =gnosis-db-schema-extras' for informations on images stored." (replace-match (propertize cloze-string 'face 'gnosis-face-cloze) nil t))) (buffer-string)))) +(defun gnosis-cloze-add-hints (str hints &optional cloze-string) + "Replace CLOZE-STRING in STR with HINTS." + (cl-assert (listp hints) nil "Hints must be a list.") + (let ((cloze-string (or cloze-string gnosis-cloze-string)) + (count 0)) + (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))) + (buffer-string)))) (defun gnosis-display-basic-answer (answer success user-input) "Display ANSWER. -- cgit v1.2.3