Sublime Forum

How can I add my own autocomplete words?

#1

Hi, everybody!

I have recently created a library in Lua programming lenguage, and I want to integrate it with my Sublime Text 2 program in Mac. I want to create new autocompletation words to use them, like functions… I mean… if I have made a function called “createNewButtonWithPreferences(nameOfButton,x,y)”, I want to have capacity to write just “crea…” and see a popup with the complete function to press enter and autocomplete it. Is it possible?

P.D: excuse my english, I’m from Spain :smiley:

0 Likes

#2

Docs: docs.sublimetext.info/en/latest/index.html

Specific to adding autocompletions: docs.sublimetext.info/en/latest/ … tions.html

0 Likes

#3

[quote=“C0D312”]Docs: docs.sublimetext.info/en/latest/index.html

Specific to adding autocompletions: docs.sublimetext.info/en/latest/ … tions.html[/quote]

Ok, but I have two little questions yet: where have I place .sublime-completions file? And how can I create it?

0 Likes

#4

Sublime Completion files can be saved anywhere in your packages directory. You can get to the packages directory by going Preferences > Browse Packages. You’ll probably want to put the completions files in the Lua subfolder to keep it organized. Just create a new file: File > New File. Then follow the template from docs.sublimetext.info/en/latest/ … tions.html

[pre=#2A2A2A]{
“scope”: “source.lua”,

    "completions":
    
            "createNewButtonWithPreferences()",
            "someOtherFunctionWithALargeName()"
    ]

}[/pre]

0 Likes

#5

[quote=“C0D312”]Sublime Completion files can be saved anywhere in your packages directory. You can get to the packages directory by going Preferences > Browse Packages. You’ll probably want to put the completions files in the Lua subfolder to keep it organized. Just create a new file: File > New File. Then follow the template from docs.sublimetext.info/en/latest/ … tions.html

[pre=#2A2A2A]{
“scope”: “source.lua”,

    "completions":
    
            "createNewButtonWithPreferences()",
            "someOtherFunctionWithALargeName()"
    ]

}[/pre][/quote]

Ok, perfect, bus I have only one more question. How can I add arguments to the functions I create? Thank you very much for your help.

0 Likes

#6

You could do something like:

[pre=#2A2A2A]{
“scope”: “source.lua”,

    "completions":
    
            "createNewButtonWithPreferences(${1:firstArg},${2:secondArg})$0",
            "someOtherFunctionWithALargeName(${1:firstArg})$0"
    ]

}[/pre]
This creates tabstops within the snippet. More info here: docs.sublimetext.info/en/latest/ … ppets.html

0 Likes