Home Download Buy Blog Forum Support

How can I modify built-in packages/snippets?

How can I modify built-in packages/snippets?

Postby qqq on Fri May 03, 2013 11:09 am

This used to be possible in ST2.

In ST3 I have only the User folder (located in C:\Users\USERNAME\AppData\Roaming\Sublime Text 3\Packages on my Windows machine) and the Packages folder (located in the program installaction directory) which contains compiled packages files.

I can add my own snippets, but they do not override existing built-in ones with the same trigger. For example I can define my own if-else (triggerd by "ife") snippet but it will appear in the dropdown popup under the existing "ife" snippet.

Snippets are key functionality in my case. Is it just my impression or does ST3 really offer much less flexibility when working with snippets?
ST2 Win7 64-bit
qqq
 
Posts: 57
Joined: Tue Mar 08, 2011 9:49 am

Re: How can I modify built-in packages/snippets?

Postby drifter on Sat May 04, 2013 8:01 pm

qqq wrote:I can add my own snippets, but they do not override existing built-in ones with the same trigger. For example I can define my own if-else (triggerd by "ife") snippet but it will appear in the dropdown popup under the existing "ife" snippet.

From my experience, that is exactly how it worked in ST2 as well.
This inconsistency was my major gripe with ST2. Considering that it was possible to override pretty much everything else (preferences, key bindings), and that it's the whole damn point of having "User" folder to begin with.

As for ST3, these .sublime-package files are just zip archives. You can extract such file to AppData Packages folder (not into User, but on the same level) and modify the file(s) within as necessary. So far the auto-updating seems to leave those untouched, so it can work unlike in ST2.

Although I'd still prefer if things were made consistent.
drifter
 
Posts: 13
Joined: Tue Apr 23, 2013 12:17 pm

Re: How can I modify built-in packages/snippets?

Postby skuroda on Sat May 04, 2013 8:08 pm

Here is some information on packages in ST3. As drifter mentioned, you can override the contents of the .sublime-package files. This is "better" as updates to ST won't blow away your changes. Though you could do the whole ignore the default package and create a new one with the modifications as you would in ST2.

http://www.sublimetext.com/docs/3/packages.html

To make it a little easier to edit/view files from the sublime-package, I wrote PackageResourceViewer. "Editing" will create the file in the proper location, so you don't have to manually extract everything.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: How can I modify built-in packages/snippets?

Postby drifter on Sat May 04, 2013 8:32 pm

That documentation seems to be wrong though.

"Packages may also be stored unzipped within a directory, or a mix of the two: any loose files in the package directory will override files stored in the .sublime-package file. "
"To override a file in an existing package, just create a file with the same name under the Packages/<Package Name> directory."
Etc.
It implies you can modify or add just the files you need.
But the reality is that you have to extract the entire package. What you have in Packages/<Package Name> folder is all you will get, because <Package Name>.sublime-package is then entirely ignored.
drifter
 
Posts: 13
Joined: Tue Apr 23, 2013 12:17 pm

Re: How can I modify built-in packages/snippets?

Postby skuroda on Sat May 04, 2013 8:39 pm

drifter wrote:That documentation seems to be wrong though.

"Packages may also be stored unzipped within a directory, or a mix of the two: any loose files in the package directory will override files stored in the .sublime-package file. "
"To override a file in an existing package, just create a file with the same name under the Packages/<Package Name> directory."
Etc.
It implies you can modify or add just the files you need.
But the reality is that you have to extract the entire package. What you have in Packages/<Package Name> folder is all you will get, because <Package Name>.sublime-package is then entirely ignored.


Really? I just did a quick test replacing the Java main snippet (well added some random text). I was then able to call a snippet from the originally defined Java.sublime-package file that I did not redefine. It inserted the correct contents both times. I did this on W7 x64.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: How can I modify built-in packages/snippets?

Postby drifter on Sat May 04, 2013 9:11 pm

@skuroda
Hmm, then it's some inconsistent behavior again. My case:

Extracted and modified just Packages\HTML\html.sublime-snippet
Restart sublime, create a new html file, type html+tab, get my new snippet. But things like tag completions are missing (ie, type div+tab, get div and a tab).
Extracted entire HTML.sublime-package to Packages\HTML\, modified html.sublime-snippet, everything works.

Edit: Although I wasn't correct saying that <Package Name>.sublime-package gets entirely ignored. Things like syntax highlighting still work.
Last edited by drifter on Sat May 04, 2013 9:22 pm, edited 1 time in total.
drifter
 
Posts: 13
Joined: Tue Apr 23, 2013 12:17 pm

Re: How can I modify built-in packages/snippets?

Postby skuroda on Sat May 04, 2013 9:22 pm

Well I wasn't restarting before, so that might explain it. When I follow the steps you outline, I see the same behavior. When I don't restart the editor, I get the expected behavior. This is definitely a bug that should be addressed. I would think the original intent was to modify select files of a package. Hmm, I'd like to report this to jps to get this addressed, though I don't know where the best way to get his attention is. I'll add a post to the latest dev release. But I don't know if he will look at it. That being said, I'll probably repost it when the next dev release occurs.

edit:
My java example works fine. So I took a look at the console. There are errors loading the .py files when you override the snippet.

Code: Select all
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "X/importlib/__init__.py", line 88, in import_module
  File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1522, in _find_and_load_unlocked
ImportError: No module named 'HTML.encode_html_entities'
reloading plugin HTML.html_completions
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "X/importlib/__init__.py", line 88, in import_module
  File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1522, in _find_and_load_unlocked
ImportError: No module named 'HTML.html_completions'
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: How can I modify built-in packages/snippets?

Postby qqq on Sun May 05, 2013 9:10 am

Apart from the bug you spotted it beats me why default snippets should take precedence over the ones created by the user. Wouldn't it be easier to just merge snippets in User directory with default .sublime-package files in such a way that would promote user snippets?

If I create a snippet, I don't do it to have an alternative one but to override the default. In 99% of cases I wouldn't need the default even as a second choice. And if I don't want to use my snippet anymore I just remove it and fall back to the default one.

Thank you guys for the explanation. I will extract and modify the appropriate files. However this isn't exactly what I'd call flexibility and ease of use.

I would like to be able to just move the contens of User folder whenever I install ST anew and have everything work as before. Now I will have to remember to move entire <data>/Packages folder.
ST2 Win7 64-bit
qqq
 
Posts: 57
Joined: Tue Mar 08, 2011 9:49 am

Re: How can I modify built-in packages/snippets?

Postby skuroda on Sun May 05, 2013 4:58 pm

I think the issue is that snippets, when loaded, are not mapped to a file name. The key bindings, menus, etc all have common file names. While iterating through these packages, a specific file name is found, then merged. By comparison, snippets file names are arbitrary.

I'll propose an alternative solution though it is still less than ideal. Consider ignoring the default HTML (and whatever other language for that matter) package by default. You can then create a "custom" package with your defined languages. Then, add that repository to package control, and install via package control. By doing this, you would not have to worry about moving the entire packages directory when you move machines. The downside is that you will not see the any updates. But if you are doing a full extraction, you wouldn't see them anyways. Anyways, just a thought to avoid moving the entire packages directory every time. Just as an example, here is facelessuser's repo of updated language files.

https://github.com/facelessuser/sublime-languages
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: How can I modify built-in packages/snippets?

Postby Gulzt on Fri Nov 08, 2013 7:09 pm

skuroda wrote:Here is some information on packages in ST3. As drifter mentioned, you can override the contents of the .sublime-package files. This is "better" as updates to ST won't blow away your changes. Though you could do the whole ignore the default package and create a new one with the modifications as you would in ST2.

http://www.sublimetext.com/docs/3/packages.html

To make it a little easier to edit/view files from the sublime-package, I wrote PackageResourceViewer. "Editing" will create the file in the proper location, so you don't have to manually extract everything.


Thank you so much!! That solved the problem, but also showed me why I was experiencing the same problem as TS. In windows 64 I tried creating the folder where I installed Sublime Text 3.
C:\Programs\Sublime Text 3\Packages.
It seemed to make sense because of the "Package" folder which contains the original sublims-package file I was editing.
I was not aware I had to put it somewhere else:
C:Users\me\AppData\Roaming\Sublime Text 3\Packages\

I'm posting this in case someone else got it confused too. Save yourself the trouble, use the plugin skuroda made.
Gulzt
 
Posts: 1
Joined: Fri Nov 08, 2013 6:56 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot] and 18 guests