Sublime Forum

Add parentheses to method names

#1

I imagine ST knows when a certain string is a method name. When I press cmd + R it lists all the methods in a file.

So… is it possible that when autocomplete throws a method name, after pressing tab, ST automatically adds parentheses after the method and move the cursor inside those parentheses?

Please excuse my ignorance if this already exists. I havent’ been able to find any package or info about that.

0 Likes

#2

bump

Maybe I wasn’t clear in my description…

If found string = function then add “()” and move cursor in between parentheses.

Is that possible?

0 Likes

#3

Currently it is not possible to automatically check if autocomplete item is function using sublime api.
But there is some sublime plugins that perform syntax analisis. May be, you can tweak such a plugin to get desired behavior. But, i won’t recommend this. In many (if not most) of languages one can use function in expression without calling it. And parentheses will not be welcome in that case.

If you have few functions, which you call frequently, snippets could help.

0 Likes

#4

That’s a shame…

Creating snippets for methods in the current project is not as straightforward as I wanted… I wanted to use the all auto complete package but it doesn’t work quite right either.

I will add a feature request to user Echo.

0 Likes

#5

As mentioned by the previous poster, we will not always want to add the brackets. Besides which, having accepted the completion-word, we only need to type an opening bracket… So I hope that this feature is not added :smiley:

0 Likes

#6

The thing is that if this feature was implemented, it should go a step beyond and also generate an “automatic snippet” with all methods parameters so you wouldn’t need to go and check the method definition. That way it should be pretty easy to erase all parameters if you wanted to use the method name as a reference, a parameter in another method, etc. Of course this should be customized in languages where you don’t need parentheses, but you’d get the benefit of the automatic parameters too.

What you are suggesting is the way it’s implemented now: you don’t get auto complete with methods from other files, you have to manually go check the method definition, and write parentheses, parameters and commas.

I really don’t see how having to manually go check the definition and writing everything is better. It’s like going back to notepad IMHO.

0 Likes