Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 Lib/idlelib/config-main.def
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ font-size= 10
font-bold= 0
encoding= none
line-numbers-default= 0
strip-trailing-whitespace-on-save= 1

Copy link
Copy Markdown
Member

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


[PyShell]
auto-squeeze-min-lines= 50
Expand Down
22 changes: 22 additions & 0 deletions 22 Lib/idlelib/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,9 @@ def create_page_general(self):
frame_context: Frame
context_title: Label
(*)context_int: Entry - context_lines
frame_strip_trailing_space_save: Frame
strip_trailing_space_save_title: Label
(*)strip_trailing_space_save_bool: Checkbutton - strip_trailing_space_save
frame_shell: LabelFrame
frame_auto_squeeze_min_lines: Frame
auto_squeeze_min_lines_title: Label
Expand Down Expand Up @@ -1891,6 +1894,9 @@ def create_page_general(self):
('main', 'EditorWindow', 'line-numbers-default'))
self.context_lines = tracers.add(
StringVar(self), ('extensions', 'CodeContext', 'maxlines'))
self.strip_trailing_space_save = tracers.add(
BooleanVar(self),
('main', 'EditorWindow', 'strip-trailing-whitespace-on-save'))

# Create widgets:
# Section frames.
Expand Down Expand Up @@ -1987,6 +1993,14 @@ def create_page_general(self):
validatecommand=self.digits_only, validate='key',
)

frame_strip_trailing_space_save = Frame(frame_editor, borderwidth=0)
strip_trailing_space_save_title = Label(
frame_strip_trailing_space_save,
text='Strip Trailing Whitespace on Save')
self.strip_trailing_space_save_bool = Checkbutton(
frame_strip_trailing_space_save,
variable=self.strip_trailing_space_save, width=1)

# Frame_shell.
frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0)
auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines,
Expand Down Expand Up @@ -2069,6 +2083,11 @@ def create_page_general(self):
frame_context.pack(side=TOP, padx=5, pady=0, fill=X)
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
self.context_int.pack(side=TOP, padx=5, pady=5)
# frame_strip_trailing_space_save.
frame_strip_trailing_space_save.pack(side=TOP, padx=5, pady=0, fill=X)
strip_trailing_space_save_title.pack(
side=LEFT, anchor=W,padx=5, pady=5)
self.strip_trailing_space_save_bool.pack(side=LEFT, padx=5, pady=5)

# frame_auto_squeeze_min_lines
frame_auto_squeeze_min_lines.pack(side=TOP, padx=5, pady=0, fill=X)
Expand Down Expand Up @@ -2113,6 +2132,9 @@ def load_general_cfg(self):
'main', 'EditorWindow', 'line-numbers-default', type='bool'))
self.context_lines.set(idleConf.GetOption(
'extensions', 'CodeContext', 'maxlines', type='int'))
self.strip_trailing_space_save.set(
idleConf.GetOption('main', 'EditorWindow',
'strip-trailing-whitespace-on-save', type='bool'))

# Set variables for shell windows.
self.auto_squeeze_min_lines.set(idleConf.GetOption(
Expand Down
5 changes: 5 additions & 0 deletions 5 Lib/idlelib/idle_test/test_configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,11 @@ def test_cursor_blink(self):
self.page.cursor_blink_bool.invoke()
self.assertEqual(mainpage, {'EditorWindow': {'cursor-blink': 'False'}})

def test_strip_trailing_space_on_save(self):
self.page.strip_trailing_space_save_bool.invoke()
name = 'strip-trailing-whitespace-on-save'
self.assertEqual(mainpage, {'EditorWindow': {name: 'False'}})

def test_autocomplete_wait(self):
self.page.auto_wait_int.delete(0, 'end')
self.page.auto_wait_int.insert(0, '11')
Expand Down
5 changes: 5 additions & 0 deletions 5 Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ def save_a_copy(self, event):
return "break"

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

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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.

text = self.fixnewlines()
chars = self.encode(text)
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add an option to IDLE to automatically strip trailing whitespace when saving
a file. The option is enabled by default.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.