Home Download Buy Blog Forum Support

How to use jQuery snippets?

Re: How to use jQuery snippets?

Postby atomi on Wed Mar 02, 2011 4:15 pm

You're probably aware of this, but just to be sure, you can confine all package specific bindings to a relevant keymap


I actually wasn't aware of that -I hadn't seen this in any of the current Packages.

Thanks for taking the time to explain your process.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: How to use jQuery snippets?

Postby atomi on Wed Mar 02, 2011 5:38 pm

Luckily I wrote a bindings/commands converter the other week for ZenCoding so it's a 10 second job to convert the jQuery folder.


That sounds cool and useful.
Have you made this converter available publicly?

Also,
If for whatever reason you want to use binding contexts other than just a <scope> selector or you want to use regex bindings (not yet in S2) you can't use <tabTrigger>
If for some reason you've written a plugin command (preserving relative indentation of $SELECTION etc) that adds extra functionality surrounding inserting snippets you can't use <tabTrigger>
If you have a few k snippets, it's a lot quicker to parse key map files to get an aggregate list of bindings, without having to track modifications.


Do these restrictions apply to the sublime-completions method as well?
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: How to use jQuery snippets?

Postby atomi on Thu Mar 03, 2011 9:10 am

...if there's a way to record 'b' as yielding 'both' and 'bottom' in different circumstances.


Well yeah, and 'block' too. :)

Of course it'd be great to have context based completions.
My problem is there isn't a concrete commitment to one particular method as far as I can tell.

It seems to me, being on the periphery of things, that sublime-completions is where further development is going to take place in regards to specific context completions. And if there are limitations to using sublime-completions file for describing tab targets, I'd love for them to outlined and addressed.

I don't mind scripting a quick and dirty converter for either sublime-keymaps or sublime-completions, but I'd like to do it for at least the one that promises to provide the most features (in case the snippets need refinement as you've mentioned).

On the other hand, if the only way to improve snippet behavior will be through a plugin, then the method of defining the snippet is irrelevant, so long as Sublime is able to find it. If that also means that a sublime-keymaps file is the best method of accessing the tab target information for fancy context based snippet plugin, I guess that's fine too.

But this architecture needs to be figured out and promoted.

Anyway, good to hear your thoughts on this.
Thanks again.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: How to use jQuery snippets?

Postby qqq on Tue Mar 08, 2011 2:25 pm

Win7/ST2(b. 2042) issue

After having read this topic and having tried a couple of things I am still not able to get jQuery to work in Sublime Text 2.

I want
1) jQuery appearing in Snippets menu (optional)
2) jQuery appearing in Syntax menu
3) be able to add working <tabTrigger> snippets

I have:

a) put the snippets downloaded from http://sublime.akalias.net/snippets/Jav ... %20jQuery/ in my %AppData%\Sublime Text 2\Packages\Javascript folder
b) put the language file downloade from https://bitbucket.org/sublimator/jquery ... tmLanguage in the same folder

The result is:
ad 1) jQuery does not appear in Snippets menu (this is probably because all the snippets were put in the JavaScript folder)
ad 2) ok - jQuery appears in Syntax menu
ad 3) some bizzare things happen, for example:
The snippet <tabTrigger>.end</tabTrigger> won't work. However if I remove the dot making it <tabTrigger>end</tabTrigger> it works just fine! This happens with all the triggers that start with a dot (and most of them do). The <tabTrigger>$</tabTrigger> also does not work and it won't until it starts with $. Tried some other combination and it seems that a trigger that doesn't start with an alphanumerical character (numbers are ok) can't be made to work. Can you explain this?
ST2 Win7 64-bit
qqq
 
Posts: 57
Joined: Tue Mar 08, 2011 9:49 am

Re: How to use jQuery snippets?

Postby tstrokes on Tue Mar 08, 2011 5:58 pm

1) jQuery appearing in Snippets menu (optional)
2) jQuery appearing in Syntax menu
You can create a first level menu item in both menus by creating a jQuery folder in the packages directory.
Then copy over the jQuery.tmLanguage and all snippets. This however is not the preferred way.
Using the user directory in the packages directory is better because these files won't get wiped away when you upgrade ST.
This will however create a second level menu in the snippets menu under User and a first level menu in the Syntax menu.

3) be able to add working <tabTrigger> snippets
This is a bug: viewtopic.php?f=2&t=1820&start=40#p8394
tstrokes
 
Posts: 17
Joined: Wed Dec 03, 2008 6:39 pm

Re: How to use jQuery snippets?

Postby qqq on Tue Mar 08, 2011 6:55 pm

Thanks @tstrokes.

However neither of your solutions solved the problem completely:

-On ST startup I get an error message "Error loading syntax file "Packages/XML/XML.tmLanguage": Error parsing plist xml: Failed to open file In file "Packages/JavaScript/jQuery.tmLanguage",
-There is neither "User" no "jQuery" in Syntax menu (Snippet menu ok),
-And I would like .js files to be in the scope of both JavaScript and jQuery. Maybe it would be the case if I was able to select "jQuery" from Syntax menu. But with "JavaScript" selected only JavaScripts snippet work.

The makeshift solution I have found is to have snippets+tmLanguage file both in JavaScript folder and in a separate jQuery folder (either in Packages or in Packages\User). This way it works, but I don't think it is a preferred solution as it should be managed by the scope, copying the same files in several different places is simply not elegant
ST2 Win7 64-bit
qqq
 
Posts: 57
Joined: Tue Mar 08, 2011 9:49 am

Re: How to use jQuery snippets?

Postby qqq on Tue Mar 08, 2011 7:37 pm

SOLVED! (my sloppy reading!) :geek: :geek: :geek: :geek: :geek:

But I'll try to summarize it here for the posterity:

1) download jQuery snippets from: http://sublime.akalias.net/snippets/Jav ... %20jQuery/
2) download a jQuery.tmLanguage file from: https://bitbucket.org/sublimator/jquery ... tmLanguage
3) put the files you have downloaded in 1) and 2) in:
a) either Packages\jQuery folder (this folder is located in %appdata%\Sublime Text 2\)
b) or Packages\User\jQuery folder (recommended, as this location is not overwritten when software is upgraded),
4) edit the file you have downloaded in 2) (jQuery.tmLanguage): it needs at least one fileTypes entry, in case it hasn't:
Enter the following code at line 7 and save changes:
Code: Select all
   <key>fileTypes</key>
   <array>
      <string>js</string>
   </array>

P.S. At the moment there is a problem with snippets whose triggers contain non-alphanumerical signs (they do not work) so don't freak out. Probably by the time most of you read this it will be fixed.
ST2 Win7 64-bit
qqq
 
Posts: 57
Joined: Tue Mar 08, 2011 9:49 am

Re: How to use jQuery snippets?

Postby gellpak on Mon Apr 11, 2011 2:40 pm

qqq wrote:SOLVED! (my sloppy reading!) :geek: :geek: :geek: :geek: :geek:

But I'll try to summarize it here for the posterity:

1) download jQuery snippets from: http://sublime.akalias.net/snippets/Jav ... %20jQuery/
2) download a jQuery.tmLanguage file from: https://bitbucket.org/sublimator/jquery ... tmLanguage
3) put the files you have downloaded in 1) and 2) in:
a) either Packages\jQuery folder (this folder is located in %appdata%\Sublime Text 2\)
b) or Packages\User\jQuery folder (recommended, as this location is not overwritten when software is upgraded),
4) edit the file you have downloaded in 2) (jQuery.tmLanguage): it needs at least one fileTypes entry, in case it hasn't:
Enter the following code at line 7 and save changes:
Code: Select all
   <key>fileTypes</key>
   <array>
      <string>js</string>
   </array>

P.S. At the moment there is a problem with snippets whose triggers contain non-alphanumerical signs (they do not work) so don't freak out. Probably by the time most of you read this it will be fixed.


Mac OS X 10.6.7

I've followed this guide and manually downloaded the packages into my ~/Library/Application Support/Sublime Text 2/Packages/ folder, making sure to rename the folders with the proper capitalization, but can't get any autocomplete working. jQuery shows up in both the Syntax menus and Snippets menus, and when I select jQuery as my syntax, the color highlighting on my code changes slightly. However, my tests of "$ > [tab]" or "this > [tab]" have no effect, I just end up with exactly what I typed. I can manually go into the menus and trigger a snippet. Tried erasing the Sublime Text 2 library folder and restarting all of this but that had no effect either. Help?
gellpak
 
Posts: 1
Joined: Mon Apr 11, 2011 2:35 pm

Re: How to use jQuery snippets?

Postby whololo on Fri Jan 13, 2012 9:27 am

P.S. At the moment there is a problem with snippets whose triggers contain non-alphanumerical signs (they do not work) so don't freak out. Probably by the time most of you read this it will be fixed.[/quote]

I think triggers with $ is still not possible.
whololo
 
Posts: 12
Joined: Fri Jul 08, 2011 10:47 am

PreviousNext

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 15 guests