jugyo / SublimeSnippetMaker

Makes managing snippets easy in Sublime Text
74 stars 15 forks source link

Escaping $ symbol #20

Closed coder054 closed 5 years ago

coder054 commented 5 years ago

When I create a snippet like this console.log($1) I want "$1" is the place where my cursor is at after the snippet triggered But now "$" is escaped so its turn into a string I don't want that :(

braver commented 5 years ago

Ha, that figures. So, you’re writing code with the tab targets, and then turn it into a snippet? Didn’t think of that... 🤔

braver commented 5 years ago

Ok, the idea here is that by default your selected code should be returned by the snippet "as is". We really can't tell if your $1 is just a dollar sign followed by a number, or if you intend for it to be turned into a tab target. It's probably the latter, but it's hard to be certain. So, right now, you'd have to edit the snippet after creation to remove the escapes. The snippet opens after creation, so you could also change your code to add the tab targets then. But I'll look into adding an argument to the command so you can opt-out of the default behavior.

tcrowe commented 5 years ago

Hi guys!

I too might have encountered this. I did this:

  1. const $1 = require("async/$1")
  2. Cmd+Shift+P -> Make snippet
  3. fill out info

The result is const \$1 = require("async/\$1")

I can see how this would be useful, for example, if people use $ like they do with jQuery. In some languages I think ALL the variables use $ as a prefix.

I'll take a look at the source and see how difficult it would be to put in a setting.

tcrowe commented 5 years ago

For later reference: https://github.com/jugyo/SublimeSnippetMaker/blob/master/SnippetMaker.py#L36 https://github.com/jugyo/SublimeSnippetMaker/blob/master/SnippetMaker.sublime-settings#L6

marcospb19 commented 5 years ago

So the defaults are always escape? I think this is better, and then user can add $1 and $2 inside of the XML file.

Should this be closed?

braver commented 5 years ago

Well, that’s not so much the default as it’s the only behavior. It’s the correct behavior though. This issue is open because we might want to add a setting or something.

marcospb19 commented 5 years ago

Is someone already working on this? I'm willing to implement it.

braver commented 5 years ago

That would be great, I really don’t have the time to do it. 👍🏻

marcospb19 commented 5 years ago

Done! @coder054 sorry for being late a few months :stuck_out_tongue:.