Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE: add rstrip to Format menu #49400

Closed
rhettinger opened this issue Feb 4, 2009 · 16 comments
Closed

IDLE: add rstrip to Format menu #49400

rhettinger opened this issue Feb 4, 2009 · 16 comments
Labels
topic-IDLE type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

BPO 5150
Nosy @rhettinger, @terryjreedy, @kbkaiser, @taleinat, @ned-deily, @serwy, @merwok, @asvetlov
Files
  • RstripExtension.py: rstrip extension
  • ReindentExtension.py: reindent.py extension
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-06-06.15:14:38.817>
    created_at = <Date 2009-02-04.08:37:42.819>
    labels = ['expert-IDLE', 'type-feature']
    title = 'IDLE: add rstrip to Format menu'
    updated_at = <Date 2020-06-06.15:14:38.816>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2020-06-06.15:14:38.816>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-06-06.15:14:38.817>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2009-02-04.08:37:42.819>
    creator = 'rhettinger'
    dependencies = []
    files = ['14108', '19247']
    hgrepos = []
    issue_num = 5150
    keywords = []
    message_count = 16.0
    messages = ['81131', '81301', '88490', '88492', '88495', '91528', '118808', '118809', '118847', '122083', '216673', '216678', '260256', '267059', '356845', '370827']
    nosy_count = 10.0
    nosy_names = ['rhettinger', 'terry.reedy', 'kbk', 'taleinat', 'gpolo', 'ned.deily', 'roger.serwy', 'eric.araujo', 'asvetlov', 'THRlWiTi']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue5150'
    versions = ['Python 3.5']

    @rhettinger
    Copy link
    Contributor Author

    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.

    @rhettinger rhettinger added topic-IDLE type-feature A feature request or enhancement labels Feb 4, 2009
    @terryjreedy
    Copy link
    Member

    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.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented May 29, 2009

    Here's an extension that adds rstrip() to the Format menu.

    @rhettinger
    Copy link
    Contributor Author

    Applied in r72999. Will backport to 2.7.

    @rhettinger rhettinger assigned rhettinger and unassigned kbkaiser May 29, 2009
    @rhettinger
    Copy link
    Contributor Author

    Backported in r73001

    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Aug 13, 2009

    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 ?

    @merwok
    Copy link
    Member

    merwok commented Oct 15, 2010

    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?

    @rhettinger
    Copy link
    Contributor Author

    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.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Oct 15, 2010

    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.

    @rhettinger
    Copy link
    Contributor Author

    Opened back up for the new patch (posted after the previous close).

    @rhettinger rhettinger reopened this Nov 22, 2010
    @rhettinger rhettinger assigned ned-deily and unassigned rhettinger Nov 29, 2010
    @ned-deily
    Copy link
    Member

    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.

    @ned-deily ned-deily removed their assignment Apr 17, 2014
    @terryjreedy
    Copy link
    Member

    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.

    bpo-18704 was about integrating the PEP-8 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.

    @rhettinger
    Copy link
    Contributor Author

    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.

    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy
    Copy link
    Member

    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 PEP-8 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?

    1. 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.)

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

    3. 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 (bpo-33046).

    @terryjreedy
    Copy link
    Member

    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.)

    @terryjreedy terryjreedy changed the title IDLE to support reindent.py IDLE: add rstrip to Format menu Jun 6, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IDLE type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants