@@ -995,6 +995,9 @@ def p_key(self, key):
995995 self .do_exit = True
996996 return None
997997
998+ elif key == '\x18 ' :
999+ return self .send_current_line_to_editor ()
1000+
9981001 elif key [0 :3 ] == 'PAD' and not key in ('PAD0' , 'PADSTOP' ):
9991002 pad_keys = {
10001003 'PADMINUS' : '-' ,
@@ -1108,10 +1111,10 @@ def repl(self):
11081111 self .push ('from bpython._internal import _help as help\n ' , False )
11091112
11101113 self .iy , self .ix = self .scr .getyx ()
1111- more = False
1114+ self . more = False
11121115 while not self .do_exit :
11131116 self .f_string = ''
1114- self .prompt (more )
1117+ self .prompt (self . more )
11151118 try :
11161119 inp = self .get_line ()
11171120 except KeyboardInterrupt :
@@ -1132,8 +1135,8 @@ def repl(self):
11321135 else :
11331136 self .stdout_hist += inp .encode (getpreferredencoding ()) + '\n '
11341137 stdout_position = len (self .stdout_hist )
1135- more = self .push (inp )
1136- if not more :
1138+ self . more = self .push (inp )
1139+ if not self . more :
11371140 self .prev_block_finished = stdout_position
11381141 self .s = ''
11391142 return self .exit_value
@@ -1203,8 +1206,8 @@ def reevaluate(self):
12031206 # I decided it was easier to just do this manually
12041207 # than to make the print_line and history stuff more flexible.
12051208 self .scr .addstr ('\n ' )
1206- more = self .push (line )
1207- self .prompt (more )
1209+ self . more = self .push (line )
1210+ self .prompt (self . more )
12081211 self .iy , self .ix = self .scr .getyx ()
12091212
12101213 self .cpos = 0
@@ -1505,6 +1508,46 @@ def yank_from_buffer(self):
15051508 self .addstr (self .cut_buffer )
15061509 self .print_line (self .s , clr = True )
15071510
1511+ def send_current_line_to_editor (self ):
1512+ lines = repl .send_to_external_editor (self .s ).split ('\n ' )
1513+ self .s = ''
1514+ self .print_line (self .s )
1515+ while lines and not lines [- 1 ]:
1516+ lines .pop ()
1517+ if not lines :
1518+ return ''
1519+
1520+ self .f_string = ''
1521+ self .cpos = - 1 # Set cursor position to -1 to prevent paren matching
1522+
1523+ self .iy , self .ix = self .scr .getyx ()
1524+ self .evaluating = True
1525+ for line in lines :
1526+ if py3 :
1527+ self .stdout_hist += line + '\n '
1528+ else :
1529+ self .stdout_hist += line .encode (getpreferredencoding ()) + '\n '
1530+ self .history .append (line )
1531+ self .print_line (line )
1532+ self .s_hist [- 1 ] += self .f_string
1533+ self .scr .addstr ('\n ' )
1534+ self .more = self .push (line )
1535+ self .prompt (self .more )
1536+ self .iy , self .ix = self .scr .getyx ()
1537+ self .evaluating = False
1538+
1539+ self .cpos = 0
1540+ indent = repl .next_indentation (self .s , self .config .tab_length )
1541+ self .s = ''
1542+ self .scr .refresh ()
1543+
1544+ if self .buffer :
1545+ for _ in xrange (indent ):
1546+ self .tab ()
1547+
1548+ self .print_line (self .s )
1549+ self .scr .redrawwin ()
1550+ return ''
15081551
15091552class Statusbar (object ):
15101553 """This class provides the status bar at the bottom of the screen.
0 commit comments