atom / snippets

Atom snippets package
MIT License
205 stars 100 forks source link

Support closing curly brackets in placeholder text #222

Closed MoritzKn closed 7 years ago

MoritzKn commented 7 years ago

I just tried to create a snippet for the rust format markro. The syntax looks like this:

format!("hello {}", "world!");

So I added this to my snippets:

{
  ".source.rust": {
    "format": {
      "prefix": "format",
      "body": "format!(\"${1:{}}\", ${2:value})$0"
    }
}

But if I type this:

format<tab>

it will result in

format!("{}", value)

but only the opening bracket ({) is selected.

I assume this is because the placeholder text is parsed by a simple regex like [^}]. If I am not mistaking, this is the responsible code.

MoritzKn commented 7 years ago

Oh, nevermind. I just realized I have to escape the closing curly bracket. This worked:

"format": {
    "prefix": "format",
    "body": "format!(\"${1:\\{\\}}\", ${2:value})$0"
}