How do you prevent removal of auto indents? - SOLVED

Is there a way to prevent PyCharm from removing the auto indents?


Current PyCharm version : 1.1

Build:  #PY-101.8

I like to space out my code with blank lines between sections.  When I hit enter on a blank line in the middle of a construct, it inserts the auto indentation based on my current settings.   Upon typing, it does what I expected.

tabsettings.jpgwhitespace_before_save.jpg

However, once the file is saved, PyCharm seems to remove the auto indents from my code.  (note: it does sometimes seem to leave tabs I've type manually, but not always.  I haven't figured out the pattern)

whitespace_after_save.jpg

This is problematic if I ever do a copy/paste of a code section into Python command line interpreter because it views the blank lines instead of lines with space or tabs in them.  I've tried using tabs and spaces for indents.

How can I prevent PyCharm from removing the auto indents?   Please tell me it's not some burried setting that I'm just missing.



Attachment(s):
tabsettings.jpg
whitespace_before_save.jpg
whitespace_after_save.jpg
7 comments
Comment actions Permalink

Hello Marcel,

You can prevent PyCharm from removing trailing whitespace (which includes

indentation on empty lines) using Settings | Editor | Strip trailing spaces

on Save. However, I don't understand why you would want to do that, because

indents on empty lines are not signficant from the point of view of the Python

language.

Is there a way to prevent PyCharm from removing the auto indents?

Current PyCharm version : 1.1 Build:  #PY-101.8

I like to space out my code with blank lines between sections.  When I

hit enter on a blank line in the middle of a construct, it inserts the

auto indentation based on my current settings.   Upon typing, it does

what I expected.

Image:tabsettings.jpg  Image:whitespace_before_save.jpg

However, once the file is saved, PyCharm seems to remove the auto

indents from my code.  (note: it does sometimes seem to leave tabs

I've type manually, but not always.  I haven't figured out the

pattern)

Image:whitespace_after_save.jpg

This is problematic if I ever do a copy/paste of a code section into

Python command line interpreter because it views the blank lines

instead of lines with space or tabs in them.  I've tried using tabs

and spaces for indents.

How can I prevent PyCharm from removing the auto indents?   Please

tell me it's not some burried setting that I'm just missing.

---

Original message URL:

http://devnet.jetbrains.net/message/5282046#5282046

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0
Comment actions Permalink

I found it.  It did not immediately pop out at me.

http://devnet.jetbrains.net/servlet/JiveServlet/download/2-13448/strip_trailing_space.jpg



Attachment(s):
strip_trailing_space.jpg
0
Comment actions Permalink

It may be a silly thing, but I will sometimes try out snippets of code in the command line interpreter.  A good example would be trying out a function.  When I copy and paste a function with blank lines in the middle, the command line input sees that as the end of the continuation.  However, if there are spaces or tabs on those blank lines, the interpreter treats the line like any other line with actual code on it.

so this:

  1. def function():
  2.     if dostuff:
  3.         print 'something'

  4.     else:
  5.         print 'nothing'

  6.     return 0

doesn't end up pasting as this:

>>> def function():

...     if dostuff:

...         print 'something'

...

>>> else:

>>>         print 'nothing'

0
Comment actions Permalink

Hello Marcel,

This reminds me of a feature that is available for some other languages and

seems to be useful to implement in PyCharm as well:

http://youtrack.jetbrains.net/issue/PY-2633

It may be a silly thing, but I will sometimes try out snippets of code

in the command line interpreter.  A good example would be trying out a

function.  When I copy and paste a function with blank lines in the

middle, the command line input sees that as the end of the

continuation.  However, if there are spaces or tabs on those blank

lines, the interpreter treats the line like any other line with actual

code on it.

so this:

1. def function():

2.     if dostuff:

3.         print 'something'

4.

5.     else:

6.         print 'nothing'

7.

8.     return 0

doesn't end up pasting as this:

>>>> def function():

>>>>

...     if dostuff:

..         print 'something'

..

>>>> else:

>>>> print 'nothing'

---

Original message URL:

http://devnet.jetbrains.net/message/5282074#5282074

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0
Comment actions Permalink

"However, I don't understand why you would want to do that, because

indents on empty lines are not signficant from the point of view of the Python

language."

Well that's clearly not true from the point of view of python interactive sessions :-)

It's reassuring to know I'm not alone with this complaint!

Can we get a fix for this behaviour?

0
Comment actions Permalink

This is very useful for me for one simple reason. Developing as a team, other team developers may or may not use the same IDE. Sometimes I may want to add a print statement to see the output of that code in the console, or add to/modify that code. I then undo and/or save that code and pycharm strips out indentations from empty lines. The version control software picks up these changes (which aren't really changes) and its impossible to revert these in pycharm! The only option is to edit the file in another IDE or text editor or tell the version control software to ignore that file, which isn't great.

0
Comment actions Permalink

It's certainly possible to revert a file which has whitespace-only changes using the Changes view in PyCharm.

0

Please sign in to leave a comment.