Sublime Forum

How to use jQuery snippets?

#1

I’m used to E text editor, it’s easy.
I just downloaded sublime 2 for the first time, i downloaded this folder with all the jquery snippets for sublime: sublime.akalias.net/snippets/Jav … %20jQuery/
then i opened the packages folder and moved the jquery snippets folder into the packages folder.
when i reset sublime, Jquery showed up in the snippets menu… but it doesn’t let me use any of the TAB shortcuts… WHY?

I saw another menu called syntax, which did NOT have Jquery in it…

… Why aren’t snippets working for Jquery, when I have them installed.
is there a jquery syntax folder/file available to download that will make this work? or? uhhh?

0 Likes

#2

I can’t seem to get any snippets working in v2.

0 Likes

#3

jQuery won’t have shown up in the snippets menu because you need a corresponding .tmLanguage file for it: there are only snippets at that link.

The snippets are scoped on “source.js.jquery”, which means they’ll only trigger if the current file is using the jQuery tmLanguage file. You’ll need to find one.

0 Likes

#4

A .tmLanguage file needs at least one fileType entry to appear in the list of available syntaxes in Sublime Text

0 Likes

#5

I’m sorry maybe i’m a little dull, but i downloaded the .zip from the bitbucket link you posted. then in S2 I went to ‘preferences’ > ‘browse packages’ then when the folder opened, i stuck the jquery folder i downloaded in there with all the other folders. i reset S2, and I see Jquery in the snippets menu, but not in the syntax menu, i even scrolled all the way down, and pressed J to scroll through all those starting with J.

Was it supposed to work after doing that?

WindowsXP 32bit

0 Likes

#6

Just tried deleting the cache file, and it’s still not showing up inside the syntax menu under ‘tools’. I searched Google for the textmate folder with snippets and all that stuff that’s in your download link, and i tried that too, and when i added that one it had the ‘t.h.i.s TAB’ stuff in the snippets menu next to the snippet, which isn’t there when i use the one you put a link to. But either way it’s still not in the syntax menu. Is there a way to make jquery work under the javascript syntax? or? i’m just trying to find any way to make jquery syntax work, sublime is no good to me if I can’t get this working. It works in E text-editor, but development over there seems dead and there’s a few problems that haven’t been taken care of and it’s been too long.

I’m using Sublime 2 Build 2020 on windowsXP 32bit

0 Likes

#7

Check that:

A) You have a .tmLanguage file for jQuery
B) Inside the .tmLanguage file, it has one or more entries in the array

0 Likes

#8

[quote=“jps”]Check that:

A) You have a .tmLanguage file for jQuery
B) Inside the .tmLanguage file, it has one or more entries in the array[/quote]

PERFECT, there was no , so i copied it from the javascript package and now jquery shows up in the syntax list. How did it work for you subliminator if you didn’t have the line in your language file? Also, in the package you put online, there’s no tabTrigger in any of the .sublime-snippet files. Does your converter keep the tab trigger? because looking through it, none of the snippets in the package you put online have tabTriggers. I added a few tab triggers to see if jquery works, and i finally got it working after adding the line, and then adding trigger word to each snippet.

0 Likes

#9

so, i can copy what you posted right there, copy that into the keymap file and it will take the name of the snippet and make that the tab trigger?

0 Likes

#10

Why not use the tabTrigger?

It seems messy to pollute the user’s .sublime-keymap file.

0 Likes

#11

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.

0 Likes

#12

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

Also,

Do these restrictions apply to the sublime-completions method as well?

0 Likes

#13

Well yeah, and ‘block’ too. :smile:

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.

0 Likes

#14

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 snippets

I have:

a) put the snippets downloaded from sublime.akalias.net/snippets/Jav … %20jQuery/ in my %AppData%\Sublime Text 2\Packages\Javascript folder
b) put the language file downloade from 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 .end won’t work. However if I remove the dot making it end it works just fine! This happens with all the triggers that start with a dot (and most of them do). The $ 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?

0 Likes

#15

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 snippets
This is a bug: viewtopic.php?f=2&t=1820&start=40#p8394

0 Likes

#16

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

0 Likes

#17

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: sublime.akalias.net/snippets/Jav … %20jQuery/
  2. download a jQuery.tmLanguage file from: 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:

<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.

0 Likes

#18

[quote=“qqq”]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: sublime.akalias.net/snippets/Jav … %20jQuery/
  2. download a jQuery.tmLanguage file from: 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:

<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.[/quote]

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?

0 Likes

#19

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.

I think triggers with $ is still not possible.

0 Likes