This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE: add rstrip to Format menu
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: THRlWiTi, asvetlov, eric.araujo, gpolo, kbk, ned.deily, rhettinger, roger.serwy, taleinat, terry.reedy
Priority: normal Keywords:

Created on 2009-02-04 08:37 by rhettinger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
RstripExtension.py roger.serwy, 2009-05-29 00:05 rstrip extension
ReindentExtension.py roger.serwy, 2010-10-15 23:28 reindent.py extension
Messages (16)
msg81131 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-02-04 08:37
Add rstrip() to the Format menu.

Python's svn repository no longer accepts files with trailing whitespace
and it is often necessary to run reindent.py before submitting.  It
would be nice to have this as a built-in formatting tool.
msg81301 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-02-06 21:50
If the interactive interpreter did not require blank lines within blocks
to have at least one 'trailing' space to avoid prematurely ending the
block (as when copy from editor window and paste), IDLE could
automatically rstrip lines.  Given that that should not be done, a menu
item would be nice.
msg88490 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2009-05-29 00:05
Here's an extension that adds rstrip() to the Format menu.
msg88492 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-05-29 01:23
Applied in r72999.  Will backport to 2.7.
msg88495 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-05-29 01:52
Backported in r73001
msg91528 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-08-13 18:07
This has been closed but why not promote reindent.py to a module and add
an option on IDLE to allow a complete reindent.py run ?
msg118808 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-10-15 17:30
reindent.py is very much a script: It lacks a nice, full programmatic API, I mean standalone functions to check a file object or a filename and functions implementing the command-line interface.  As it is now, you see for example print calls in the middle of functions, so it’s not usable as a module.

Maybe bring this to python-dev or -ideas?
msg118809 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-10-15 17:39
There's no need to go to python-dev or python-ideas with this one.  If someone wants to figure-out a way to add reindent functionality to IDLE, patches are welcome.
msg118847 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2010-10-15 23:28
I grabbed the core of reindent.py and put it into an extension, unmodified. 

The original reindent.py will emit Indentation Errors if they exist. 
ScriptBinding already has nice code to handle these problems by highlighting the error, placing the cursor at the error, and presenting a message box. Rather than duplicate this code, this extension makes calls into ScriptBinding to check for syntax errors when the core reindent code throws exceptions.
msg122083 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-11-22 03:27
Opened back up for the new patch (posted after the previous close).
msg216673 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-04-17 08:27
The code needs to be updated for Python 3 and it needs a test.  I'm deassigning it in the hopes that someone will feel free to pick it up.
msg216678 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-04-17 09:33
I use rstrip routinely when editing idlelib files, before committing, so it has been useful for that purpose.

I do not happen to know what reindent.py does that the current format options do not.

#18704 was about integrating the pep8 style checker. That was closed in favor of adding a generic facility to run external analysis tools. There is not an open issue for that yet, but I expect it to happen, perhaps this summer. Reindent.py, if maybe improved, might be a candidate, though I will also try to look at the patch sometime.
msg260256 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-02-13 23:27
One other thought, it would be nice if there were an option (on by default) to automatically strip trailing whitespace when a file is saved.  That would be much nicer than making the user remember to do periodic clean-ups as they edit.
msg267059 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-03 06:41
Having occasionally forgotten, and had to do whitespace commits, I agree.  For Python code, there is never an absolute need for trailing whitespace.  Trailing whitespace in string literals can be done by parse time concatenation.
'''\
line 1
line 2
''' 'line with trailig space    '
Indeed, the trick is needed to mark the trailing space in the code.

I have thought about removing trailing spaces after each return, but pasting may be a problem.
msg356845 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-11-18 06:11
reindent.py does the following:

1. Change Python (.py) files to use 4-space indents and no hard tab characters.  IDLE editor does this by default, as do other programming editors, except as PEP8 recommends something else for continuation lines within fences <(), [], {}>.  Before doing anything with reindent, I would want to check whether it messes with IDLE;s smart indents.

The format module and Format menu has functions to add/remove tabs and changes space indents, as well as rewrap.

The only thing left is dealing with a messed up file, but suspect that this is rarer than 19 (1st public version of reindent.py) or even 10 years ago (this issue).  Is this issue still needed?

2. Trim excess spaces and tabs from ends of lines.  Format => strip whitespace, added on this issue, does this. (The code is now in the format module.)

3. Remove empty lines at the end of files.  Rstrip should do this but does not.  This is a separate issue from reindenting.

4. Ensure that the last line ends with a newline.  Save in iomenu ensures this, but this should be part of 'strip whitespace', especially if we 'rstrip' on save (#33046).
msg370827 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-06-06 15:14
Adding rstrip as it was then was done over a decade ago, and this issue was closed then.  Improvements, as discussed immediately above have been added with other issues, or will be.  I am rejecting the add-on idea of incorporating reindent.py as unneeded.  (It should have been a new issue instead of re-opening this one.)
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49400
2020-06-06 15:14:38terry.reedysetstatus: open -> closed
title: IDLE to support reindent.py -> IDLE: add rstrip to Format menu
messages: + msg370827

resolution: fixed
stage: patch review -> resolved
2019-11-18 06:11:22terry.reedysetnosy: + taleinat
messages: + msg356845
2016-06-03 06:41:54terry.reedysetmessages: + msg267059
2016-02-13 23:27:22rhettingersetmessages: + msg260256
2016-02-13 11:59:30THRlWiTisetnosy: + THRlWiTi
2014-04-17 09:33:32terry.reedysetmessages: + msg216678
2014-04-17 08:27:37ned.deilysetassignee: ned.deily ->
stage: commit review -> patch review
messages: + msg216673
versions: + Python 3.5, - Python 3.2
2012-03-25 21:32:41asvetlovsetnosy: + asvetlov
2010-11-29 01:52:07rhettingersetassignee: rhettinger -> ned.deily

nosy: + ned.deily
2010-11-26 22:48:30terry.reedysetstage: resolved -> commit review
resolution: fixed -> (no value)
versions: + Python 3.2, - Python 3.1, Python 2.7
2010-11-22 03:27:56rhettingersetstatus: closed -> open

messages: + msg122083
2010-10-15 23:28:11roger.serwysetfiles: + ReindentExtension.py

messages: + msg118847
2010-10-15 17:39:55rhettingersetmessages: + msg118809
2010-10-15 17:30:56eric.araujosetmessages: + msg118808
2010-07-10 19:38:36eric.araujosetnosy: + eric.araujo

resolution: accepted -> fixed
stage: needs patch -> resolved
2009-08-13 18:07:28gpolosetmessages: + msg91528
2009-05-29 01:52:33rhettingersetstatus: open -> closed

messages: + msg88495
2009-05-29 01:23:16rhettingersetassignee: kbk -> rhettinger
resolution: accepted
messages: + msg88492
2009-05-29 00:05:15roger.serwysetfiles: + RstripExtension.py
nosy: + roger.serwy
messages: + msg88490

2009-04-26 22:18:25ajaksu2setnosy: + gpolo

stage: needs patch
2009-02-06 21:50:38terry.reedysetnosy: + terry.reedy
messages: + msg81301
2009-02-04 08:37:42rhettingercreate