unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32876: 26.1; python-mode mixes existing tabs with new spaces
@ 2018-09-29 16:13 Per Starbäck
  2018-09-29 20:11 ` Andreas Röhler
  2021-06-23 14:38 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 4+ messages in thread
From: Per Starbäck @ 2018-09-29 16:13 UTC (permalink / raw)
  To: 32876

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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32876: 26.1; python-mode mixes existing tabs with new spaces
  2018-09-29 16:13 bug#32876: 26.1; python-mode mixes existing tabs with new spaces Per Starbäck
@ 2018-09-29 20:11 ` Andreas Röhler
  2021-06-23 14:38 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Röhler @ 2018-09-29 20:11 UTC (permalink / raw)
  To: 32876

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.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32876: 26.1; python-mode mixes existing tabs with new spaces
  2018-09-29 16:13 bug#32876: 26.1; python-mode mixes existing tabs with new spaces Per Starbäck
  2018-09-29 20:11 ` Andreas Röhler
@ 2021-06-23 14:38 ` Lars Ingebrigtsen
  2022-05-07 12:00   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-23 14:38 UTC (permalink / raw)
  To: Per Starbäck; +Cc: 32876

starback@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@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32876: 26.1; python-mode mixes existing tabs with new spaces
  2021-06-23 14:38 ` Lars Ingebrigtsen
@ 2022-05-07 12:00   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-07 12:00 UTC (permalink / raw)
  To: Per Starbäck; +Cc: 32876

Lars Ingebrigtsen <larsi@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-07 12:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-29 16:13 bug#32876: 26.1; python-mode mixes existing tabs with new spaces Per Starbäck
2018-09-29 20:11 ` Andreas Röhler
2021-06-23 14:38 ` Lars Ingebrigtsen
2022-05-07 12:00   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).