4

I'm using sublime text 3 for python development. I have autocompletion turned on as I type, which works. I expect, that when I type an object name followed by a period, a list of object's methods/attributes would popup. It does not happen, so I press Tab.

import time
time.[TAB]

What happens now, is just absolutely weird! . is replaced by self., so I end up with

import time
timeself.

I was looking in all setting files, I tried packages python completions, code intel and code complice, but none of them disabled this "feature", which drives me crazy!

Finally, I have found Jedi package, which solved this issue for the text editor. But I still have problems in the interpreter window (package SublimeREPL). By the way, if I install both Jedi and code complice, the autocompletion in the REPL seems to work better, but it offers some irrelevant crap like %%! or %%HTML. And yes, if I press [TAB] twice, I still end up with timeself. instead of time.!

Does anyone know what's going on? Where this . -> self. behavior is coming from? How to disable %%! stuff?

R Kiselev
  • 1,124
  • 1
  • 9
  • 18

2 Answers2

6

I had this problem myself, and it was not easy to track down.

The problem is not caused by any package. I found out after running default built of Sublime text 3. While I highly recommend Anaconda (as mentioned by MattDMo), the problem can occur also when Anaconda is installed.

The problem:

The cause of the problem is the default Python snippet shipped with Sublime Text 3 called self.sublime-snippet and looks like this:

<snippet>
    <content><![CDATA[self.]]></content>
    <tabTrigger>.</tabTrigger>
    <scope>source.python</scope>
    <description>self</description>
</snippet>

In Sublime text 2, this file can simply be removed, but the default snippets in ST3 isn't stored in the same way, so there is no way to easily delete this file.

The solution:

This stack overflow answer explains how to extract the package information for a language, in this case Python. The snippet can then be deleted as normally.

Update:

The snippet has now been removed in the source code due to this problem. Probably included in next update. Source: https://github.com/sublimehq/Packages/issues/473

Community
  • 1
  • 1
Martin Hallén
  • 1,492
  • 1
  • 12
  • 27
  • 2
    Thank you so much! I used PackageResourceViewer to find this snipped, then I replaced `self.` with `.` in the second line of the snipped. Now autocompletion pops up on the tab key, but annoying "self" word is not inserted! – R Kiselev Jun 15 '16 at 16:14
  • Perfect! Glad to hear :) You can also delete the whole `self.sublime-snippet`-file if you want to, so the tooltip doesn't show an option for selecting that snippet. – Martin Hallén Jun 15 '16 at 16:16
  • For some reason autocompletion stops to working if I simply delete the snipped - so I left it there, but changed. – R Kiselev Jun 16 '16 at 13:42
  • Yes, you might have to force the suggestion box to open on `.` if the snippet is removed. If you use Anconda (as I believe you do), you can do this by this method: http://damnwidget.github.io/anaconda/IDE/#toc_3 – Martin Hallén Jun 16 '16 at 13:46
3

I would highly recommend getting rid of your other completion packages and install Anaconda (no relation to the Anaconda Python distribution). I've been using it for a couple of years now, and I absolutely love it. Basically all you need to do to set it up is provide a path for "python_interpreter" in Anaconda's settings or in your project's settings, and it just works. No taking forever to index everything like SublimeCodeIntel, and no need to set up a separate linter if you don't want to, because several linters are built-in. Virtualenvs are seamless. Anaconda will see all the modules available to the version of Python specified by "python_interpreter", so you don't need to worry about adding extra paths to the environment through settings. Make sure you copy all of the default settings file into the user settings file, then change the options as needed. Project-specific settings override user settings, so you can customize even more by editing your project.

BTW, I'm not affiliated with the project in any way, except for a minor pull request or two, I'm just a very satisfied user.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Anaconda is wonderful! Works like a charm! Thank you so much for this hint! – R Kiselev Apr 29 '16 at 20:41
  • @MattDMo: Any reason for editing my answer? The sentence you removed was not about gaining reputation points, it was about letting other people with the same problem finding the solution to the problem! As per now, your answer does not answer the question at all. – Martin Hallén Jun 15 '16 at 12:47
  • 1
    @mart0903 my solution works very well for me, and apparently for the OP as well, so it *does* answer the question. It may not work for you, and you are perfectly welcome to submit your own answer, but that's no reason to downvote mine. The sentence I removed from your answer - `Please consider accepting this answer, as it solves the problem and might be useful for future users.` is both inappropriate and redundant. **Every** answer on SO hopefully solves the problem, and will hopefully be useful for other readers - that's the whole point of answering. – MattDMo Jun 15 '16 at 13:08
  • 1
    @MattDMo: I agree that the sentence was redundant, ok. One point though: From http://stackoverflow.com/help/how-to-answer : "Read the question carefully. What, specifically, is the question asking for? Make sure your answer provides that – or a viable alternative." In your case, you answer is the typical "jQuery has a nice plugin for that!", when the question is "How to add two numbers in javascript". I don't agree that Anaconda is a viable **alternative**. Anyway, let's settle this, and work better together in the future. - Martin – Martin Hallén Jun 15 '16 at 13:18