Repository navigation
Modernize Code In IDLELib Editor Backspace #136556
Copy link
Copy link
Open
Labels
Description
(and potentially deprecate handling of tabs in IDLE, though likely separate issue)
In #136061,
Lines 1365 to 1385 in 561212a
| # Ick. It may require *inserting* spaces if we back up over a | |
| # tab character! This is written to be clear, not fast. | |
| tabwidth = self.tabwidth | |
| have = len(chars.expandtabs(tabwidth)) | |
| assert have > 0 | |
| want = ((have - 1) // self.indentwidth) * self.indentwidth | |
| # Debug prompt is multilined.... | |
| ncharsdeleted = 0 | |
| while True: | |
| chars = chars[:-1] | |
| ncharsdeleted = ncharsdeleted + 1 | |
| have = len(chars.expandtabs(tabwidth)) | |
| if have <= want or chars[-1] not in " \t": | |
| break | |
| text.undo_block_start() | |
| text.delete("insert-%dc" % ncharsdeleted, "insert") | |
| if have < want: | |
| text.insert("insert", ' ' * (want - have), | |
| self.user_input_insert_tags) | |
| text.undo_block_stop() | |
| return "break" |
However, the complexity there comes from a loop which handles situations (files with tabs) that either cannot or should not occur; in the current default IDLE, you can't put tabs, and a space after a tab should just be deleted in a file coming from elsewhere as in indicated in #134874 (comment). Therefore, simplifying the function specification and/or deprecating IDLE to handle tabs (which we should do) will allow elimination of this piece of obsolete code, as indicated in #136061 (comment).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
StanFromIreland commentedon Jul 11, 2025
Can this not just go under #136061?
johnzhou721 commentedon Jul 11, 2025
#134874 (comment) by @terryjreedy
I have not analyzed the current vs desired behaviro yet. Maybe someone else can tackle this. Also maybe make it type-refactor not type-feature.
StanFromIreland commentedon Jul 11, 2025
johnzhou721 commentedon Jul 11, 2025
[-]Modernize Code In IDLELib Editor[/-][+]Modernize Code In IDLELib Editor Backspace[/+]StanFromIreland commentedon Jul 11, 2025
johnzhou721 commentedon Jul 11, 2025
picnixz commentedon Jul 11, 2025
Pleae update the title accordingly as I didn't read the resolved conservations before changing the labels (modernizing code means refactoring to me)
[-]Modernize Code In IDLELib Editor Backspace[/-][+]Modernize Code In IDLELib Editor Backspace (and potentially deprecate handling of tabs in IDLE)[/+]terryjreedy commentedon Jul 12, 2025
The
type_xyzlabel does not matter since the PR will be backported regardless.Any deprecation should be a separate issue; it would require discussion involving other coredevs, and I have not yet decided what, if anything, I want to ask for.
I did some of the needed analysis in the second part of the referenced comment and more since while doing some live experiments with IDLE. I concluded that tabs should be treated as normal characters whether used for indenting (where mixing with spaces is now illegal) or otherwise (where spaces also need no special handling). Spaces need only be treated specially in syntactically significant indents, but currently are also in other indents. Consider this:
The smart indent is 5 spaces so that '2', etc, lines up with the '1'. Backspace now removes 1 and then 4 spaces. One might decide that in a style indent, it should always be one, but deciding the indent type could require backing up multiple lines. My initial goal would be to leave the current situation alone. I have not seen any requests for changes.
I will try to submit a PR soon.
serhiy-storchaka commentedon Jul 12, 2025
Can IDLE be used to edit other types of files? For example, in
Makefiletabs are mandatory.[-]Modernize Code In IDLELib Editor Backspace (and potentially deprecate handling of tabs in IDLE)[/-][+]Modernize Code In IDLELib Editor Backspace[/+]