I need to search for every declared variable in a string with format %^{var}, prompt a value and replace in place.

(let ((primitive "(%^{size}, %^{center})"))
  (if (string-match "%^{\\([^}]*\\)}" primitive)
      (replace-regexp-in-string (format "%%^{%s}" (match-string 1 primitive))
                                (read-string (format "%s: " (match-string 1 primitive)))
  (message "%s" primitive))

However this does not replace the variable in the string and the primitive is printed unchanged.

(Later when I fix this problem, I'm changing if to while so it does it for every variable in the string)


1 Answer 1


You're not doing anything with the return value of replace-regexp-in-string.

  • Fuck me. Rookie mistake. Commented May 26, 2023 at 7:38
  • 1
    We've all been there :)
    – phils
    Commented May 26, 2023 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.