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: make smart indent after comment line consistent
Type: behavior Stage: test needed
Components: IDLE Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: cheryl.sabella, terry.reedy
Priority: normal Keywords: patch

Created on 2018-02-23 03:41 by terry.reedy, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 5755 cheryl.sabella, 2018-02-23 03:43
Messages (2)
msg312613 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-02-23 03:41
https://docs.python.org/3/reference/lexical_analysis.html#blank-lines says "A logical line that contains only spaces, tabs, formfeeds and possibly a comment, is ignored" but notes that REPLs might not ignore them during interactive input.  The same is true of editors as lines are typed.  In particular, even a no-code comment line can suggest where a smart indenter should indent.  In any case, Python does not care what follows '#', and IDLE should not either (except when uncommenting-out lines). 

Suppose one types the following:

if 1:
    if 2:
        print(3)
    #
    #x
    # x

Currently, IDLE indents 4 columns after '#' and '# x' and 8 columns after '#x'. If one moves the comments to the margin, the indents are 0 and 8 columns.  This is because pyparse.Parser._study2 ignores lines that match _junkre and _junkre only  matches comments with '#' followed by a non-space (/B) character.

I think that IDLE should generally assume that the comment starts on a legal column and that the comment will apply to the next line typed, which will have the same indent, and that the lack of space after '#' (there have been many such in idlelib) is preference, indifference, or error.

The only exception relevant to IDLE is '##' inserted at the beginning of code lines  to (temporarily) make them ignored.  If one places the cursor at the end of such a line and hits return to insert new lines, some indent is likely wanted if the line above is indented.  Matching '##.*\n' is easy enough.

Note that smart indent always uses the line above, if there is one, because there typically is not one below, and if there is, either choice is arbitrary and being smarter would cost time.  (This should be in revised doc.)
msg312614 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-02-23 03:54
So I am proposing _junkre = re.compile(r"(?:[ \t]*|##.*)\n").match with test change to match.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77099
2018-02-23 03:54:11terry.reedysetassignee: terry.reedy
messages: + msg312614
components: + IDLE
stage: patch review -> test needed
2018-02-23 03:43:25cheryl.sabellasetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request5602
2018-02-23 03:41:55terry.reedycreate