bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#32876: 26.1; python-mode mixes existing tabs with new spaces


From: Andreas Röhler
Subject: bug#32876: 26.1; python-mode mixes existing tabs with new spaces
Date: Sat, 29 Sep 2018 22:11:12 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

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.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]