auto completion on dot #32

Closed
dbrgn opened this Issue Oct 28, 2012 · 25 comments

Comments

Projects
None yet
10 participants
Collaborator

dbrgn commented Oct 28, 2012

  1 class Test(object):
  2     def __init__(self):
  3         self
                ↑

If you write the dot after self, it is automatically completed to self.__init__. So if I want to create/assign a new attribute, I first have to delete the __init__ part before being able to write the new name.

Owner

davidhalter commented Oct 28, 2012

Basically thats a vim problem. I guess there's probably an option to prevent that? However, until now I didn't do something about it, because magic methods will be introduced, which means that this won't be a problem anymore.

Collaborator

dbrgn commented Oct 28, 2012

Well, wouldn't it be possible to not automatically complete the word, but to offer the completion inside the "options menu"? In this case, the options menu doesn't even show up.

Shougo commented Oct 29, 2012

Basically thats a vim problem. I guess there's probably an option to prevent that? However, until now I didn't do something about it, because magic methods will be introduced, which means that this won't be a problem anymore.

I recommend for you to change the code in ftplugin/python/jedi.vim.

inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<C-X>\<C-O>" : ""<CR>

To:

inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<C-X>\<C-O>\<C-P>" : ""<CR>

The autocompletion should not select first candidate in default.

The autocompletion should not select first candidate in default.

+1

Shougo commented Oct 29, 2012

The autocompletion should not select first candidate in default.

Because to use auto completion selects first candidate is difficult.
I use the behavior autocompletion but I configured some keymappings in my .vimrc.
The beginner should not use it.

Contributor

mattn commented Oct 31, 2012

+1

Owner

davidhalter commented Nov 2, 2012

I try to do something by implementing magic methods (but I'm having difficulties to find time until Christmas). If you want something else (a VIM solution, which is basically the problem) you are free to propose solutions.
I have absolutely no idea, how I could solve this (but it's not a problem anymore, if magic methods are included).

@Shougo's suggestion worked for me (except that the existing line is slightly different).

I replaced

inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>" : ""<CR>

with

inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>\<lt>C-P>" : ""<CR>

Thanks! It helped me too! 👍

Owner

davidhalter commented Nov 18, 2012

This seems to be a VIM problem. Clearly I could do some nasty hacks, but I doubt that it would make sense.
I hope that introducing magic methods to jedi solves this (which I will be doing next).

BTW: I thought of something like this:

if stridx(&completeopt, 'longest') > -1                                     
    inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>\<lt>C-P>\<lt>C-P>\<lt>C-P>" : ""<CR>
else                                                                        
    inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>\<lt>C-P>" : ""<CR>

But it clearly isn't working properly in some cases.

Owner

davidhalter commented Nov 19, 2012

I added a few code lines to enable magic methods. Therefore this should solve this issue. However it's just solved because of a bug, that enables mro to be visible in instances (should only be visible within types).

davidhalter/jedi@03f4dd5 et al.

The autocompletion should not select first candidate in default.

Isn't that the main issue? Will this be fixed?

Owner

davidhalter commented Dec 11, 2012

It should already be fixed. Not the VIM part, I couldn't come up with a solution (VIM's strange sometimes). But magic functions are displayed now, which take care of this, because there are always multiple candidates.

Interesting. The above suggested snipped worked for me:

inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>\<lt>C-P>" : ""<CR>
Owner

davidhalter commented Dec 11, 2012

Which version of jedi/jedi-vim are you using?

also, please post :set completeopt.

Actually I don't see a reason why this is still an issue.

almet commented Dec 11, 2012

@davidhalter and what about the solution proposed by @Shougo and @treyhunner ? It seems to do what I want.

Owner

davidhalter commented Dec 11, 2012

@ametaireau It doesn't work for all cases, see: #32 (comment).

However, I probably see what the problems of @ametaireau and @halst are. You didn't set set completeopt=menuone,longest,preview but rather to set completeopt=menuone,preview. Right?

I probably can use @treyhunner's solution for this particular case (in the case of longest it doesn't work). What do you think?

almet commented Dec 11, 2012

I just installed it and didn't touched anything & that works with the change pointed out.

:set completeopt gives completeopt=menu,preview

I used the latest master of jedi-vim (about an hour ago), and did git submodule update --init as prescribed.

Owner

davidhalter commented Dec 11, 2012

@halst @ametaireau I fixed it now, if longest is not set (which I would recommend). Please try and tell me if it's working.

If longest is set, you won't have a problem because there's always magic methods around and mro.

It works now, thanks.

j5shi commented Mar 6, 2014

No, this bug has not been fixed, it still exists. I'm using the latest jedi-vim and also jedi, with completeopt=menuone,longest,preview, jedi-vim still select the first candidate automatically sometimes.

I mean, sometimes, first you select a word, then delete it (also the dot) using backspace and then keep pressing dot again, sometimes, abort (the first candidate) will be selected automatically, just as follows!

untitled

Owner

davidhalter commented Mar 6, 2014

You've opened a new issue, so I'm keeping this one closed.

Shougo commented Mar 6, 2014

I mean, sometimes, first you select a word, then delete it (also the dot) using backspace and then keep pressing dot again, sometimes, abort (the first candidate) will be selected automatically, just as follows!

You should map <BS> and <C-h>

inoremap <expr><C-h>    pumvisible()? "\<C-y>\<BS>" : "\<BS>"
inoremap <expr><BS>    pumvisible()? "\<C-y>\<BS>" : "\<BS>"
Owner

davidhalter commented Mar 6, 2014

But that always removes the popup menu if using backspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment