@@ -830,6 +830,9 @@ def p_key(self, key):
830830 elif key == '\t ' :
831831 return self .tab ()
832832
833+ elif key == 'KEY_BTAB' :
834+ return self .tab (back = True )
835+
833836 elif len (key ) == 1 and not unicodedata .category (key ) == 'Cc' :
834837 self .addstr (key )
835838 self .print_line (self .s )
@@ -1135,13 +1138,15 @@ def size(self):
11351138 self .h = h - 1
11361139 self .x = 0
11371140
1138- def tab (self ):
1141+ def tab (self , back = False ):
11391142 """Process the tab key being hit. If there's only whitespace
11401143 in the line or the line is blank then process a normal tab,
11411144 otherwise attempt to autocomplete to the best match of possible
1142- choices in the match list."""
1145+ choices in the match list.
1146+ If `back` is True, walk backwards through the list of suggestions
1147+ and don't indent if there are only whitespace in the line."""
11431148
1144- if self .atbol ():
1149+ if self .atbol () and not back :
11451150 x_pos = len (self .s ) - self .cpos
11461151 num_spaces = x_pos % OPTS .tab_length
11471152 if not num_spaces :
@@ -1177,7 +1182,10 @@ def tab(self):
11771182 if not expanded and self .matches :
11781183 if self .matches_iter :
11791184 self .s = self .s [:- len (self .matches_iter .current ())] + cw
1180- current_match = self .matches_iter .next ()
1185+ if back :
1186+ current_match = self .matches_iter .previous ()
1187+ else :
1188+ current_match = self .matches_iter .next ()
11811189 if current_match :
11821190 try :
11831191 self .show_list (self .matches , self .argspec , current_match )
0 commit comments