Skip to content

Commit 473e7e6

Browse files
fix bpython#266, multiline syntax highlighting bug
1 parent e4db2b3 commit 473e7e6

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,6 @@ def push(self, line, insert_into_history=True):
477477
478478
If the interpreter successfully runs the code, clear the buffer
479479
"""
480-
if insert_into_history:
481-
self.insert_into_history(line)
482-
self.buffer.append(line)
483-
484480
if self.paste_mode:
485481
self.saved_indent = 0
486482
else:
@@ -493,15 +489,23 @@ def push(self, line, insert_into_history=True):
493489
indent = max(0, indent - self.config.tab_length)
494490
self.saved_indent = indent
495491

496-
logging.debug('running %r in interpreter', self.buffer)
497-
code_to_run = '\n'.join(self.buffer)
498-
499492
#current line not added to display buffer if quitting #TODO I don't understand this comment
500493
if self.config.syntax:
501-
self.display_buffer.append(bpythonparse(format(self.tokenize(line), self.formatter)))
494+
display_line = bpythonparse(format(self.tokenize(line), self.formatter))
495+
# careful: self.tokenize requires that the line not be in self.buffer yet!
496+
497+
logging.debug('display line being pushed to buffer: %r -> %r', line, display_line)
498+
self.display_buffer.append(display_line)
502499
else:
503500
self.display_buffer.append(fmtstr(line))
504501

502+
if insert_into_history:
503+
self.insert_into_history(line)
504+
self.buffer.append(line)
505+
506+
code_to_run = '\n'.join(self.buffer)
507+
508+
logging.debug('running %r in interpreter', self.buffer)
505509
try:
506510
c = bool(code.compile_command('\n'.join(self.buffer)))
507511
self.saved_predicted_parse_error = False
@@ -614,6 +618,7 @@ def current_line_formatted(self):
614618
"""The colored current line (no prompt, not wrapped)"""
615619
if self.config.syntax:
616620
fs = bpythonparse(format(self.tokenize(self._current_line), self.formatter))
621+
logging.debug('Display line %r -> %r', self._current_line, fs)
617622
else:
618623
fs = fmtstr(self._current_line)
619624
if hasattr(self, 'old_fs') and str(fs) != str(self.old_fs):

0 commit comments

Comments
 (0)