diff options
author | Thanos Apollo <[email protected]> | 2024-02-16 01:59:42 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-02-16 01:59:42 +0200 |
commit | e4ca956cc7da0de1ec18e8ff844cb07896894f4d (patch) | |
tree | aedf33dbc46747f1099bf544a05717819081494e /gnosis.el | |
parent | 1af69254111046396a0ea5dab3a7c20608c4201a (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.el | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -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) |