MCPcopy Index your code
hub / github.com/bpython/bpython / tab

Method tab

bpython/urwid.py:1061–1109  ·  view source on GitHub ↗

Process the tab key being hit. If the line is blank or has only whitespace: indent. If there is text before the cursor: cycle completions. If `back` is True cycle backwards through completions, and return instead of indenting. Returns True if the key was h

(self, back=False)

Source from the content-addressed store, hash-verified

1059 # self.echo(repr(event))
1060
1061 def tab(self, back=False):
1062 """Process the tab key being hit.
1063
1064 If the line is blank or has only whitespace: indent.
1065
1066 If there is text before the cursor: cycle completions.
1067
1068 If `back` is True cycle backwards through completions, and return
1069 instead of indenting.
1070
1071 Returns True if the key was handled.
1072 """
1073 self._completion_update_suppressed = True
1074 try:
1075 # Heavily inspired by cli's tab.
1076 text = self.edit.get_edit_text()
1077 if not text.lstrip() and not back:
1078 x_pos = len(text) - self.cpos
1079 num_spaces = x_pos % self.config.tab_length
1080 if not num_spaces:
1081 num_spaces = self.config.tab_length
1082
1083 self.edit.insert_text(" " * num_spaces)
1084 return True
1085
1086 if not self.matches_iter:
1087 self.complete(tab=True)
1088 cw = self.current_string() or self.cw()
1089 if not cw:
1090 return True
1091
1092 if self.matches_iter.is_cseq():
1093 cursor, text = self.matches_iter.substitute_cseq()
1094 self.edit.set_edit_text(text)
1095 self.edit.edit_pos = cursor
1096 elif self.matches_iter.matches:
1097 if back:
1098 self.matches_iter.previous()
1099 else:
1100 next(self.matches_iter)
1101 cursor, text = self.matches_iter.cur_line()
1102 self.edit.set_edit_text(text)
1103 self.edit.edit_pos = cursor
1104 self.overlay.tooltip_focus = True
1105 if self.tooltip.grid:
1106 self.tooltip.grid.set_focus(self.matches_iter.index)
1107 return True
1108 finally:
1109 self._completion_update_suppressed = False
1110
1111
1112def main(args=None, locals_=None, banner=None):

Callers 2

reevaluateMethod · 0.95
handle_inputMethod · 0.95

Calls 7

cwMethod · 0.95
current_stringMethod · 0.80
is_cseqMethod · 0.80
substitute_cseqMethod · 0.80
previousMethod · 0.80
cur_lineMethod · 0.80
completeMethod · 0.45

Tested by

no test coverage detected