VI auto completion Nonesense - python

I read that CTRL+P is the auto completion short cut in VI, but the recommendation given by the auto completion doesn't make that much sense to me.
Say from the re package there is a method called findall. Eclipse could recommend that method when I do CTRL+Space:
But When I tried the auto completion in VI, it could not find the findall method. the only recommendation seems like a command that I have typed before which has nothing to do with the re module.
Can Anyone give me some hints what is the auto completion story behind the CTRL+P in VI and how could I tune it up so it would be as good as Eclipse's auto completion.
(Every time I doubt the power of VI, the truth is always that it is me who lack the power to discover the beauty of VI)
Thanks!

In vim <C-p> is not the only completion shortcut available. Omni completion defined for python should be called with <C-x><C-o>, then use <C-n>/<C-p> to select variants. There are more completion types, all start with <C-x>, see :h ins-completion.
It is still better to use some third-party plugin (like jedi-vim or klen/python-mode) to get python completion as they are smarter. Note that at least klen/python-mode will not redefine <C-p>. They redefine <C-x><C-o> by setting 'omnifunc' option.

Without any additional modules, vim's autocompletion only searches the current file for occurences of the string you've started typing, regardless of whether it makes sense. If you use the tags file, via ctags or other, you're able to use strings across a variety of files, rather than just the current buffer.

Related

Enable python autocompletion in Vim without any install

I am coding Python3 in Vim and would like to enable autocompletion.
I must use different computers without internet access. Every computer is running Linux with Vim preinstalled.
I dont want to have something to install, I just want the simplest way to enable python3 completion (even if it is not the best completion), just something easy to enable from scratch on a new Linux computer.
Many thanks
Unfortunately Vim, by default doesn't do what you want, you are pretty much limited to the Ctrl-P style, which is better than it seems once you get used to it.
However i also often find myself working on machines that are not allowed to access the internet or have other files placed on them and When i find myself in this situation and i am using an unfamiliar language i sometimes use Vim's dictionary completion: http://vim.wikia.com/wiki/VimTip91
To populate this dictionary i cat / trim / filter the man pages for the language to get a variety of keywords. I ram these into a filetype specific dictionary: au FileType * execute 'setlocal dict+=~/.vim/words/'.&filetype.'.txt'
Obviously this isn't the greatest solution and it is a bit heavy handed but it does provide a certain degree of "What is that function called" type stuff.
If you have compiled vim with +python3, you can try omnifunc.
Add following to your ~/.vimrc:
au FileType python setl ofu=python3complete#Complete
Then in insert mode, just type CtrlX + CtrlO.
See :help omnifunc.
by default, Ctrl-P in insert mode do an autocompletion with all the words already present in the file you're editing

Emacs plugin to list all methods in a python module

Is there a emacs plugin which lists all the methods in the module in a side pane.
I am looking for a plugin which has keyboard shortcuts to show/hide all the methods in python module file currently opened.
I suggest using elpy.
C-c C-o runs elpy-occur-definitions which creates a new buffer with a list of all the class and function signatures.
You can navigate the list using C-n and C-p.
The mode works with next-error-follow minor mode.
So C-c C-f inside the buffer enables jumping to the class or function definition selected.
Here's an example of the contents of that buffer:
8 matches for "^ *\(def\|class\) " in buffer: leveling_utils.py
11:def leveling(episodes_with_potential_associations_by_member):
26:def _apply_leveling(sorted_episodes):
41:def _set_non_chronic_associations(episode):
73:def _apply_sub_to_procedural_association(assoc):
94:def _set_chronic_associations(episode):
102:def _set_associations_for_self(episode):
118:def _set_to_actual(association):
122:def _log_actual_associations(member, leveled_episodes):
By the way, it has many other useful features that to me, make it a necessary addition to python-mode.
For the first question, use M-xspeed-bar, like Alex suggested.
For the second, enable hs-minor-mode, M-xhs-minor-mode, and use C-cC-#C-S-h to hide all methods, and C-cC-#C-S-s to show.
You can look to ECB (it's better to take my fork of it, as it's adapted to fresh Emacs & CEDET) - it can display information about source code fetching it from Semantic (CEDET subpackage) or via imenu (for languages that aren't supported by Semantic).
Speedbar (included into GNU Emacs) can also show a list of top level objects, but doesn't show differences between imports, functions of other top-level stuff
For me, the easiest and most convenient method to quickly lookup methods is the command helm-occur (C-x c M-s o). You start typing the name of the method you want to jump to and suggestions start popping in as you type. Then you hit enter to select the one you want and your cursor jumps right there in the code. Helm-occur wasn't strictly written for this purpose, but works quite well that way.
Speedbar is good, and another nice alternative is helm-imenu. I've bind several keys to access it quicky from different contexts and use it most of the time

Python.el and Python-mode: Documentation & Features

I have been reading about the different Python packages available for Emacs for some time. However, I have never been able to find the official documentation of either package.
From what I understand, python-mode seems is hosted at launchpad, but the repository does not have a wiki nor a document explaining the features, etc. On the other hand, python.el comes with recent versions of Emacs, but I can't find a documentation walkthrough its features anywhere.
Also, do both of them support step-by-step debugging through ipdb ipython? Where can I find more information on this matter?
Comments following ;;; Commentary is a good starting point, as #lunaryorn suggested. If you need setup read this part first.
But I think just start using it when your setup is done (for python.el, there is nothing to do if you use Emacs 24.3) is the best way to go through the features.
This is because Emacs is self-documenting editor. You can read all document about Emacs in Emacs. In Python buffer, use <f1> b (or C-h instead of <f1>) to see a list of command you can use (this is the list of features). Each command is linked to the docstring of the command. You can also open a menu using "Ctrl + Right Click" to see a list of command you can use in the buffer. The document of python-mode function, which can be opened by <f1> f python-mode RET, may be another good starting point. If you want to see documentation of some keybind, type <f1> k KEY-BIND. There are more useful help commands. See <f1> <f1> for more info. These techniques are not specific to python-mode, so you can use them for python.el and python-mode.el.
Re ipdb: python.el (and I guess python-mode.el also) can do it. There is code snippet in ;;; Commentary that you can use in Emacs configuration.
https://blueprints.launchpad.net/python-mode/+documentation
This offers some basic FAQs meanwhile.
python-mode.el is designed to support ipdb and all other debuggers right from the spot. Configuration as explained at top of python.el isn't needed, as these stuff is implemented. Most commands are self-explaining. Every command has a documentation string, which users will find useful for some features like py-expression. Also the return values are reported there.
To get an overview which commands exist, the menu is a good starting point.
http://www.gnu.org/software/emacs/manual/html_node/emacs/Menu-Bar.html
python-mode.el lists commands alongside with its explanations in directory "doc".
Read the comments as suggested. Afterwards maybe employ outline-mode or hs-minor-mode to take a tour of the symbols.
Finally: M-x py- TAB, resp. M-x python- TAB lists the implemented commands. Once the name is known, call it's docu Ctrl-h f
Both modes should work with IPython/ipdb.
Seem several howto's at the net.
Maybe consult this
http://gremu.net/blog/2010/using-ipythons-debugger-pdb-replacement/
Please file a bug-report if you can't make it work.
As for with python-mode.el:
https://bugs.launchpad.net/python-mode
As for python.el : M-x report-emacs-bug RET

Quickhelp for Python in Emacs autocomplete.el?

I am using Emacs 23.1.1 on GNU/Linux with autocomplete.el 1.3 and Ropemacs 0.6.
In Lisp programming, autocomplete.el shows the documentation (known as 'QuickHelp' in autocomplete.el) of the suggested completions. Python completion with ropemacs works, but does not show quick help for the Python completion. Is it possible to enable it and did somebody make it work?
Ropemacs does the job : Use the function rope-show-doc over the symbol or use the keybinding C-c d. Simple :)
I stopped using all the autocomplete stuff in all my developing environments. They rarely do what I want. Either the lists is too long, or too short, or not sorted well. Therefore I use dabbrev-expand in all my modes global-set-key to tab.
This works even quote well for text. Usually it is enough to get a good expansion from the local buffer where you are in. If I start typing in an empty buffer I open a second one which expand can use to look up its suggestions. This is not language sensitive, not does depend on the object you want to call a method of, but its still a big boost, and you get used to it. Maybe its not, you don't get "quick help" this way.

How can I get Geany to show me the methods a library has when I press the '.' key?

In visual studio, I could just press ctrl+spacekey and the methods appeared. In Geany is there a way for me to get this functionality?
No, because is Python is dynamically typed language and quite hard to achieve that. Python plugins for netbeans do that partially, but I believe such plugin is not in geany developers plans. There are different things to be done ;-)
However, geany provides some completions support. First, it analyzes your imports in a file and uses it in completions; furthermore it completes functions from the std library. It also analyzes all you open files for suggestions, although you may need to apply it in preferences. Also you can get call tips, when you hit Ctrl+Shift+Space, which not everyone know about. They are quite good, because they appear in form <Class>.<method>(<args>), which is very helpful.
shortcut ctrl+space works for me. also, you can setup autocomplete suggestion length (ie how many letters you must type before the autocomplete tooltip pops up automatically - http://www.geany.org/manual/current/#editor-completions-preferences ).
this works only for method names. if i want to see the options for method parameters, i must type bracket ( after the method full name.

Categories

Resources