Sublime Forum

Autocomplete for standart functions

#1

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:
    i55.tinypic.com/2e4i2c9.png
  2. How I make functions/variable-autocomplete in JS, as in PHP?
    example: I type in PHP file: 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?
0 Likes

#2

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

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

from AutoComplete import AutoCompleteCommand

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

AutoCompleteCommand.completionCallbacks'exampleCompletions'] = exampleCompletions
0 Likes

#3

[quote=“jps”]You would have to write a plugin to provide these completions.

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

[code]
from AutoComplete import AutoCompleteCommand

def exampleCompletions(view, pos, prefix, completions):
return “xyzzy”, “idkfa”] + completions

AutoCompleteCommand.completionCallbacks’exampleCompletions’] = exampleCompletions
[/code][/quote]

Yes, i did it. But this is not what I need - no filter on the first letter of the function.
screenshot of the result:

this is not what I need.
Can you help me?
P.S. text-file with name of all PHP-functions there

0 Likes

#4

I believe you need to do the filtering of the list within the python code, something like this

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
0 Likes

#5

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

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
0 Likes

#6

good job, guys! big thanks!
I’ll write a similar plugin for JS
Does anyone need it?

0 Likes

#7

I need it for js, but also for html5 & css3. Is there any of these autocomplete plugins available?

0 Likes

#8

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):

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…):

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

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

0 Likes