Comment 4 for bug 916869

Revision history for this message
Richard Everson (r-m-everson) wrote : Re: [Bug 916869] tab completion in Ipython buffers

Hi Andreas,

I don't know how to stop IPython from incrementing the prompt counter, but using py-completion-at-point just hangs emacs for me. If I start with a new IPython shell, then

In [1]: import sys

In [2]: sys.pa

then M-x py-completion-at-point, hoping to complete to sys.path, Emacs hangs. Escaping out of it shows that the *Python* buffer has the contents:

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'nil' is not defined
>>>

So I think it's best not to allow use of py-completion-at-point. Might just be my configuration, but I don't think so.

Attached is a patch (against revno 795) that inserts a tab if there's nothing to complete. Seems to work for the simple tests I've tried.

On the other hand, IPython's interaction and completion itself is pretty impressive (for versions greater than 0.10 at least): it inserts the correct indentation for for, if, etc and it will show completions even within a loop. Here's an example from a terminal shell:

In [1]:

In [1]: for i in range(3):
   ...: print i, sys.p<------------ Pressed tab here; indentation inserted automatically
sys.path sys.path_importer_cache sys.prefix
sys.path_hooks sys.platform sys.py3kwarning
   ...: print i, sys.path<------------ Pressed tab again
sys.path sys.path_hooks sys.path_importer_cache

So, I think there's a good argument for not doing *any* completion in the *IPython* buffer and just leaving it to IPython. I guess it might be nice to have the completions in a *Completions* buffer instead of the *IPython* buffer, but I'm not sure if it's an advantage and it's nice not to have buffers continually popping up. How about providing a null completion function for ipython-complete-function? What do you think?

Cheers,
Richard.

On 20 Jan 2012, at 21:55, Andreas Roehler wrote:

> BTW thanks for the patch.
>
> will still take
>
> + (substitute-key-definition 'complete-symbol 'completion-at-point
> + map global-map)
>
> as for completion in ipython-shell see doku of new ipython-complete-
> function
>
> well, must not be the end of all reasoning... :)
>
> Cheers,
>
> Andreas
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/916869
>
> Title:
> tab completion in Ipython buffers
>
> Status in An Emacs mode for editing Python code:
> In Progress
>
> Bug description:
>
> Hi Andreas,
>
> shell completion under ipython doesn't work because:
>
> a. New versions of Ipython have a different way of addressing the
> completer
>
> b. python-mode always calls py-shell-complete regardless of whether
> it's a Python shell or an IPython shell.
>
> The attached patch fixes both these. I've commented out py-shell-
> complete function because it's not referred to anywhere else in
> python-mode.el and would need to be a bit more sophisticated not to
> call ipython-complete for Python shells and py-shell-complete for
> IPython shells. Also got rid of a remaining definition of python-
> shell-map that I think should have been py-shell-map.
>
> Hope this makes sense. Probably related to bugs #912919 and #894666
>
> Best,
> Richard.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/python-mode/+bug/916869/+subscriptions