@@ -652,10 +652,10 @@ def displayhook(self, obj):
652652 self .message (repr (obj ))
653653
654654 @contextmanager
655- def _disable_command_completion (self ):
655+ def _enable_multiline_completion (self ):
656656 completenames = self .completenames
657657 try :
658- self .completenames = self .completedefault
658+ self .completenames = self .complete_multiline_names
659659 yield
660660 finally :
661661 self .completenames = completenames
@@ -753,7 +753,7 @@ def default(self, line):
753753 buffer = line
754754 if (code := codeop .compile_command (line + '\n ' , '<stdin>' , 'single' )) is None :
755755 # Multi-line mode
756- with self ._disable_command_completion ():
756+ with self ._enable_multiline_completion ():
757757 buffer = line
758758 continue_prompt = "... "
759759 while (code := codeop .compile_command (buffer , '<stdin>' , 'single' )) is None :
@@ -996,6 +996,21 @@ def _complete_expression(self, text, line, begidx, endidx):
996996 # Complete a simple name.
997997 return [n for n in ns .keys () if n .startswith (text )]
998998
999+ def _complete_indentation (self , text , line , begidx , endidx ):
1000+ try :
1001+ import readline
1002+ except ImportError :
1003+ return []
1004+ # Fill in spaces to form a 4-space indent
1005+ return [' ' * (4 - readline .get_begidx () % 4 )]
1006+
1007+ def complete_multiline_names (self , text , line , begidx , endidx ):
1008+ # If text is space-only, the user entered <tab> before any text.
1009+ # That normally means they want to indent the current line.
1010+ if not text .strip ():
1011+ return self ._complete_indentation (text , line , begidx , endidx )
1012+ return self .completedefault (text , line , begidx , endidx )
1013+
9991014 def completedefault (self , text , line , begidx , endidx ):
10001015 if text .startswith ("$" ):
10011016 # Complete convenience variables
0 commit comments