JulianEberius / SublimeRope

ST2 only, use SublimePythonIDE with ST3: Adds Python completions and some IDE-like functions to Sublime Text 2, through the use of the Rope library
GNU General Public License v2.0
250 stars 26 forks source link

Rope exludes () when autocompleting #43

Closed jcldavid closed 11 years ago

jcldavid commented 12 years ago

For example when I type:

app.

then I press ctrl+space (how do I make the functions automatically appear?), then I press tab, the () are not included. So it becomes:

app.run

instead of

app.run()

Is there a way to make it insert the () automatically?

DamnWidget commented 12 years ago

Hi @Apathetic012

We should wait what @JulianEberius says about this issue but I don't see the easy way to perform this change because I think the only behavior what we can control about auto-completion is just for the proposal words list not the behavior of adding the selected word code to the buffer.

JulianEberius commented 12 years ago

Motivated by your question I looked a bit more into what information Rope provides with the completion proposals, and what ST2's API allows. It was in fact quite simple to implement your request, and even more: Sublime Rope will now insert not only the function name and the "()" for functions without arguments, but also a snippet with the argument names that you can tab through if there are arguments. For example, "os.geten" will insert os.getenv(key, default) with "key" selected, and TAB jumping to "default".

Please report if it works for you!

p.s.: This new behavior can also be disabled using the "add_proposal_snippet" setting. p.p.s.: Concerning your question about how to make the completions appear automatically: This has nothing to do with SublimeRope I think, it is ST2 behavior which you can change with a setting called "auto_complete" (should be set to True)

DamnWidget commented 12 years ago

Interesting @JulianEberius I didn't know about this ST2's API possibilities. I'll read your last changes in detail :)

JulianEberius commented 12 years ago

Basically, ST2 allows you to return not only plain strings as proposals but also strings in it's (or originally, TextMate's) Snippet format.

You can look this up at http://docs.sublimetext.info/en/latest/extensibility/completions.html and http://docs.sublimetext.info/en/latest/extensibility/snippets.html

Julian

OscarL commented 12 years ago

@Apathetic012 / @JulianEberius:

It is actually quite easy to make SublimeText to show the autocomplete dialog automatically after typing the dot in, for example: "app.".

You just have to create a file named "Python.sublime-settings" in Packages/User (in case you don't have one already), and there, you add a line like this:

"auto_complete_triggers": [ {"selector": "source.python - string - comment", "characters": "."} ],

So the autocomplete gets triggered when hitting "." (but only for Python source code, but not inside strings or comments :D).

For reference, here's more or less what I'm currently using for Python:

{
    "word_wrap": false,
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "use_tab_stops": true,
    "auto_indent": true,
    "trim_automatic_white_space": true,
    "trim_trailing_white_space_on_save": true,
    "auto_complete_selector": "source.python - string - comment - constant.numeric",
    "auto_complete_triggers": [ {"selector": "source.python - string - comment", "characters": "."} ],
}

The line "auto_complete_selector": "source.python - string - comment - constant.numeric", makes the autocomplete not to show inside strings or comments, but fails to do the same with literal hexadecimal numbers (that's seems to be a bug in ST2).

JulianEberius commented 11 years ago

Yes it works this way :-) -> closed