Home Download Buy Blog Forum Support

Default auto-complete list?

Default auto-complete list?

Postby fentruck on Wed Feb 29, 2012 4:22 pm

Hi, I have a question that's probably pretty easy, but has been bugging me for a few days.I was unable to find anything like this in the forums about this.
I write a lot of SQL (lots of uppercase keywords), so auto-complete is a lifesaver. However, these keywords only auto-complete when they are already present in the document, so I need to type each of those keywords once before they;ll show up. I was wondering if there was a way to define a default universal auto-complete keyword list that would apply to all documents, rather than just pulling from the current document, so that I can be even more efficient (lazier) with my typing.

Thanks
fentruck
 
Posts: 4
Joined: Wed Feb 29, 2012 4:15 pm

Re: Default auto-complete list?

Postby guillermooo on Wed Feb 29, 2012 4:24 pm

guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Default auto-complete list?

Postby fentruck on Wed Feb 29, 2012 5:07 pm

So let me get this straight. You can define completions through a JSON .sublime-completions file.
For my purposes, the contents would be pretty simple.
Code: Select all
{
        "scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",

        "completions":
        [
                "SELECT",
                "FROM",
                "INSERT",
                "JOIN"
        ]
}


The header part confuses me though. What is "scope"? Is that where the completions are applied? If so, what would I set it to to apply to all SQL files? test.sql? What does the rest of it (source - meta.tag, punctuation.definition.tag.begin) mean? Also, where would I put the file?

Sorry for all the questions. The documentation is sparse on this topic.

Thanks.
fentruck
 
Posts: 4
Joined: Wed Feb 29, 2012 4:15 pm

Re: Default auto-complete list?

Postby agibsonsw on Wed Feb 29, 2012 6:14 pm

You need something like one of the following:

Code: Select all
"scope": "source.sql",

"scope": "source.sql - string.quoted.double.sql",

"scope": "source.sql - string.quoted.double.sql, - string.quoted.single.sql",
"scope": "source.sql - string.quoted.double.sql - string.quoted.single.sql",
"scope": "source.sql - string.quoted.double.sql, source.sql - string.quoted.single.sql",

I'm sure the first two are okay, but I'm not 100% of the other three alternatives - perhaps experiment ;)

Basically, you're specifying that the completions only apply to .sql files, but not within quoted text.

You can store the file pretty much anywhere in your Packages folder, but User is generally the best place - so you can find it later, and it won't interfere with anything else. You can also name it anything, but it must have the extension 'sublime-completions'.
"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: Default auto-complete list?

Postby agibsonsw on Wed Feb 29, 2012 6:30 pm

This version works for me:

Code: Select all
"scope": "source.sql - string.quoted.double.sql - string.quoted.single.sql",


You could even save the following as 'SELECT.sublime-snippet' in your User folder.

Code: Select all
<snippet>
   <content><![CDATA[SELECT ${1} FROM ${2} WHERE ${3};$0]]></content>
   <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
   <tabTrigger>SELECT</tabTrigger>
   <!-- Optional: Set a scope to limit where the snippet will trigger -->
   <scope>source.sql - string.quoted.double.sql - string.quoted.single.sql</scope>
</snippet>

Start typing SELECT and then press Tab to complete the other parts of the statement, pressing tab to move between fields. Although.. I'm not sure that it will save you a lot of time 8-)
"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: Default auto-complete list?

Postby fentruck on Wed Feb 29, 2012 7:01 pm

Oh wow! Thanks a lot agibsonsw. That works perfectly. The snippet idea is pretty nifty too. Maybe in the future I'll find a good use for something like that.
fentruck
 
Posts: 4
Joined: Wed Feb 29, 2012 4:15 pm

Re: Default auto-complete list?

Postby agibsonsw on Wed Feb 29, 2012 7:24 pm

fentruck wrote:Oh wow! Thanks a lot agibsonsw. That works perfectly. The snippet idea is pretty nifty too. Maybe in the future I'll find a good use for something like that.


No problem. You could put spaces after your completions, "SELECT ", as they're always followed by a space anyway ;)
"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: Default auto-complete list?

Postby agibsonsw on Wed Feb 29, 2012 7:52 pm

For your later consideration :D the following snippet is more useful. It is triggered from the word 'left' and helps you complete the basic structure for a LEFT (OUTER) JOIN:

Code: Select all
<snippet>
   <content><![CDATA[SELECT ${1:table1}.${2:field1}, ${3:table2}.${4:field2} FROM ${1} AS ${5:tbl1_alias}
LEFT JOIN ${3} AS ${6:tbl2_alias}
ON ${5}.${7:join_fld} = ${6}.${7};$0]]></content>
   <tabTrigger>LEFT</tabTrigger>
   <scope>source.sql - string.quoted.double.sql - string.quoted.single.sql</scope>
</snippet>

It will still need to be edited afterwards, but at least the basic structure will be in place quickly.

As an exercise (home work!) you can create one for RIGHT as well. Andy.
"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


Return to General Discussion

Who is online

Users browsing this forum: gregor.hoch, j9ac9k and 29 guests