Friday, March 6, 2015

Re: Unable to get omnicomplete to work for Python 3.4.3.

On Fri, Mar 6, 2015 at 8:00 PM, boB Stepp <robertvstepp@gmail.com> wrote:
> On Fri, Mar 6, 2015 at 11:12 AM, boB Stepp <robertvstepp@gmail.com> wrote:
>>
>> I am not seeing anything in the help that I am seeing as a solution to
>> my dilemma. I guess I am going to bite the bullet, uninstall Vim and
>> reinstall it. Perhaps during installation it will see that there is no
>> Python 2 installed, only Python 3 and will configure itself
>> appropriately. Not elegant, but I do not know enough for an elegant
>> approach. At least this might eliminate a few things and make it
>> easier for further assistance. I'll let everyone know what transpires.
>
> I have continued to struggle with this all day. I do not understand
> vim scripting, file type detection, etc., but it is clear that my
> Python 3 files are not being recognized. If I am understanding things
> correctly when I write:
>
> filetype plugin indent on
>
> in my _vimrc file, this should lead to Vim checking the ftplugin
> directory to get the appropriate file for the detected file type and
> run that file. In each of my several installations today of different
> people's Windows installers for Vim 7.4, there is only one file
> pertaining to Python in the ftplugin directory, which is "python.vim"
> . Inside this file is the line:
>
> setlocal omnifunc=pythoncomplete#Complete
>
> which governs omnicompletion for Python2. The corresponding
> omnicompletion function for Python3 is python3complete#Complete, which
> obviously is never seen since it has no way to be called as Vim 7.4 is
> currently set up.
>
> Am I correct about this? If yes, how can I get a ftplugin file set up
> for Python3?

I guess where this whole process starts of deciding whether a Python
file is Python 2 or Python 3 starts with the file
$VIMRUNTIME/filetype.vim In it I found:

1621 " Python
1622 au BufNewFile,BufRead *.py,*.pyw setf python
1623
1624 " Quixote (Python-based web framework)
1625 au BufNewFile,BufRead *.ptl setf python

So in the current configuration of this file, any Python file in
Windows will be set as a file type of "python", which matches to
Python 2. To verify that this was in fact happening, I temporarily
changed line 1622's end to "setf python3". When I checked for file
type with :set ft?, it correctly returned python3 for one of my Python
files. In fact, typing <C-x><C-o> actually caused omnicomplete to try
to run, but it could not find a pattern match with any Python keywords
I tried typing in. I presume that this is because other files are
similarly set to file type "python".

It occurs to me that this filetype.vim could be improved by doing a
check for Python version in the shebang line of a Python file. IF the
programmer specifies something like, "#!/usr/env/bin Python3", then
Vim should then be able to settle on the correct Python version for
that particular program file. But then there are these unknown (to me)
number of other files that would have to be adjusted as well.

Have I analyzed this situation correctly? If yes, has anyone thought
about this and come up with a fix? If there is, for a relatively
standard Vim installation, I have so far not been able to find it. Of
course, there seems to be various collections of Python plugins for
Vim that add all kinds of great functionality, but all I wanted was
this relatively simple omnicompletion to work, so that while I am
learning Python, if I could not remember the correct syntax, then I
could hit <C-x><C-o> and see what I should be typing.

Anyway, I would think that if Vim is compiled for both Python 2 and 3,
then these basic features should work "out of the box" for both Python
versions. Am I being unreasonable here, or is my ignorance showing?

I will have to give up on omnicompletion for Python, and get back to
finalizing a basic set up for learning Python and learning how to
efficiently use Vim.

I've had quite an interesting couple of snow days looking into this!

Cheers!
boB

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment