Running Spacemacs v.0.200.13 on emacs 25.2.2 on Kubuntu 18.04.
Consider the following code:
(defun xx-ll ()
(interactive)
(save-excursion
(goto-char (point-min))
(xx-replace-regexp-and-return
"^[[:blank:]]\*LLA[[:space:]]\*\\(<[ou]l class=\"nicelist\"\\)"
"\\1 type=\"A\"")
(xx-replace-regexp-and-return
"^[[:blank:]]\*LLI[[:space:]]\*\\(<[ou]l class=\"nicelist\"\\)"
"\\1 type=\"I\"")
(xx-replace-regexp-and-return
"^[[:blank:]]\*LLa[[:space:]]\*\\(<[ou]l class=\"nicelist\"\\)"
"\\1 type=\"a\"")
(xx-replace-regexp-and-return
"^[[:blank:]]\*LLi[[:space:]]\*\\(<[ou]l class=\"nicelist\"\\)"
"\\1 type=\"i\"")))
(defun xx-replace-regexp-and-return (from to)
(save-excursion
(while (re-search-forward from nil t)
(replace-match to 1))))
The 1
in replace-to
is to preserve case of replacement string. All goes well except that LLa
and LLi
leads to replacement by type="A"
and type="I"
respectively.
How do I set this right? Also, if I need to make any changes to any initialization variables, I will like to make them ONLY for this function.
case-fold-search
when you invokere-search-forward
? Do you see the same behavior when you remove the first two calls toxx-replace-regexp-and-return
(those forLLA
andLLI
)? If so, try bindingcase-fold-search
tot
in the defun ofxx-replace-regexp-and-return
.case-fold-search
is set to t. When I remove the first two calls,LLA
andLLa
both convert totype="a"
andLLI
andLLi
both convert totype="i"
So, it is different from previously.(setq case-fold-search nil)
toxx-replace-regexp-and-return
and all is well.case-fold-search
in your function. 2. Please consider posting an answer, with the solution you found. You can accept your own answer. (Comments can be deleted at any time. Answers in comments don't help much, and they don't count.)(setq case-fold-search nil)
that would have assigned it a new (global) value, which would have remained in effect when your function finished. Instead, you bound the value locally, within the scope of the function.