Skip to content
Closed
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
38 changes: 7 additions & 31 deletions Lib/idlelib/hyperparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,20 @@ def __init__(self, editwin, index):

parser = pyparse.Parser(editwin.indentwidth, editwin.tabwidth)

startatindex = text.index('iomark')

def index2line(index):
return int(float(index))
lno = index2line(text.index(index))

if not editwin.prompt_last_line:
for context in editwin.num_context_lines:
startat = max(lno - context, 1)
startatindex = repr(startat) + ".0"
stopatindex = "%d.end" % lno
# We add the newline because PyParse requires a newline
# at end. We add a space so that index won't be at end
# of line, so that its status will be the same as the
# char before it, if should.
parser.set_code(text.get(startatindex, stopatindex)+' \n')
bod = parser.find_good_parse_start(
editwin._build_char_in_string_func(startatindex))
if bod is not None or startat == 1:
break
parser.set_lo(bod or 0)
else:
r = text.tag_prevrange("console", index)
if r:
startatindex = r[1]
else:
startatindex = "1.0"
stopatindex = "%d.end" % lno
# We add the newline because PyParse requires it. We add a
# space so that index won't be at end of line, so that its
# status will be the same as the char before it, if should.
parser.set_code(text.get(startatindex, stopatindex)+' \n')
parser.set_lo(0)

# We want what the parser has, minus the last newline and space.
self.rawtext = parser.code[:-2]
statement = text.get(startatindex, '%d.end' % lno)
self.rawtext = statement
parser.set_code(statement + '\n')

# Parser.code apparently preserves the statement we are in, so
# that stopatindex can be used to synchronize the string with
# the text box indices.
self.stopatindex = stopatindex
self.stopatindex = '%d.end' % lno
self.bracketing = parser.get_last_stmt_bracketing()
# find which pairs of bracketing are openers. These always
# correspond to a character of rawtext.
Expand Down
5 changes: 4 additions & 1 deletion Lib/idlelib/idle_test/mock_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, master=None, cnf={}, **kw):
There are just a few Text-only options that affect text behavior.
'''
self.data = ['', '\n']
self.marks = {}

def index(self, index):
"Return string version of index decoded according to current text."
Expand Down Expand Up @@ -144,6 +145,8 @@ def _decode(self, index, endflag=0):
return lastline, len(self.data[lastline]) - 1
elif index == 'end':
return self._endex(endflag)
elif '.' not in index:
return self._decode(self.marks[index], endflag)

line, char = index.split('.')
line = int(line)
Expand Down Expand Up @@ -271,7 +274,7 @@ def compare(self, index1, op, index2):

def mark_set(self, name, index):
"Set mark *name* before the character at index."
pass
self.marks[name] = index

def mark_unset(self, *markNames):
"Delete all marks in markNames."
Expand Down
1 change: 1 addition & 0 deletions Lib/idlelib/idle_test/test_calltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class mock_Shell:
"Return mock sufficient to pass to hyperparser."
def __init__(self, text):
text.tag_prevrange = Mock(return_value=None)
text.mark_set('iomark', '1.0')
self.text = text
self.prompt_last_line = ">>> "
self.indentwidth = 4
Expand Down
Loading