Sublime Forum

Snippets?

#1

Hi All,

I have been using Sublime Text for a total of 24 hours and am blown away, awesome editor well worth the money. Thanks Jon.

Anyways, I was wondering of there is a snippets repository some place ? I could not find any mention of one in the forum. I did see a post regarding the Google code repository for bundles, are snippets considered bundles ?

Digging around I saw the snippets are in a handy xml format and are super simple to create. Being extraordinarily lazy, and knowing that Textmate has loads of snippets I hacked together a small ruby script to do conversion of plist snippets to ST snippets and create the Default.sublime-keymap file. Given I never have an original thought I was wondering of anyone else needs this sort of tool ? If so where would be the appropriate place to upload the snippets I have already converted or the semi-complete tool ?

cheers

matt

0 Likes

#2

Well done Nick !

Based on your post you have done way more than I did with my ruby convertor. I did come across some of the issues you mentioned in your post, but have not had the time to find a work around, the unicode filenames was the biggest hurdle I was working on, I pulled my .plist files from my MacBook, but the git repo looks like a better source.

I was wondering about the $0 being the last tab stop in TextMate snippets but the first in ST so thanks for clearing that up.

I think the TextMate repo idea is great and would be of benefit to many ST users. Prehaps, as you have suggested a “complete” and “incomplete” area for the snippets would be the best. I know that I would be using the Ruby, HTML, Javascript and PHP snippets the most and would be willing to work on the manual conversion of those ones which could not be converted automagically,

cheers,

matt.

0 Likes

#3

Oh Crap, got myself in to some responsibilty then :smile:

I will give it a shot Nick.

0 Likes

#4

just read this thread, well done! it is very late for me, so i just compared your transformation to one snippet that once i’ve manually transformed. it looks good except the regex part. look (diff marked with bold blue):

my (manually transformed):


yours (new):


textmate regex used for path manipulation looks for / while on windows path use . any way i chose to support both, but the issues here (at last…) that maybe you should include this rule on the transformations. i.e. replace any / with \|/].

0 Likes

#5

How does one get ‘shell’ commands executed in ST snippets ? In TM snippets using back ticks allows shell interpolation.

0 Likes

#6

Thanks Nick, I am not sure how many users require this sort of functionality anyways, I don’t think I ever use it on a regular basis. I just noticed a few of the TM snippets contained backticks.

A python plugin would be good idea for those who do need this functionality; prehaps something like the following silly example

Would this work ?

Matt

0 Likes

#7

Great idea, when you get to them could you advise me how you dealt with the filenames for the snippets which have percentage signs in the names. A few of the Ruby snippets have these percentage signs in the filenames, most notably “%7c” which translates to “|” , and I am not sure how these should be dealt with. Other languages may not have this problem because the pipe “|” may not be so prevalent.

It seems that the name of the snippet in the menu display in ST is based on the filename for the snippet, would it be possible to have the name in the Default.sublime-keymap file instead ? Either as an attribute on the binding element or as an element itself ? I know this is not really a query for you Nick, just tossing it out there.

<binding command='insertSnippet 'Packages/Ruby/all.sublime-snippet''' key='a,l,l,tab' name="all? { |e|  }">
  <context name='selector' value='source.ruby'/>
</binding>

or

<binding command='insertSnippet 'Packages/Ruby/all.sublime-snippet''' key='a,l,l,tab'"> <name>all? { |e| }</name> <context name='selector' value='source.ruby'/> </binding>

Matt

0 Likes

#8

Nick, i will say it once again - Bravo!

few issues i wanted to address:

  1. Didn’t understand that part:

[quote]How to deal with ‘keyEquivalent’ snippets? ie ctrl+b for bold
{
“$” : “shift”,
“^” : “control”,
“~” : “option”,
“@” : “command”,
“#” : “number pad”
}[/quote]

  1. Didn’t understand that part:

[quote]>>> Mac OSX KeyBoard mappings
HOTKEY_MAPPING = {
“$” : “shift”,
“~” : “alt”,
“@” : “ctrl”
}[/quote]

  1. In general i think automation is better, because on future updates on the TM repo, we’ll have easier life. of course unless it is too much work. regarding our specific issue, i think your solution for searching the TM_PATH for path styles replacements is good.
  1. The wiki state is horrible, i think we can consider the use of the google code wiki
  1. Finally, I suggest you publish the conversion script you did, so we can help/contribute.

did i say well done? :wink:

0 Likes

#9

I seriously need to learn Python after reading that code !

0 Likes

#10

Re: .plist files.

It should also be mentioned that .plist files can be in binary format. In order to transform them to the neato XML one needs to run:

plutil -convert xml1 file.plist

This command can be found in OSX, not sure if there is a *nix alternative

Does anyone know of a library that performs the translation ?

matt

0 Likes

#11

From my understanding these are old plist files, some carry over from NeXT step days. If there are a lot of these then a function to parse them should not be too hard right ?

matt

0 Likes

#12

I really have no idea what you are saying here, could you elaborate for me please ? Expecially the "allPreceedingText contexts"

Cheers

matt

0 Likes

#13

thanks,

I now understand ‘allPreceedingText’, but I am getting way lost with all the other gear. I will put that down to my lack of Python experience an not knowing ST well enough at this stage.

matt

0 Likes

#14

Haha, sure, easier to blame you anyway than my shortcomings :stuck_out_tongue_winking_eye:

When I get to work this morning I will check them out and play around. Funny you had Tortoise crash on you, I did as well last night. Eventually I gave up and went to bed.

I noticed in a prior post that when you have 2 snippets with the same tab trigger i.e c,l,a,tab (Ruby) you append an ‘a’ or 'b, have I read this right ? If so can I suggest that instead of ‘a’ etc we use 1, 2 3 etc. In TM when I wish to use a snippet that has the same trigger as other snippets a menu pops up and I am afforded the opportunity of typing 1 or 2. I believe that it would make the transition easier.

matt

0 Likes

#15

Hey,

i just simply unpacked all the snippets directory in to sublime packages directory (i used this sublimetextwiki.wazoo.com.au/snippets/, though i didn’t understand the difference from the contextual_snippets link :open_mouth: )

anyway this is my report:

  1. it all seems to work, i guess in time we need to go through most of them and we’ll fix them. i think we should keep using the google svn repo for this (if you have checkin problems try adding then checkin less files in a row).

  2. few snippets cause error on load, you may want to remove them till they are fixed:

ColdFusion/hash.sublime-snippet Eiffel/debug-(de).sublime-snippet JavaScriptJQuery/$_get.sublime-snippet JavaScriptJQuery/$_getIfModified.sublime-snip OCamlCodeCompletion/Int64.compare.sublime-sni OCamlCodeCompletion/List.memq.sublime-snippet OCamlCodeCompletion/Nativeint.mcompar-e.subli PHP/Include-TextMate-Support-Script.sublime-s Source/Continue-line-comment.sublime-snippet

  1. sublime editor takes more than minute and a half to start on very high cpu usage (and i tried it few times to see if it happen only once for caching or something). i think sublime should not load all the snippets on start up to avoid this, maybe just load their names and not their syntax (jps?)

  2. the manage snippets on sublime tools menu, just opens the explorer on the Packages folder, i think it misses the point, maybe it is on the todo (jps?)

anyway, for now i am going to remove it all (i dont want to wait a minute and a half each time i open sublime) and use only the relevant for the languages i expect to use.

0 Likes

#16

Simply awesome work Nick, kudos.

When I completely understand the benefits of the contextual snippets I will use them, for now though I will be using the sequential snippets.

On a side note I have been doing a little reading on Python and an surprised to say that i can understand larger blocks of your converter code. :geek:

matt.

0 Likes

#17

I am not sure if this will effect other users on the forum but it may, after removing my old snippets (delete) and replacing them with sublimators (copy - paste) I realised I no longer had sytax highlighting etc. This was because I deleted my .tmlanguage, .sublime-options and .sublime-build files. The moral of the story then would be:

doh !

matt

0 Likes

#18

That was a great intro to the contextual binding, made a lot of sense, thanks Nick.

0 Likes

#19

Hi, I’m newee on sublime, before I was using dreamwaver cs6, and I’m missing one of the features, wich displays the related files of the document, I mean, I was able to see the “file1.js” and all the other java or css files within the same group.
Is this option allowed in the current version, or is there a package for do that?

0 Likes