tab completion in Ipython buffers

Bug #916869 reported by Richard Everson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

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.

Revision history for this message
Richard Everson (r-m-everson) wrote :
Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.0.5
importance: Undecided → Medium
Changed in python-mode:
status: New → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi Richard,

that bug should be fixed. Please re-open if otherwise,

Cheers,

Andreas

Revision history for this message
Andreas Roehler (a-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

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

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 ...

Read more...

Revision history for this message
Andreas Roehler (a-roehler) wrote : was: Re: [Bug 916869] tab completion in Ipython buffers

Am 21.01.2012 19:10, schrieb Richard Everson:
[ ... ]
Hi Richard,

thanks a lot for the patch.

Could not look at it closer yet; just some ideas, as the completion
issues affects other reports/request too, true auto-completion is ahead.

(completion-at-point) says:

"Complete the thing at point according to local mode.
This runs the hook `completion-at-point-functions' until a member
returns non-nil."

That's basically the proceeding I'm heading to: py-complete-function
should hand over a list of completion-functions sorted with resp. to
environment.

So far just an idea.

As sometimes it might not be obvious what's the best path to choose, it
might be of interest having alternatives. Should you reach a point where
you want to see something, while a different path has been chosen here,
please don't hesitate to open a personal branch, so we may play with it.
All you need AFAIK is applying to be member of the team, which is
nothing more than a formality.

Afterwards

bzr push lp:~MY-NAME/python-mode/MY-BRANCH

should do it.

So far from this morning,
Cheers,

Andreas

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 916869] tab completion in Ipython buffers
Download full text (4.2 KiB)

Am 21.01.2012 19:10, schrieb Richard Everson:
> 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.

Agreed, basically. Thanks for the helpful example.

Remains the task to get the stuff back from the IPython process.

       (process-send-string python-process
                            (format completion-command-string pattern))
       (accept-process-output python-process)

etc. So we need some Emacs Lisp here, let's call it ipython-complete.

  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 have buffers continually popping up. How about providing a null
> completion function for ipython-complete-function? What do you think?
>

Will make ipython-complete the default and also cite your comment inside
the docstring of `ipython-complete-function', so people are advertised
not to change it.

Thanks a lot,

Andreas

> 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:
...

Read more...

Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.