Home Download Buy Blog Forum Support

[Solved] How to use/add custom autocompletion?

[Solved] How to use/add custom autocompletion?

Postby Tobl on Sat Oct 13, 2012 11:18 pm

Hello,

I'm trying to modify the existing html autocompletions. To do so, I have tried:

1. Modifying the existing "HTML.sublime-complesions" in "AppData\Roaming\Sublime Text 2\Packages\HTML":
changing
Code: Select all
{ "trigger": "a", "contents": "<a href=\"$1\">$2</a>" },

to
Code: Select all
{ "trigger": "a", "contents": "<abc href=\"$1\">$2</abc>" },


2. adding a custom "HTML.sublime-completions" in "AppData\Roaming\Sublime Text 2\Packages\User":
consisting of
Code: Select all
{
   "scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",
   "completions":
   [
      { "trigger": "a", "contents": "<abc href=\"$1\">$0</abc>" }
   ]
}


3. Doing both at once.


However, none of them adds any new option to the completions-list or changes the result of the autocomplete, even though modifying the preferences or snippets works perfectly fine.
Is there an obvious reasons / something I'm doing wrong that prevents this from working? If so, how should I implement custom completions to override the default ones?

Thanks in advance,
Tobl


My system:
Windows 7 64-bit;
Sublime Text 2, Version 2.0.1, Build 2217
Last edited by Tobl on Sun Oct 14, 2012 3:14 am, edited 1 time in total.
Tobl
 
Posts: 7
Joined: Sat Oct 13, 2012 10:36 pm

Re: How to use/add custom autocompletion?

Postby Tobl on Sun Oct 14, 2012 3:13 am

Okay, after a lot of research, I've got it working.
If anyone encounters the same problem, here's what I did, however, I think it's very likely that I'll soon encounter problems with this solution/workaround:

The problem with modifying the HTML.sublime-completions is that they're overwritten by the html_completions.py . Aside from learning Python there's two ways around this:

A: make your modifications to the HTML.sublime-completions and delete/rename the html_completions.py . The problem with this approach is, that every update will overwrite your custom file and replace the python. You therefore would have to make a backup of your file and change the files after every update.

B: copy the HTML.sublime-completions into your User -Package, add your modifications and rename it into something that's not in use already. Fancy stuff like MyPersonalHTML.sublime-completions will work. Now open the preferences.sublime-settings in the User Package and add the line
Code: Select all
"ignored_packages": ["Vintage", "HTML"]

The problem with this approach is, that the entire HTML-Package will be ignored. So if there are other important things in that folder, they'll be missing if you don't copy them as well. I'm pretty new to sublime, so I can't tell you if any of the files will have an impact.


Finally, there's one problem both approaches share. Due to a small programming inattantion, they'll add a second < character when autocompleting. This can be easily avoided by going to your sublime-completions file and adding a < in front of every trigger, i.e.:
Code: Select all
{ "trigger": "body", "contents": "<body>$1</body>" },

becomes
Code: Select all
{ "trigger": "<body", "contents": "<body>$1</body>" },


If you're as new to Sublime as I was a few days earlier: mark one whole block at a time (but none of the empty lines) and press Ctrl+Shift+L to select every single line. now just use Pos1 and the arrow-keys to navigate to the beginning of the trigger and add the <. It'll be added in all lines at once.

bw,
Tobl
Tobl
 
Posts: 7
Joined: Sat Oct 13, 2012 10:36 pm

Re: [Solved] How to use/add custom autocompletion?

Postby agibsonsw on Sun Oct 14, 2012 3:33 am

Renaming files will not prevent them from being found and used by ST, as long as they remain in the Packages area. Personally, I moved the html completions file completely out of the Packages directory and replaced them with my own versions, in a different folder. I am aware that these files will be re-instated on a future build or update, but this doesn't concern me too much, as I will just delete or move them again.

The extra < that is inserted is usually caused by the ZenCoding package. If you have this package installed, but are not using, then you can disable it via PackageControl - or uninstall it.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: [Solved] How to use/add custom autocompletion?

Postby Tobl on Sun Oct 14, 2012 6:06 am

Hello,
Thanks for the tips. I usually rename my files by extension, for example "html_completions.py.deact". They're pretty dead that way, but I should've tried normal renaming before posting it here.

considering the < : My ST2-installation is only a day old and completely vanilla, so no, it's not Zen. Mayby Zen changes the priorities from the .py- to the .sublime-completions-files and has that as a sideeffect, but the cause lies within the files. If you compare the python-files, you'll see that they have the correct < from the beginning.

bw,
Tobl
Tobl
 
Posts: 7
Joined: Sat Oct 13, 2012 10:36 pm


Return to Technical Support

Who is online

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