completion doesn't work on GNU Emacs (mac)

Bug #1284141 reported by Seong-Kook Shin on 2014-02-24
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Medium
Andreas Roehler

Bug Description

- Emacs Version 24.3 (from http://emacsformacosx.com/)
- python 2.7.5 (shipped by Apple)
- python-mode version 6.0.10 (from package.el)

When I completing in "*Python*" buffer, the completion didn't work.

In that buffer, after I typed "import socket", and in the next line "socket.<TAB>", then the buffer shows
>>> exec '''\ndef print_completions(namespace, text, prefix=''):\n for name in namespace:\n if name.startswith(text):\n print(prefix + name)\n\ndef complete(text):\n import __builtin__\n import __main__\n if '.' in text:\n terms = text.split('.')\n try:\n if hasattr(__main__, terms[0]):\n obj = getattr(__main__, terms[0])\n else:\n obj = getattr(__builtin__, terms[0])\n for term in terms[1:-1]:\n obj = getattr(obj, term)\n print_completions(dir(obj), terms[-1], text[:text.rfind('.') + 1])\n except AttributeError:\n pass\n else:\n import keyword\n print_completions(keyword.kwlist, text)\n print_completions(dir(__builtin__), text)\n print_completions(dir(__main__), text)\ncomplete('socket.')''' in {}^M_

(I marked the point at the end of line as '_')

Don't know why it does not execute the line but stopped at that line.

But, when I press <RET>, then it shows the completion as expected.

Changed in python-mode:
importance: Undecided → Medium
assignee: nobody → Andreas Roehler (a-roehler)

Am 24.02.2014 15:24, schrieb Seong-Kook Shin:
> Public bug reported:
>
> - Emacs Version 24.3 (from http://emacsformacosx.com/)
> - python 2.7.5 (shipped by Apple)
> - python-mode version 6.0.10 (from package.el)
>
> When I completing in "*Python*" buffer, the completion didn't work.
>
> In that buffer, after I typed "import socket", and in the next line "socket.<TAB>", then the buffer shows
>>>> exec '''\ndef print_completions(namespace, text, prefix=''):\n for name in namespace:\n if name.startswith(text):\n print(prefix + name)\n\ndef complete(text):\n import __builtin__\n import __main__\n if '.' in text:\n terms = text.split('.')\n try:\n if hasattr(__main__, terms[0]):\n obj = getattr(__main__, terms[0])\n else:\n obj = getattr(__builtin__, terms[0])\n for term in terms[1:-1]:\n obj = getattr(obj, term)\n print_completions(dir(obj), terms[-1], text[:text.rfind('.') + 1])\n except AttributeError:\n pass\n else:\n import keyword\n print_completions(keyword.kwlist, text)\n print_completions(dir(__builtin__), text)\n print_completions(dir(__main__), text)\ncomplete('socket.')''' in {}^M_
>
> (I marked the point at the end of line as '_')
>
> Don't know why it does not execute the line but stopped at that line.
>
> But, when I press <RET>, then it shows the completion as expected.
>

Checked in a fix. Please tell it it's done for you.

Changed in python-mode:
status: New → Fix Committed
Seong-Kook Shin (cinsky) wrote :

Using the current trunk, the symptom is fix.

However, it dumped the all candidates in the "*Python*" buffer, which looks somewhat annoying.

For example, when I try to complete from "socket.SO", it dumps following output in "*Python*" buffer:

>>> 'socket.SOCK_DGRAM;socket.SOCK_RAW;socket.SOCK_RDM;socket.SOCK_SEQPACKET;socket.SOCK_STREAM;socket.SOL_IP;socket.SOL_SOCKET;socket.SOL_TCP;socket.SOL_UDP;socket.SOMAXCONN;socket.SO_ACCEPTCONN;socket.SO_BROADCAST;socket.SO_DEBUG;socket.SO_DONTROUTE;socket.SO_ERROR;socket.SO_KEEPALIVE;socket.SO_LINGER;socket.SO_OOBINLINE;socket.SO_RCVBUF;socket.SO_RCVLOWAT;socket.SO_RCVTIMEO;socket.SO_REUSEADDR;socket.SO_REUSEPORT;socket.SO_SNDBUF;socket.SO_SNDLOWAT;socket.SO_SNDTIMEO;socket.SO_TYPE;socket.SO_USELOOPBACK'
>>> socket.SO_USELOOPBACK

Is that intentional?

Thanks,

Seong-Kook Shin (cinsky) wrote :

One more comment:

I think those contents should be parsed and goes to some "*completions*" buffer.

Thanks,

Am 25.02.2014 14:07, schrieb Seong-Kook Shin:
> One more comment:
>
> I think those contents should be parsed and goes to some "*completions*"
> buffer.

That's the way it is supposed to work. So there is a bug still.

Changed in python-mode:
status: Fix Committed → New
Andreas Roehler (a-roehler) wrote :

Checked in some changes, please try again.

Seong-Kook Shin (cinsky) wrote :

Actually, the symptom is same, no "*completion*" buffer, but dumps the candidates (separated by ';') in "*Python*" buffer.

Andreas Roehler (a-roehler) wrote :

Am 28.02.2014 15:21, schrieb Seong-Kook Shin:
> Actually, the symptom is same, no "*completion*" buffer, but dumps the
> candidates (separated by ';') in "*Python*" buffer.
>

Checked in some changes again.

Please try the following:

Start from emacs -Q

Load python-mode.el, make sure no compiled "*.elc"-file is around.
M-x python RET

insert "import socket"
RET
insert "socket."

M-TAB

Seong-Kook Shin (cinsky) wrote :

Even with your support, python-mode still gave me the same bug.

I tried to follow the code step by step with edebug, and found the culprit. I think `py-send-string-no-output' has some timing issue.

I set the breakpoint at `py-send-string-no-output`, then typed "socket." and pressed M-TAB:
and followed the control step by step. Then it works perfectly!

If I remove that breakpoint, and set another one in the parent function, `py-shell-completion--get-completion', then

Seong-Kook Shin (cinsky) wrote :

(continued from the previous comment)

python-mode calls

(py-shell-completion--get-completions "socket." ...)

then, it returned

("'.join(__COMPLETOR_all_completions('''socket.'''))^M")

, which was totally different from what I got from the edebug session.

I guess that `py-send-string-no-output` has some timing issue. I guess that it did try to analyze the output before the comint buffer receives the candidates from the python process.

Hope this will help.

Thank you

Andreas Roehler (a-roehler) wrote :

Am 01.03.2014 10:45, schrieb Seong-Kook Shin:
> (continued from the previous comment)
>
> python-mode calls
>
> (py-shell-completion--get-completions "socket." ...)
>
> then, it returned
>
> ("'.join(__COMPLETOR_all_completions('''socket.'''))^M")
>
> , which was totally different from what I got from the edebug session.
>
> I guess that `py-send-string-no-output` has some timing issue. I guess
> that it did try to analyze the output before the comint buffer receives
> the candidates from the python process.
>
> Hope this will help.
>

Your guess might be right. The delay for receiving results from process is 11 miliseconds
currently, a little bit short probably.

Please change py-send-string-no-output in line with

(accept-process-output process nil 11)

into

(accept-process-output process 1)

i.e. delay of one second. You might even try a higher value.

Thanks!

Seong-Kook Shin (cinsky) wrote :

I'm not elisp expert, but according to the documentation string, following sexp will take 1 second whether or not there is any subprocess output, right?

  (accept-process-output process 1)

On my darwin Emacs 24.3, it does take 1 second when I step the code using edebug. However, without edebug, when I press M-TAB, it does not take 1 second. (AFAIK it should take 2 seconds; 1 second for "import socket", then 1 second for completing "socket.")

Perhaps it is a darwin Emacs bug?

Andreas Roehler (a-roehler) wrote :

Am 03.03.2014 15:57, schrieb Seong-Kook Shin:
> I'm not elisp expert, but according to the documentation string,
> following sexp will take 1 second whether or not there is any subprocess
> output, right?
>
That's a minimum to wait. At least it will return after. Maybe earlier if completed, don't know.

> (accept-process-output process 1)
>
> On my darwin Emacs 24.3, it does take 1 second when I step the code
> using edebug. However, without edebug, when I press M-TAB, it does not
> take 1 second. (AFAIK it should take 2 seconds; 1 second for "import
> socket", then 1 second for completing "socket.")
>
> Perhaps it is a darwin Emacs bug?
>

Might be many reasons.
Did you try a higher value?

Seong-Kook Shin (cinsky) wrote :

Even if I modified to 5 seconds delay, M-<TAB> instantly returned with wrong result.

Fortunately, ipython completion work perfectly normal. I guess I'll stick to the ipython completion for a time being.

Thank you for supporting so far.

Andreas Roehler (a-roehler) wrote :

Am 04.03.2014 12:02, schrieb Seong-Kook Shin:
> Even if I modified to 5 seconds delay, M-<TAB> instantly returned with
> wrong result.
>

I.e. right result but inserted in wrong buffer?

> Fortunately, ipython completion work perfectly normal. I guess I'll
> stick to the ipython completion for a time being.
>
> Thank you for supporting so far.
>

I'll keep it open for a while.
Should others experience that bug also, please report here with some example code.

Seong-Kook Shin (cinsky) wrote :

Sent from my iPhone

> On 2014. 3. 5., at 오전 1:54, Andreas Roehler <email address hidden> wrote:
>
> Am 04.03.2014 12:02, schrieb Seong-Kook Shin:
>> Even if I modified to 5 seconds delay, M-<TAB> instantly returned with
>> wrong result.
>
> I.e. right result but inserted in wrong buffer?
>
Python code for listing completion candidates is excuted, but elisp couldn't catch it, the result is simply pasted into the *Python* buffer.
>> Fortunately, ipython completion work perfectly normal. I guess I'll
>> stick to the ipython completion for a time being.
>>
>> Thank you for supporting so far.
>
> I'll keep it open for a while.
> Should others experience that bug also, please report here with some example code.
Although not solved yet, you're the most responsive person whom I've report a bug to. thank you.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1284141
>
> Title:
> completion doesn't work on GNU Emacs (mac)
>
> Status in An Emacs mode for editing Python code:
> New
>
> Bug description:
> - Emacs Version 24.3 (from http://emacsformacosx.com/)
> - python 2.7.5 (shipped by Apple)
> - python-mode version 6.0.10 (from package.el)
>
> When I completing in "*Python*" buffer, the completion didn't work.
>
> In that buffer, after I typed "import socket", and in the next line "socket.<TAB>", then the buffer shows
>>>> exec '''\ndef print_completions(namespace, text, prefix=''):\n for name in namespace:\n if name.startswith(text):\n print(prefix + name)\n\ndef complete(text):\n import __builtin__\n import __main__\n if '.' in text:\n terms = text.split('.')\n try:\n if hasattr(__main__, terms[0]):\n obj = getattr(__main__, terms[0])\n else:\n obj = getattr(__builtin__, terms[0])\n for term in terms[1:-1]:\n obj = getattr(obj, term)\n print_completions(dir(obj), terms[-1], text[:text.rfind('.') + 1])\n except AttributeError:\n pass\n else:\n import keyword\n print_completions(keyword.kwlist, text)\n print_completions(dir(__builtin__), text)\n print_completions(dir(__main__), text)\ncomplete('socket.')''' in {}^M_
>
> (I marked the point at the end of line as '_')
>
> Don't know why it does not execute the line but stopped at that line.
>
> But, when I press <RET>, then it shows the completion as expected.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/python-mode/+bug/1284141/+subscriptions

Andreas Roehler (a-roehler) wrote :

Am 04.03.2014 23:32, schrieb Seong-Kook Shin:

>>
>> In that buffer, after I typed "import socket", and in the next line "socket.<TAB>",

If strickly done so, i.e. no RET after "import socket", that can't work.
Because M-TAB will send only the word-at-point, not the line before.

then the buffer shows
>>>>> exec '''\ndef print_completions(namespace, text, prefix=''):\n for name in namespace:\n if name.startswith(text):\n print(prefix + name)\n\ndef complete(text):\n import __builtin__\n import __main__\n if '.' in text:\n terms = text.split('.')\n try:\n if hasattr(__main__, terms[0]):\n obj = getattr(__main__, terms[0])\n else:\n obj = getattr(__builtin__, terms[0])\n for term in terms[1:-1]:\n obj = getattr(obj, term)\n print_completions(dir(obj), terms[-1], text[:text.rfind('.') + 1])\n except AttributeError:\n pass\n else:\n import keyword\n print_completions(keyword.kwlist, text)\n print_completions(dir(__builtin__), text)\n print_completions(dir(__main__), text)\ncomplete('socket.')''' in {}^M_
>>
>> (I marked the point at the end of line as '_')
>>

It looks like the wrong completion-code was taken

M-TAB is at py-shell-complete, right?

Your first report from old python-mode.el showed a wrong selection choosen by that function.

May you edebug it again and tell if py-commint--complete is employed?

Andreas Roehler (a-roehler) wrote :

Please check out again....

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

Other bug subscribers