Skip to content
Merged
Changes from 1 commit
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
Next Next commit
gh-104719: IDLE - test editor.IndentSearcher
This class contains all editor references to tokenize module.
  • Loading branch information
terryjreedy committed May 22, 2023
commit 446ddc461f99c9fb6dad986a0288226c1693e01e
18 changes: 10 additions & 8 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ def reindent_to(self, column):
# blocks are found).

def guess_indent(self):
opener, indented = IndentSearcher(self.text, self.tabwidth).run()
opener, indented = IndentSearcher(self.text).run()
if opener and indented:
raw, indentsmall = get_line_indent(opener, self.tabwidth)
raw, indentlarge = get_line_indent(indented, self.tabwidth)
Expand Down Expand Up @@ -1609,13 +1609,9 @@ def get_line_indent(line, tabwidth):


class IndentSearcher:
"Manage initial indent guess, returned by run method."

# .run() chews over the Text widget, looking for a block opener
# and the stmt following it. Returns a pair,
# (line containing block opener, line containing stmt)
# Either or both may be None.

def __init__(self, text, tabwidth):
def __init__(self, text):
self.text = text
self.tabwidth = tabwidth
self.i = self.finished = 0
Expand All @@ -1633,7 +1629,8 @@ def readline(self):
def tokeneater(self, type, token, start, end, line,
INDENT=tokenize.INDENT,
NAME=tokenize.NAME,
OPENERS=('class', 'def', 'for', 'if', 'try', 'while')):
OPENERS=('class', 'def', 'for', 'if', 'match','try',
Comment thread
terryjreedy marked this conversation as resolved.
Outdated
'while', 'with')):
if self.finished:
pass
elif type == NAME and token in OPENERS:
Expand All @@ -1643,6 +1640,10 @@ def tokeneater(self, type, token, start, end, line,
self.finished = 1

def run(self):
"""Return 2 lines containing block opener and and indent.

Either or both may instead be None.
"""
try:
tokens = tokenize.generate_tokens(self.readline)
for token in tokens:
Expand All @@ -1654,6 +1655,7 @@ def run(self):

### end autoindent code ###


def prepstr(s):
"""Extract the underscore from a string.

Expand Down