GNU bug report logs - #32876
26.1; python-mode mixes existing tabs with new spaces

Previous Next

Package: emacs;

Reported by: starback <at> stp.lingfil.uu.se (Per Starbäck)

Date: Sat, 29 Sep 2018 16:14:01 UTC

Severity: normal

Tags: confirmed, wontfix

Found in version 26.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32876 in the body.
You can then email your comments to 32876 AT debbugs.gnu.org in the normal way.

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

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


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#32876; Package emacs. (Sat, 29 Sep 2018 16:14:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to starback <at> stp.lingfil.uu.se (Per Starbäck):
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 29 Sep 2018 16:14:02 GMT) Full text and rfc822 format available.

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

From: starback <at> stp.lingfil.uu.se (Per Starbäck)
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; python-mode mixes existing tabs with new spaces
Date: Sat, 29 Sep 2018 18:13:30 +0200
In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.26)

### Problem ###

I did "emacs -Q pytab.py" where pytab.py contains the two lines:

------------------------------
def foo():
	print('hello')
------------------------------

The second line begins with a TAB.

Then I add a line to this marvellous program with

	M-> TAB print('world') C-x C-s

This new line will have eight spaces in the beginning, and because of
that this is no longer a valid Python3 program!

### Background ###

Earlier you could mix spaces and tabs (seen as 8 spaces) in Python, but
Python3 disallows mixing them.

Spaces are preferred, and the style guide "PEP 8" says that

  Tabs should be used solely to remain consistent with code that is
  already indented with tabs.

So python-mode ought to help you remain consistent with such old
code. I think that checking with what characters the current block is
indented all the time would be overdoing it for something that shouldn't
occur that often, but that it should suffice to just scan through the
visited file to see if it contains any tabs in that case instead turn on
indent-tabs-mode instead of turning it off.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32876; Package emacs. (Sat, 29 Sep 2018 20:07:02 GMT) Full text and rfc822 format available.

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

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32876: 26.1; python-mode mixes existing tabs with new spaces
Date: Sat, 29 Sep 2018 22:11:12 +0200
On 29.09.2018 18:13, Per Starbäck wrote:
> In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.26)
> 
> ### Problem ###
> 
> I did "emacs -Q pytab.py" where pytab.py contains the two lines:
> 
> ------------------------------
> def foo():
> 	print('hello')
> ------------------------------
> 
> The second line begins with a TAB.
> 
> Then I add a line to this marvellous program with
> 
> 	M-> TAB print('world') C-x C-s
> 
> This new line will have eight spaces in the beginning, and because of
> that this is no longer a valid Python3 program!
> 
> ### Background ###
> 
> Earlier you could mix spaces and tabs (seen as 8 spaces) in Python, but
> Python3 disallows mixing them.
> 
> Spaces are preferred, and the style guide "PEP 8" says that
> 
>    Tabs should be used solely to remain consistent with code that is
>    already indented with tabs.
> 
> So python-mode ought to help you remain consistent with such old
> code. I think that checking with what characters the current block is
> indented all the time would be overdoing it for something that shouldn't
> occur that often, but that it should suffice to just scan through the
> visited file to see if it contains any tabs in that case instead turn on
> indent-tabs-mode instead of turning it off.
> 
> 
> 

May confirm that with

GNU Emacs 27.0.50 (build 1, i686-pc-linux-gnu, GTK+ Version 3.14.5) of 
2018-09-19

python.el hard-codes

(set (make-local-variable 'indent-tabs-mode) nil)

which should be customizable.





Added tag(s) confirmed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 25 Oct 2018 00:52:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32876; Package emacs. (Wed, 23 Jun 2021 14:39:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: starback <at> stp.lingfil.uu.se (Per Starbäck)
Cc: 32876 <at> debbugs.gnu.org
Subject: Re: bug#32876: 26.1; python-mode mixes existing tabs with new spaces
Date: Wed, 23 Jun 2021 16:38:45 +0200
starback <at> stp.lingfil.uu.se (Per Starbäck) writes:

> I did "emacs -Q pytab.py" where pytab.py contains the two lines:
>
> ------------------------------
> def foo():
> 	print('hello')
> ------------------------------
>
> The second line begins with a TAB.
>
> Then I add a line to this marvellous program with
>
> 	M-> TAB print('world') C-x C-s
>
> This new line will have eight spaces in the beginning, and because of
> that this is no longer a valid Python3 program!
>
> ### Background ###
>
> Earlier you could mix spaces and tabs (seen as 8 spaces) in Python, but
> Python3 disallows mixing them.

Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:

> python.el hard-codes
>
> (set (make-local-variable 'indent-tabs-mode) nil)
>
> which should be customizable.

Well, I don't know -- the problem is that mixing them leads to invalid
programs, so specifying a single tab mode here makes sense, since it
will presumably lead to fewer problems in the long run.

That is, python-mode doesn't really support .py files with tabs in
them -- as a design decision.  So I think this works as designed.

Anybody else have an opinion here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32876; Package emacs. (Sat, 07 May 2022 12:01:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: starback <at> stp.lingfil.uu.se (Per Starbäck)
Cc: 32876 <at> debbugs.gnu.org
Subject: Re: bug#32876: 26.1; python-mode mixes existing tabs with new spaces
Date: Sat, 07 May 2022 14:00:07 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Well, I don't know -- the problem is that mixing them leads to invalid
> programs, so specifying a single tab mode here makes sense, since it
> will presumably lead to fewer problems in the long run.
>
> That is, python-mode doesn't really support .py files with tabs in
> them -- as a design decision.  So I think this works as designed.
>
> Anybody else have an opinion here?

Nobody had in half a year, so I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 07 May 2022 12:01:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 32876 <at> debbugs.gnu.org and starback <at> stp.lingfil.uu.se (Per Starbäck) Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 07 May 2022 12:01:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 05 Jun 2022 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 324 days ago.

Previous Next


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