Skip to content

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Sep 22, 2017

In IDLE, the title in an editor or shell window is bookended by asterisks when changes are made to the text, indicating that the file needs to be saved. However, the shell window was adding the asterisks as text was typed, but upon pressing the enter key, the asterisks disappeared. This patch retains the asterisks after enter is pressed.

https://bugs.python.org/issue21937

@terryjreedy
Copy link
Member

In general, patches should have a specification posted on the issue that detail what the patch is intended to do. In this case, how IDLE should behave after the patch.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that EditorWindows and Outwins use .. to indicate 'changed since last save', the derived Shell window must be doing something different to use ... differently. The request on the issue is to remove that difference. So I expect the patch to remove whatever makes Shell act differently, not add more difference on top of the existing difference.

That said, the patch seems to work, but I don't know why. Can you explain a bit?

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I didn't expect the Spanish Inquisition!. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella
Copy link
Contributor Author

I just wrote a really long description and lost it. :-(

@csabella
Copy link
Contributor Author

csabella commented Sep 22, 2017

So, here's the shorter description.

The difference between shell and editor windows is that the shell clears the undo/redo every time enter is pressed. So, you can only undo/redo on the current prompt line and not anything prior to that. In editor, even after Save, you can undo/redo as much as you want (up to the stored limit).

The change I made clarified this difference and didn't add more of a difference.

In undo.py, text.insert and text.delete (both input and output) write to a buffer list to record the changes made. Undo/Redo know what to do because they traverse the items on this list. The way it tracks where it is in the list is with self.pointer. Another variable in undo.py is self.saved which is set to the value of self.pointer after a filesave. Function get_saved() returns self.saved == self.pointer. For the title in the editor window, the asterisks are added when get_saved() is False. So, the only time the asterisks show up is when self.saved doesn't equal self.pointer.

Going back to the difference between shell and editor, that functionality is added in showprompt() in shell.py. showprompt() calls reset_undo() (which is in undo.py). reset_undo() clears the undo/redo buffer and sets self.pointer to 0. It also calls set_saved() (also in undo.py), which takes a parameter called flag. If flag is True, then self.saved is set to self.pointer. If flag is False, then self.saved is set to -1 (essentially meaning unsaved).

My patch simply sends a flag from showprompt() to reset_undo() to prevent it from setting self.saved to be the same as self.pointer. Before the patch, the call was hard-coded to 1 (True), so that self.saved and self.pointer were always the same. I send a False so that self.saved gets set to -1. This causes get_saved() to be False and the asterisks to display.

Note: reset_undo() is only called from shell and showprompt is only in shell. Also, I made the new flag a keyword argument that defaults to True, so the default behavior is to do exactly what it did before.

Sorry if this reads like this.

@terryjreedy
Copy link
Member

I will probably have to read that a couple of times while looking at the code, but I think it will be enough. The short story is that the handling of undo in Shell is so different that the dirty marking cannot operate the same.

Aside: I wonder if clearing undo in the Shell could be delayed until the statement is submitted.

Copy link
Contributor

@taleinat taleinat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into the code, I think the approach here is overly complex. Why not do what IOBinding.loadfile() does, i.e. just call set_saved(False) after calling reset_undo()?

I also think that the lengthy doc-strings added aren't a good idea. They describe in great detail how the methods work, which should be irrelevant to the callers of those methods, and is prone to get out of sync with their code.

If you're willing to rework this a bit, I'd be happy to review again so we can get this merged.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested much shorter docstring additions. I have not yet re-reviewed in light of Tal's implementation suggestion.

status for the window based on the parameter. If set_saved_flag
is True, then the window will look like it's been saved. If
it's false, it will not be flagged as saved.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe replacing the 4 lines with "If set_saved_flag, clear the unsaved markers on the title bar." gives the essential additional information needed.

self.interp.restart_subprocess(with_cwd=True)

def showprompt(self):
"""Display the prompt in the shell window.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Display the prompt in the shell window.
"Display the prompt."

and delete rest. I will soon propose changing handing of prompt.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 23, 2022
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jul 29, 2022
@github-actions
Copy link

github-actions bot commented Sep 1, 2022

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Sep 1, 2022
@hauntsaninja hauntsaninja changed the title bpo-21937: IDLE: Fix use of unsaved indicator in titlebar of shell window gh-66136: IDLE: Fix use of unsaved indicator in titlebar of shell window Jan 7, 2023
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jan 8, 2023
@github-actions
Copy link

github-actions bot commented Feb 7, 2023

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 7, 2023
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Sep 8, 2025
Copy link

github-actions bot commented Oct 8, 2025

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes stale Stale PR or inactive for long period of time. topic-IDLE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants