Why does SuperTab output self when I press <tab>?
Asked Answered
O

1

11

The Setup

In my .vimrc I have the following lines:

" .vimrc
let g:virtualenv_directory="/Users/Kit/Development/virtualenv"

Then in ~/.vim/ftplugin/python/virtualenv.vim I have these:

py << EOF
import os.path
import sys
import vim
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    sys.path.insert(0, project_base_dir)
    activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))
    print "virtualenv in os.environ!"
EOF
VirtualEnvActivate my-virtualenv-python-2.7

In ~/.vim/ftplugin/python/virtualenv.vim I have these SuperTab settings:

setlocal omnifunc=pythoncomplete#Complete
setlocal completeopt=menuone,longest,preview
let g:SuperTabDefaultCompletionType="<c-x><c-]>"

In my working directory, where I always work from, I executed the following bash command to generate a TAGS file for all my .py files

find . -name '*.py' -type f -print0 | xargs -0 etags -l python

The problem

For example, I have a main.py which has an object app inside it, such that the following script works fine:

import main
new_app = main.app() # works totally fine Python-wise

If, for example, I write some new code and try to use SuperTab omnicompletion:

import main
new_new_app = main.<Tab>

This is what I get:

new_new_app = mainself.

And if I press Tab several times:

new_new_app = mainselfselfselfself.

What works for me

If, however, I do the following:

new_new_app = main.a<Tab>

I get a whole list of a.. objects that include those that don't belong to module main.

What I want

If I set the following in .vimrc:

let g:SuperTabDefaultCompletionType="context"

Then, I use a module from the standard Python library:

import sys
sys.<Tab> # This will still result in sysselfselfself.
sys.p<Tab> # This will result in the correct list of `sys` members beginning with `p`

But the "context" setting won't work on my own modules:

new_new_app = main.a<Tab>
# Will say at the bottom: Omni completion (^O^N^P) Pattern not found

The Question

How should I set up omnicompletion and SuperTab so that it behaves for my own modules as for the standard library modules? As well as eliminate the selfselfself. annoyance?

Odilia answered 8/2, 2012 at 12:31 Comment(3)
I may be wrong but I think SuperTab does what other similar plugins do: they try to guess the context and call the correct builtin omni-completion to propose the most accurate results. Did you try omni-completion without SuperTab? <C-x><C-o>, <C-x><C-]>, <C-x><C-u> What is the outcome? Also what Pyton completetion script do you use?Dyeing
@romainl, yes the key sequences you mentioned turn out all right. I think this is caused by a SnipMate bug. github.com/garbas/vim-snipmate/issues/65Odilia
Try reverting to the original SnipMate.Dyeing
W
5

As you point out, this is caused by snipmate: https://github.com/garbas/vim-snipmate/issues/65

I also proposed a solution: https://github.com/garbas/vim-snipmate/pull/84

It did not get accepted, because snipmate should not be context sensitive.

There are two solutions for this:

  1. Take my snipmate fork:

    https://github.com/davidhalter/vim-snipmate

    Which is probably not the best idea, since it's just my fork and I don't actively maintain it.

  2. Fork https://github.com/honza/snipmate-snippets and remove the mapping for the dot (Using the dot will not be possible anymore, to complete self).

Wilburnwilburt answered 7/4, 2012 at 23:10 Comment(1)
Thanks for the answer! I just cloned your fork and also discovered all the cool work you and others have been doing on the new fork of Snipmate! Excellent.Fader

© 2022 - 2024 — McMap. All rights reserved.