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

bpo-33046: An IDLE option to strip trailing whitespace on save #17201

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Nov 17, 2019

@ZackerySpytz
Copy link
Contributor Author

ZackerySpytz commented Nov 17, 2019

There are calls to undo_block_start() and undo_block_stop() in do_rstrip(), which means that saving a file with the option enabled will add an undo command. I don't think this is preferable. I guess a new var could be added to the Rstrip class in order to prevent the undo_block_*() calls in this case.

@terryjreedy
Copy link
Member

terryjreedy commented Nov 17, 2019

I am thinking about the undo issue to make sure I agree.

@taleinat
Copy link
Contributor

taleinat commented Nov 17, 2019

Having an item in the undo history is needed, otherwise undoing changes before the whitespace stripping could potentially be broken. I don't really see a way to avoid it.

Copy link
Contributor

@taleinat taleinat left a comment

LGTM

Copy link
Member

@terryjreedy terryjreedy left a comment

Some of the changes you can do now, some need more input from me.

@@ -67,6 +67,7 @@ font-size= 10
font-bold= 0
encoding= none
line-numbers-default= 0
strip-trailing-whitespace-on-save= 1
Copy link
Member

@terryjreedy terryjreedy Nov 18, 2019

Choose a reason for hiding this comment

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

rstrip-on-save might be sufficient.

Except for line-numbers, the other existing items are actually for the base class used for editor, shell, and output windows. This has to be for editor windows only, at least at present. PyShell subclasses code.Interactive Interpreter, which already does some stripping before compiling. And user code output should not be touched. This different between items should somehow be more obvious on the configdialog tab. I am thinking about what to do.

If someone want to disable this, doing so for particular windows makes more sense than globally. Could we get away with having only a window option, or are there really people who would never want

@@ -371,6 +371,11 @@ def save_a_copy(self, event):
return "break"

def writefile(self, filename):
strip = idleConf.GetOption(
Copy link
Member

@terryjreedy terryjreedy Nov 18, 2019

Choose a reason for hiding this comment

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

If rstrip_save is a per-window property, this will not work.

'main', 'EditorWindow',
'strip-trailing-whitespace-on-save', type='bool')
if strip:
self.editwin.Rstrip(self.editwin).do_rstrip()
Copy link
Member

@terryjreedy terryjreedy Nov 18, 2019

Choose a reason for hiding this comment

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

There is already a per-window event handler which I believe could be reused.

@bedevere-bot
Copy link

bedevere-bot commented Nov 18, 2019

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 have made the requested changes; please review again. 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.

@terryjreedy
Copy link
Member

terryjreedy commented Nov 18, 2019

On undo, I will go with what Tal says until an actual problem becomes evident.

@csabella
Copy link
Contributor

csabella commented Jan 19, 2020

@ZackerySpytz, please address the code review. Thanks!

@taleinat
Copy link
Contributor

taleinat commented Sep 19, 2020

Ping, @ZackerySpytz?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants