From e4ca956cc7da0de1ec18e8ff844cb07896894f4d Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 16 Feb 2024 01:59:42 +0200 Subject: [fix] gnosis-cloze-replace-words: Replace only first instance Refactor cl-loop to replace only the first instance of given word, instead of replacing all instances of given word using replace-regexp-in-string. --- gnosis.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gnosis.el b/gnosis.el index b57338b..8db4827 100644 --- a/gnosis.el +++ b/gnosis.el @@ -691,12 +691,11 @@ Works both with {} and {{}} to make easier to import anki notes." result)) (defun gnosis-cloze-replace-words (string words new) - "In STRING replace WORDS with NEW." + "In STRING replace only the first occurrence of each word in WORDS with NEW." (cl-assert (listp words)) - (cl-loop for word - in words - do (setf string (replace-regexp-in-string (concat "\\<" word "\\>") ;; use word boundary indentifiers - new string))) + (cl-loop for word in words + do (when (string-match (concat "\\<" word "\\>") string) + (setq string (replace-match new t t string)))) string) (defun gnosis-cloze-extract-answers (str) -- cgit v1.2.3