Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(261603)

Side by Side Diff: Lib/rlcompleter.py

Issue 25660: tabs don't work correctly in python repl
Patch Set: Created 3 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Word completion for GNU readline. 1 """Word completion for GNU readline.
2 2
3 The completer completes keywords, built-ins and globals in a selectable 3 The completer completes keywords, built-ins and globals in a selectable
4 namespace (which defaults to __main__); when completing NAME.NAME..., it 4 namespace (which defaults to __main__); when completing NAME.NAME..., it
5 evaluates (!) the expression up to the last dot and completes its attributes. 5 evaluates (!) the expression up to the last dot and completes its attributes.
6 6
7 It's very cool to do "import sys" type "sys.", hit the completion key (twice), 7 It's very cool to do "import sys" type "sys.", hit the completion key (twice),
8 and see the list of names defined by the sys module! 8 and see the list of names defined by the sys module!
9 9
10 Tip: to use the tab key as the completion key, call 10 Tip: to use the tab key as the completion key, call
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 This is called successively with state == 0, 1, 2, ... until it 69 This is called successively with state == 0, 1, 2, ... until it
70 returns None. The completion should begin with 'text'. 70 returns None. The completion should begin with 'text'.
71 71
72 """ 72 """
73 if self.use_main_ns: 73 if self.use_main_ns:
74 self.namespace = __main__.__dict__ 74 self.namespace = __main__.__dict__
75 75
76 if not text.strip(): 76 if not text.strip():
77 if state == 0: 77 if state == 0:
78 return '\t' 78 readline.insert_text('\t')
79 readline.redisplay()
80 return ''
Martin Panter 2015/11/21 00:28:23 Might be better to return None (indicates no more
Yury Selivanov 2015/11/21 00:40:42 We need to return an empty string here, otherwise,
79 else: 81 else:
80 return None 82 return None
81 83
82 if state == 0: 84 if state == 0:
83 if "." in text: 85 if "." in text:
84 self.matches = self.attr_matches(text) 86 self.matches = self.attr_matches(text)
85 else: 87 else:
86 self.matches = self.global_matches(text) 88 self.matches = self.global_matches(text)
87 try: 89 try:
88 return self.matches[state] 90 return self.matches[state]
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 try: 167 try:
166 import readline 168 import readline
167 except ImportError: 169 except ImportError:
168 pass 170 pass
169 else: 171 else:
170 readline.set_completer(Completer().complete) 172 readline.set_completer(Completer().complete)
171 # Release references early at shutdown (the readline module's 173 # Release references early at shutdown (the readline module's
172 # contents are quasi-immortal, and the completer function holds a 174 # contents are quasi-immortal, and the completer function holds a
173 # reference to globals). 175 # reference to globals).
174 atexit.register(lambda: readline.set_completer(None)) 176 atexit.register(lambda: readline.set_completer(None))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+