summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-02-16 01:59:42 +0200
committerThanos Apollo <[email protected]>2024-02-16 01:59:42 +0200
commite4ca956cc7da0de1ec18e8ff844cb07896894f4d (patch)
treeaedf33dbc46747f1099bf544a05717819081494e /gnosis.el
parent1af69254111046396a0ea5dab3a7c20608c4201a (diff)
[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.
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el9
1 files 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)