-
Notifications
You must be signed in to change notification settings - Fork 6
Various fixes for pythoncomplete.vim #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Prior to this patch opening parenthesis were not considered part of the current word, so a completion token such as ``myfunc(`` would never test positive for a trailing ``(``.
This patch fixes completion of parameters required by a class when creating a new instance. For example completing ``MyClass(`` should take the parameters from ``MyClass.__init__``. The ``_ctor`` closure within ``Completer.get_arguments`` always raised a NameError exception because the function signature named its incoming argument ``obj`` rather than ``class_ob``.
The test that determined if ``func_obj`` is a class did not cope with meta-classes (which are both a class, and a type). Generally ``type()`` is not a robust way to reason about the Python objects, so this patch replaces all checks of the form:: type(foo) == types.FooType with calls to the ``inspect`` module, for instance:: inspect.isclass(foo) inspect.ismethod(foo) inspect.isfuction(foo)
Completed parameters are space and comma seperated, instead of just being comma seperated. Old behaviour:: myfunc(a,b,c) New behaviour:: myfunc(a, b, c) This better matches common practice, and the exampels in PEP 8 [1]_. If this upsets established users, a configuration variable could be created to control it. .. [1] http://www.python.org/dev/peps/pep-0008/
Regarding my proposal to rename the script (to FWIW, I believe that |
This patch renames ``pythoncomplete.py`` to ``python_complete.py`` since the latter is automatically loaded by Vim (tested with v7.3). Using Vim's tracing feature (e.g. ``vim -Vtrace.log somefile.py``) I discovered that Vim does not automatically load ``$HOME/.vim/ftplugin/pythoncomplete.vim`` without additional configuration, it only considers the following:: Searching for ftplugin/python.vim ftplugin/python_*.vim ftplugin/python/*.vim in $HOME/.vim /var/lib/vim/addons /usr/share/vim/vimfiles /usr/share/vim/vim73 /usr/share/vim/vimfiles/after /var/lib/vim/addons/after $HOME/.vim/after Note that the default distribution of Vim v7.3 [1]_ includes `ftplugin/python.vim` which contains the following line:: setlocal omnifunc=pythoncomplete#Complete This conflicts with the changed introduced in this patch, and is no longer needed (since this script now sets 'omnifunc' itself). .. [1] At least, it does on Ubuntu v11.10's "vim-runtime" package, version "2:7.3.154+hg~74503f6ee649-2ubuntu3"
Until the stock `ftplugin/python.vim` drops its definition for 'omnifunc' `python_complete.vim` must be loaded after system defaults to ensure it is actually used. Should this version of `python_complete.vim` become the new stock version, users should install future updates into `$HOME/.vim/ftplugin`, since a guard at the top of the script will preventing existing definitions being replaced.
It comes by default, but I hadn't exposed it in the SuperTab configuration. I better source/investigate a better omnicomplete function, such as: https://github.com/mjbrownie/pythoncomplete.vim vim-scripts/pythoncomplete#1 but for now, this will do. I'll have to search for a way to customize the preview window that appears on top of the window containing the pydoc for the corresponding function (Hot Damn! It's starting to look like a proper IDE).
Please consider my commits for inclusion in pythoncomplete.vim. Most are bug fixes related to the completion of callable (function/class-constructor) parameters.
There are also 2x enhancements: parameter completion adds a space after commas, a newline at the end of the file (to stop git complaining).
I've also RENAMED the script from pythoncomplete.vim to python_complete.vim since the former is not automatically loaded by Vim (v7.3), but the latter is. Please see the commit log for my full justification.
And let me say thanks for producing such a useful script!