GNU bug report logs - #48609
Eglot and tab-always-indent conflict in python-mode

Previous Next

Package: emacs;

Reported by: Pankaj Jangid <pankaj <at> codeisgreat.org>

Date: Sun, 23 May 2021 14:56:04 UTC

Severity: normal

To reply to this bug, email your comments to 48609 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to joaotavora <at> gmail.com, bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Sun, 23 May 2021 14:56:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Pankaj Jangid <pankaj <at> codeisgreat.org>:
New bug report received and forwarded. Copy sent to joaotavora <at> gmail.com, bug-gnu-emacs <at> gnu.org. (Sun, 23 May 2021 14:56:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Pankaj Jangid <pankaj <at> codeisgreat.org>
To: bug-gnu-emacs <at> gnu.org
Subject: Eglot and tab-always-indent conflict in python-mode
Date: Sun, 23 May 2021 20:25:28 +0530
If ‘eglot’ is running and ‘tab-always-indent’ is set to ’complete. Then
in python-mode, TAB doesn’t cycle point column positions. For example,
in the following code if you are at end of line 2 and then you press RET
then TAB doesn’t move the point to left margin. Without ‘eglot’ this
works fine.

#+begin_src python
def greet(s):
    print(f"Hello {s}!")
#+end_src




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Sun, 23 May 2021 20:42:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Sun, 23 May 2021 21:41:22 +0100
Pankaj Jangid <pankaj <at> codeisgreat.org> writes:

> If ‘eglot’ is running and ‘tab-always-indent’ is set to ’complete. Then
> in python-mode, TAB doesn’t cycle point column positions. For example,
> in the following code if you are at end of line 2 and then you press RET
> then TAB doesn’t move the point to left margin. Without ‘eglot’ this
> works fine.
>
> #+begin_src python
> def greet(s):
>     print(f"Hello {s}!")
> #+end_src

Hello Pankaj,

I cannot reproduce this.  Here's what I ran:

  $ emacs --version | head -1
  GNU Emacs 26.3
  $ emacs -Q -f package-initialize -L ~/path/to/eglot/eglot -l eglot \
    ~/path/to/a/python/file.py -f eglot

This opens the file which has your example contents, and starts up
eglot.  I move point to the end of line 2, press RET and press TAB
twice.  Point is at the left margin.

Without Eglot, the result is exactly the same.

I would find it odd that Eglot messes with TAB behaviour, but I'm
waiting for a more complete reproduction recipe from your part so we can
understand what's going on.

João








Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Sun, 23 May 2021 21:03:02 GMT) Full text and rfc822 format available.

Message #11 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: Doug Davis <ddavis <at> ddavis.io>
To: João Távora <joaotavora <at> gmail.com>
Cc: 48609 <at> debbugs.gnu.org
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Sun, 23 May 2021 17:02:47 -0400
Hi João & Pankaj,

João Távora <joaotavora <at> gmail.com> writes:

> Pankaj Jangid <pankaj <at> codeisgreat.org> writes:
>
>> If ‘eglot’ is running and ‘tab-always-indent’ is set to ’complete. Then
>> in python-mode, TAB doesn’t cycle point column positions. For example,
>> in the following code if you are at end of line 2 and then you press RET
>> then TAB doesn’t move the point to left margin. Without ‘eglot’ this
>> works fine.
>>
>> #+begin_src python
>> def greet(s):
>>     print(f"Hello {s}!")
>> #+end_src
>
> Hello Pankaj,
>
> I cannot reproduce this.  Here's what I ran:
>
>   $ emacs --version | head -1
>   GNU Emacs 26.3
>   $ emacs -Q -f package-initialize -L ~/path/to/eglot/eglot -l eglot \
>     ~/path/to/a/python/file.py -f eglot

Just driving by, hopefully this is helpful; it looks like company may be
the missing ingredient. If I follow these steps but add:
`-L ~/path/to/company -l company`, run both

M-x company-mode
and
M-x eglot

with `tab-always-indent' set to 'complete I'm able to reproduce the
issue described by Pankaj. If I skip loading Eglot but only use company
the issue doesn't surface.

Cheers,
Doug




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Sun, 23 May 2021 21:18:01 GMT) Full text and rfc822 format available.

Message #14 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: Doug Davis <ddavis <at> ddavis.io>
Cc: 48609 <at> debbugs.gnu.org
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Sun, 23 May 2021 22:17:28 +0100
Doug Davis <ddavis <at> ddavis.io> writes:

> Hi João & Pankaj,
>
> João Távora <joaotavora <at> gmail.com> writes:
>
>> Pankaj Jangid <pankaj <at> codeisgreat.org> writes:
>>
>>> If ‘eglot’ is running and ‘tab-always-indent’ is set to ’complete. Then
>>> in python-mode, TAB doesn’t cycle point column positions. For example,
>>> in the following code if you are at end of line 2 and then you press RET
>>> then TAB doesn’t move the point to left margin. Without ‘eglot’ this
>>> works fine.
>>>
>>> #+begin_src python
>>> def greet(s):
>>>     print(f"Hello {s}!")
>>> #+end_src
>>
>> Hello Pankaj,
>>
>> I cannot reproduce this.  Here's what I ran:
>>
>>   $ emacs --version | head -1
>>   GNU Emacs 26.3
>>   $ emacs -Q -f package-initialize -L ~/path/to/eglot/eglot -l eglot \
>>     ~/path/to/a/python/file.py -f eglot
>
> Just driving by, hopefully this is helpful; it looks like company may be
> the missing ingredient.

No, it wasn't, but indeed, there was a missing ingredient.  I had
forgotten to set tab-always-indent to 'complete.

With this recipe, I can reproduce the bug:

   $ emacs -Q -f package-initialize -L ~/path/to/eglot/eglot -l eglot  \
     ~/path/to/a/python/file.py                                        \
     --eval '(setq tab-always-indent (quote complete))' -f eglot

Don't know what's up, though.  Going to have a better look.

João





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Sun, 23 May 2021 21:40:02 GMT) Full text and rfc822 format available.

Message #17 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: Doug Davis <ddavis <at> ddavis.io>, pankaj <at> codeisgreat.org
Cc: 48609 <at> debbugs.gnu.org
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Sun, 23 May 2021 22:38:52 +0100
João Távora <joaotavora <at> gmail.com> writes:

> Doug Davis <ddavis <at> ddavis.io> writes:
>
>> Hi João & Pankaj,
>>
>> João Távora <joaotavora <at> gmail.com> writes:
>>
>>> Pankaj Jangid <pankaj <at> codeisgreat.org> writes:
>>>
>>>> If ‘eglot’ is running and ‘tab-always-indent’ is set to ’complete. Then
>>>> in python-mode, TAB doesn’t cycle point column positions. For example,
>>>> in the following code if you are at end of line 2 and then you press RET
>>>> then TAB doesn’t move the point to left margin. Without ‘eglot’ this
>>>> works fine.
>>>>
>>>> #+begin_src python
>>>> def greet(s):
>>>>     print(f"Hello {s}!")
>>>> #+end_src
>>>
>>> Hello Pankaj,
>>>
>>> I cannot reproduce this.  Here's what I ran:
>>>
>>>   $ emacs --version | head -1
>>>   GNU Emacs 26.3
>>>   $ emacs -Q -f package-initialize -L ~/path/to/eglot/eglot -l eglot \
>>>     ~/path/to/a/python/file.py -f eglot
>>
>> Just driving by, hopefully this is helpful; it looks like company may be
>> the missing ingredient.
>
> No, it wasn't, but indeed, there was a missing ingredient.  I had
> forgotten to set tab-always-indent to 'complete.
>
> With this recipe, I can reproduce the bug:
>
>    $ emacs -Q -f package-initialize -L ~/path/to/eglot/eglot -l eglot  \
>      ~/path/to/a/python/file.py                                        \
>      --eval '(setq tab-always-indent (quote complete))' -f eglot
>
> Don't know what's up, though.  Going to have a better look.

I see what's up.  When Eglot is turned on, having tab-always-indent set
to 'complete means that the first TAB press after pressing RET will
actually try to complete things.

When Eglot is active, the completion system can find a large number of
completions available for that empty line.  Since you have selected
tab-always-indent to be 'complete, Eglot will request and present those
completions in the *Completions* buffer.

The only way to cancel that operation is by C-g or clicking somewhere
else.  This in turn makes it so that the "last" command issued isn't
indent-for-tab-command anymore, and so there aren't two
indent-for-tab-command commands in a row.  And that is the criteria
consulted by python.el's indentation function to decide to cycle the
indentation.

So I'm not sure what needs to be fixed here, if anything, or how you
would like this to behave.

João.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Mon, 24 May 2021 08:19:02 GMT) Full text and rfc822 format available.

Message #20 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: Andrii Kolomoiets <andreyk.mad <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: 48609 <at> debbugs.gnu.org, Doug Davis <ddavis <at> ddavis.io>,
 pankaj <at> codeisgreat.org
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Mon, 24 May 2021 11:17:54 +0300
João Távora <joaotavora <at> gmail.com> writes:

> So I'm not sure what needs to be fixed here, if anything, or how you
> would like this to behave.

IMO works as described in the `tab-always-indent` docstring:

If ‘complete’, TAB first tries to indent the current line, and if the line
was already indented, then try to complete the thing at point.

One can reproduce this without Eglot:

1. emacs -Q
2. C-x C-f test.py
3. M-: (setq tab-always-indent 'complete)
4. C-c C-p

After step 4 the `python-completion-at-point` function starts producing
completions and each TAB key will lead to "No match" message.

Pankaj, take a look at the `tab-first-completion` variable.


--
Andrii




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Tue, 25 May 2021 06:42:01 GMT) Full text and rfc822 format available.

Message #23 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: Pankaj Jangid <pankaj <at> codeisgreat.org>
To: Andrii Kolomoiets <andreyk.mad <at> gmail.com>
Cc: 48609 <at> debbugs.gnu.org, Doug Davis <ddavis <at> ddavis.io>,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Tue, 25 May 2021 12:11:06 +0530
Andrii Kolomoiets <andreyk.mad <at> gmail.com> writes:

> IMO works as described in the `tab-always-indent` docstring:
>
> If ‘complete’, TAB first tries to indent the current line, and if the line
> was already indented, then try to complete the thing at point.

Thanks for sharing this. I think I should have been more specific. The
bug is more related to python-mode then to ‘tab-always-indent’.

In ‘python’ buffers, TABs cycle position of point. But as described in
my original report and reproduced by João, bringing Eglot, inhibits this
behavior. 





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Tue, 25 May 2021 06:48:02 GMT) Full text and rfc822 format available.

Message #26 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: Pankaj Jangid <pankaj <at> codeisgreat.org>
To: João Távora <joaotavora <at> gmail.com>
Cc: 48609 <at> debbugs.gnu.org, Doug Davis <ddavis <at> ddavis.io>
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Tue, 25 May 2021 12:17:06 +0530
João Távora <joaotavora <at> gmail.com> writes:

> When Eglot is active, the completion system can find a large number of
> completions available for that empty line.  Since you have selected
> tab-always-indent to be 'complete, Eglot will request and present those
> completions in the *Completions* buffer.
>
> The only way to cancel that operation is by C-g or clicking somewhere
> else.  This in turn makes it so that the "last" command issued isn't
> indent-for-tab-command anymore, and so there aren't two
> indent-for-tab-command commands in a row.  And that is the criteria
> consulted by python.el's indentation function to decide to cycle the
> indentation.
>
> So I'm not sure what needs to be fixed here, if anything, or how you
> would like this to behave.

I think that the best place should be python.el then. A variable
‘python-completion-on-empty-line’ or some better name. I don’t know if
such a variable already exist or not. Need to check.

Since the point-position is cycled by python.el, that is the place where
it should be configured.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Tue, 25 May 2021 09:34:02 GMT) Full text and rfc822 format available.

Message #29 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: Pankaj Jangid <pankaj <at> codeisgreat.org>
Cc: 48609 <at> debbugs.gnu.org, Doug Davis <ddavis <at> ddavis.io>,
 Andrii Kolomoiets <andreyk.mad <at> gmail.com>
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Tue, 25 May 2021 10:32:52 +0100
Pankaj Jangid <pankaj <at> codeisgreat.org> writes:

> Andrii Kolomoiets <andreyk.mad <at> gmail.com> writes:
>
>> IMO works as described in the `tab-always-indent` docstring:
>>
>> If ‘complete’, TAB first tries to indent the current line, and if the line
>> was already indented, then try to complete the thing at point.
>
> Thanks for sharing this. I think I should have been more specific. The
> bug is more related to python-mode then to ‘tab-always-indent’.
>
> In ‘python’ buffers, TABs cycle position of point. But as described in
> my original report and reproduced by João, bringing Eglot, inhibits this
> behavior.

Yes, but what actually happened is that the one of those tabs was
waiting for completions to come in, so the system was indeed behaving as
intended.  It's just that when you don't have Eglot, you also don't have
completions.

João




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Tue, 25 May 2021 09:37:01 GMT) Full text and rfc822 format available.

Message #32 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: Pankaj Jangid <pankaj <at> codeisgreat.org>
Cc: 48609 <at> debbugs.gnu.org, Doug Davis <ddavis <at> ddavis.io>
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Tue, 25 May 2021 10:36:23 +0100
Pankaj Jangid <pankaj <at> codeisgreat.org> writes:

> João Távora <joaotavora <at> gmail.com> writes:
>
>> When Eglot is active, the completion system can find a large number of
>> completions available for that empty line.  Since you have selected
>> tab-always-indent to be 'complete, Eglot will request and present those
>> completions in the *Completions* buffer.
>>
>> The only way to cancel that operation is by C-g or clicking somewhere
>> else.  This in turn makes it so that the "last" command issued isn't
>> indent-for-tab-command anymore, and so there aren't two
>> indent-for-tab-command commands in a row.  And that is the criteria
>> consulted by python.el's indentation function to decide to cycle the
>> indentation.
>>
>> So I'm not sure what needs to be fixed here, if anything, or how you
>> would like this to behave.
>
> I think that the best place should be python.el then. A variable
> ‘python-completion-on-empty-line’ or some better name. I don’t know if
> such a variable already exist or not. Need to check.

Yes, I agree, python.el.  I wonder if instead of that variale the
cycling logic could be changed to account for this case where there may
be completions at point (Eglot is only one possible provider of such
completions, btw.)

João





Information forwarded to fgallina <at> gnu.org, bug-gnu-emacs <at> gnu.org:
bug#48609; Package emacs. (Tue, 25 May 2021 14:09:01 GMT) Full text and rfc822 format available.

Message #35 received at 48609 <at> debbugs.gnu.org (full text, mbox):

From: Pankaj Jangid <pankaj <at> codeisgreat.org>
To: João Távora <joaotavora <at> gmail.com>
Cc: 48609 <at> debbugs.gnu.org, Doug Davis <ddavis <at> ddavis.io>
Subject: Re: bug#48609: Eglot and tab-always-indent conflict in python-mode
Date: Tue, 25 May 2021 19:38:37 +0530
João Távora <joaotavora <at> gmail.com> writes:

>>> When Eglot is active, the completion system can find a large number of
>>> completions available for that empty line.  Since you have selected
>>> tab-always-indent to be 'complete, Eglot will request and present those
>>> completions in the *Completions* buffer.
>>>
>>> The only way to cancel that operation is by C-g or clicking somewhere
>>> else.  This in turn makes it so that the "last" command issued isn't
>>> indent-for-tab-command anymore, and so there aren't two
>>> indent-for-tab-command commands in a row.  And that is the criteria
>>> consulted by python.el's indentation function to decide to cycle the
>>> indentation.
>>>
>>> So I'm not sure what needs to be fixed here, if anything, or how you
>>> would like this to behave.
>>
>> I think that the best place should be python.el then. A variable
>> ‘python-completion-on-empty-line’ or some better name. I don’t know if
>> such a variable already exist or not. Need to check.
>
> Yes, I agree, python.el.  I wonder if instead of that variale the
> cycling logic could be changed to account for this case where there may
> be completions at point (Eglot is only one possible provider of such
> completions, btw.)

CC’ing Fabián.





This bug report was last modified 4 years and 77 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.