Home Download Buy Blog Forum Support

Autocomplete for standart functions

Autocomplete for standart functions

Postby sc0rp10 on Fri Oct 15, 2010 3:04 pm

Hi. I have two questions:
1) How i make full autocomplete for my language (PHP)? e.g. I typed 'mysql_f' and pressed Ctrl+Space and see dropdown list with these words: 'mysql_fetch_array', `mysql_fetch_assoc', 'mysql_fetch_field' etc...
Sorry for my bad English, if You don't understand me, I attached screenshot from notepad++ with this feature:
http://i55.tinypic.com/2e4i2c9.png
2) How I make functions/variable-autocomplete in JS, as in PHP?
example: I type in PHP file:
Code: Select all
function myFunc($var) {
    return $var
}
and in other place of document I type 'myF', press Ctrl+space and see dropdown with name of functions whose name begins with 'myF'.
same with the variables. Why this feature works with PHP and not with JS?
sc0rp10
 
Posts: 11
Joined: Fri Oct 01, 2010 2:27 pm

Re: Autocomplete for standart functions

Postby jps on Mon Oct 18, 2010 10:56 pm

You would have to write a plugin to provide these completions.

An example plugin that adds "xyzzy" and "idkfa" as completions is:

Code: Select all
from AutoComplete import AutoCompleteCommand

def exampleCompletions(view, pos, prefix, completions):
   return ["xyzzy", "idkfa"] + completions

AutoCompleteCommand.completionCallbacks['exampleCompletions'] = exampleCompletions
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Autocomplete for standart functions

Postby sc0rp10 on Tue Oct 19, 2010 4:45 pm

jps wrote:You would have to write a plugin to provide these completions.

An example plugin that adds "xyzzy" and "idkfa" as completions is:

Code: Select all
from AutoComplete import AutoCompleteCommand

def exampleCompletions(view, pos, prefix, completions):
   return ["xyzzy", "idkfa"] + completions

AutoCompleteCommand.completionCallbacks['exampleCompletions'] = exampleCompletions

Yes, i did it. But this is not what I need - no filter on the first letter of the function.
screenshot of the result:
Image
this is not what I need.
Can you help me?
P.S. text-file with name of all PHP-functions there
sc0rp10
 
Posts: 11
Joined: Fri Oct 01, 2010 2:27 pm

Re: Autocomplete for standart functions

Postby mikeb on Tue Oct 19, 2010 7:17 pm

I believe you need to do the filtering of the list within the python code, something like this
Code: Select all
from AutoComplete import AutoCompleteCommand

def exampleCompletions(view, pos, prefix, completions):
   my_completions = ["abs", "acos", "acosh", "and_so_on"]
   return [c for c in my_completions if c.startswith(prefix)] + completions

AutoCompleteCommand.completionCallbacks['exampleCompletions'] = exampleCompletions
mikeb
 
Posts: 31
Joined: Mon Sep 07, 2009 12:33 am

Re: Autocomplete for standart functions

Postby jps on Tue Oct 19, 2010 9:10 pm

Looking good... as a further refinement, you can make it only offer these completions within PHP code:

Code: Select all
from AutoComplete import AutoCompleteCommand

def exampleCompletions(view, pos, prefix, completions):
    my_completions = ["abs", "acos", "acosh", "and_so_on"]
    if view.matchSelector(pos, "source.php"):
        return [c for c in my_completions if c.startswith(prefix)] + completions
    else:
        return completions

AutoCompleteCommand.completionCallbacks['exampleCompletions'] = exampleCompletions
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Autocomplete for standart functions

Postby sc0rp10 on Wed Oct 20, 2010 7:52 am

good job, guys! big thanks!
I'll write a similar plugin for JS
Does anyone need it?
sc0rp10
 
Posts: 11
Joined: Fri Oct 01, 2010 2:27 pm

Re: Autocomplete for standart functions

Postby apeisa on Wed Dec 15, 2010 4:42 pm

I need it for js, but also for html5 & css3. Is there any of these autocomplete plugins available?
apeisa
 
Posts: 1
Joined: Wed Dec 15, 2010 4:40 pm

Re: Autocomplete for standart functions

Postby lode on Fri Dec 17, 2010 10:30 am

Hej, just discovered this marvelous project!

Hooking in this discussion. From my old editor PSPAD I'm used to have variables with it in an intelligent way. Typing <ctrl+space, strp, enter> gives me (| = cursor):
Code: Select all
strpos(|string haystack, string needle, [int offset])


I tried doing it with key-bindings and snippets like this (not exactly understanding the context tag below made me just commenting it..):
Code: Select all
<bindings>
   <binding key="s,t,r,p,o,s,tab" command="insertSnippet 'Packages/PHP/strpos(-).sublime-snippet'">
      <!--<context name="selector" value="text.html - meta.tag - source, punctuation.definition.tag.begin, meta.scope.between-tag-pair.html"/>-->
   </binding>
</bindings>

Code: Select all
<snippet>
    <content><![CDATA[strpos(\$${1:haystack}, \$${2:needle});$0]]></content>
    <tabTrigger>strpos</tabTrigger>
    <scope>source.php</scope>
    <description>strpos …</description>
</snippet>


That works. But has some drawbacks; 1) it doesn't show a drop-down, it only works by typing the whole function name out exactly, without typo's and 2) I would have to create a lot of snippets and key-bindings this way, it would be nice to automate most of this.

Is there anything like this already? Or something pointing in the right direction?
lode
 
Posts: 2
Joined: Fri Dec 17, 2010 10:14 am
Location: Netherlands


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 22 guests