-1

I want to insert this template: << prints("on_%s.gd:"%name, "msg: %s"%msg); >> How to convince emacs it's a string?

VanDeiMin
  • 1
  • 1
  • 2
    It's not clear to me -- at all -- what you're asking. What do you mean by "convince emacs" that this is a string: << prints("on_%s.gd:"%name, "msg: %s"%msg); >>? Where does that text occur? Out of the blue (no context), that text isn't a string. And a string in what programming language? And what do you mean by "template", here? I find nothing about your question to be at all comprehensible; sorry. – Drew Apr 18 '23 at 19:09

1 Answers1

1

Execute this:

(insert "<< prints(\"on_%s.gd:\"%name, \"msg: %s\"%msg); >>")

in the *Scratch* buffer to see it inserting:

<< prints("on_%s.gd:"%name, "msg: %s"%msg); >>

Use:

(message "<< prints(\"on_%s.gd:\"%%name, \"msg: %s\"%%msg); >>" "EVENT" "MESSAGE")

to get:

"<< prints(\"on_EVENT.gd:\"%name, \"msg: MESSAGE\"%msg); >>"

Notice that in the first case you need only to escape the quotation marks with a backslash \ where in the second case it is in addition to that also necessary to escape the percent % sign by doubling it in order to get a % in the output.

FINALLY:

(insert (message "<< prints(\"on_%s.gd:\"%%name, \"msg: %s\"%%msg); >>" "EVENT" "MESSAGE"))

will give you:

<< prints("on_EVENT.gd:"%name, "msg: MESSAGE"%msg); >>

After you have got the idea how it works, you can also escape the %s with %%s instead of using it to inject values into the output string in the (message statement, but I suppose this is not what you are asking for.

Claudio
  • 450
  • 3
  • 12