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
5 changes: 5 additions & 0 deletions 5 Lib/idlelib/config-keys.def
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ goto-line=<Alt-Key-g> <Meta-Key-g> <Alt-Key-G> <Meta-Key-G>
smart-backspace=<Key-BackSpace>
newline-and-indent=<Key-Return> <Key-KP_Enter>
smart-indent=<Key-Tab>
smart-dedent=<Shift-Key-Tab>
indent-region=<Control-Key-bracketright>
dedent-region=<Control-Key-bracketleft>
comment-region=<Alt-Key-3> <Meta-Key-3>
Expand Down Expand Up @@ -107,6 +108,7 @@ goto-line=<Alt-Key-g> <Meta-Key-g>
smart-backspace=<Key-BackSpace>
newline-and-indent=<Key-Return> <Key-KP_Enter>
smart-indent=<Key-Tab>
smart-dedent=<Shift-ISO_Left_Tab>

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.

@StanFromIreland
I found ISO keysyms on https://www.tcl-lang.org/man/tcl8.6/TkCmd/keysyms.htm.
Unknown to me and likely new in 8.6. Are these a linux (unix) thing? Would 'tab' really not work?
In any case, 'Key' for the event should still be needed before the keysym.

Suggested change
smart-dedent=<Shift-ISO_Left_Tab>
smart-dedent=<Shift-Key-ISO_Left_Tab>

Repeat twice below.

@StanFromIreland StanFromIreland Oct 12, 2025

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.

They are not a tk thing, but an X11 thing.

I tested, and just smart-dedent=<Shift-Key-Tab> does not work.

On my system it is actually not necessary to have Key- (but it is best to have it anyway IMO). Secondly, ISO_Left_Tab implies Shift, although IIRC this is not always the case and causes problems with some apps.

indent-region=<Control-Key-bracketright>
dedent-region=<Control-Key-bracketleft>
comment-region=<Alt-Key-3>
Expand Down Expand Up @@ -167,6 +169,7 @@ goto-line = <Control-Key-g>
smart-backspace = <Key-BackSpace>
newline-and-indent = <Key-Return> <Key-KP_Enter>
smart-indent = <Key-Tab>
smart-dedent = <Shift-ISO_Left_Tab>
indent-region = <Control-Key-bracketright>
dedent-region = <Control-Key-bracketleft>
comment-region = <Control-Key-d>
Expand Down Expand Up @@ -227,6 +230,7 @@ goto-line=<Command-Key-j>
smart-backspace=<Key-BackSpace>
newline-and-indent=<Key-Return> <Key-KP_Enter>
smart-indent=<Key-Tab>
smart-dedent=<Shift-Key-Tab>
indent-region=<Command-Key-bracketright>
dedent-region=<Command-Key-bracketleft>
comment-region=<Control-Key-3>
Expand Down Expand Up @@ -275,6 +279,7 @@ smart-backspace = <Key-BackSpace>
change-indentwidth = <Control-Key-u>
do-nothing = <Control-Key-F12>
smart-indent = <Key-Tab>
smart-dedent = <Shift-Key-Tab>
center-insert = <Control-Key-l>
history-next = <Control-Key-n>
del-word-right = <Option-Key-Delete>
Expand Down
1 change: 1 addition & 0 deletions 1 Lib/idlelib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ def GetCoreKeys(self, keySetName=None):
'<<smart-backspace>>': ['<Key-BackSpace>'],
'<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'],
'<<smart-indent>>': ['<Key-Tab>'],
'<<smart-dedent>>': ['<Shift-ISO_Left_Tab>', '<Shift-Key-Tab>'],
'<<indent-region>>': ['<Control-Key-bracketright>'],
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
'<<comment-region>>': ['<Alt-Key-3>'],
Expand Down
24 changes: 23 additions & 1 deletion 24 Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
text.bind("<<smart-backspace>>",self.smart_backspace_event)
text.bind("<<newline-and-indent>>",self.newline_and_indent_event)
text.bind("<<smart-indent>>",self.smart_indent_event)
text.bind("<<smart-dedent>>", self.smart_dedent_event)
self.fregion = fregion = self.FormatRegion(self)
# self.fregion used in smart_indent_event to access indent_region.
# self.fregion used in smart-x-events to access region.
text.bind("<<indent-region>>", fregion.indent_region_event)
text.bind("<<dedent-region>>", fregion.dedent_region_event)
text.bind("<<comment-region>>", fregion.comment_region_event)
Expand Down Expand Up @@ -1386,6 +1387,27 @@ def smart_indent_event(self, event):
finally:
text.undo_block_stop()

def smart_dedent_event(self, event):
# if selection:
# do dedent-region
# elif only whitespace to the left:
# dedent one level
first, last = self.get_selection_indices()
self.text.undo_block_start()
try:
if first and last:
if index2line(first) != index2line(last):
return self.dedent_region_event(event)
prefix = self.text.get('insert linestart', 'insert')
raw, effective = get_line_indent(prefix, self.tabwidth)
if raw == len(prefix):
# Only whitespace to the left
self.reindent_to(effective - self.indentwidth)
self.text.see('insert')
return 'break'
finally:
self.text.undo_block_stop()

def newline_and_indent_event(self, event):
"""Insert a newline and indentation after Enter keypress event.

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.