Show More
@@ -170,41 +170,38 b' def compress_user(path, tilde_expand, tilde_val):' | |||
|
170 | 170 | |
|
171 | 171 | |
|
172 | 172 | |
|
173 |
def |
|
|
174 | """key for sorting that penalizes magic commands in the ordering | |
|
173 | def completions_sorting_key(word): | |
|
174 | """key for sorting completions | |
|
175 | 175 | |
|
176 | Normal words are left alone. | |
|
177 | ||
|
178 | Magic commands have the initial % moved to the end, e.g. | |
|
179 | %matplotlib is transformed as follows: | |
|
180 | ||
|
181 | %matplotlib -> matplotlib% | |
|
182 | ||
|
183 | [The choice of the final % is arbitrary.] | |
|
184 | ||
|
185 | Since "matplotlib" < "matplotlib%" as strings, | |
|
186 | "timeit" will appear before the magic "%timeit" in the ordering | |
|
187 | ||
|
188 | For consistency, move "%%" to the end, so cell magics appear *after* | |
|
189 | line magics with the same name. | |
|
190 | ||
|
191 | A check is performed that there are no other "%" in the string; | |
|
192 | if there are, then the string is not a magic command and is left unchanged. | |
|
176 | This does several things: | |
|
193 | 177 | |
|
178 | - Lowercase all completions, so they are sorted alphabetically with | |
|
179 | upper and lower case words mingled | |
|
180 | - Demote any completions starting with underscores to the end | |
|
181 | - Insert any %magic and %%cellmagic completions in the alphabetical order | |
|
182 | by their name | |
|
194 | 183 | """ |
|
184 | # Case insensitive sort | |
|
185 | word = word.lower() | |
|
195 | 186 | |
|
196 | # Move any % signs from start to end of the key | |
|
197 | # provided there are no others elsewhere in the string | |
|
187 | prio1, prio2 = 0, 0 | |
|
198 | 188 | |
|
199 | if word[:2] == "%%": | |
|
200 | if not "%" in word[2:]: | |
|
201 | return word[2:] + "%%" | |
|
189 | if word.startswith('__'): | |
|
190 | prio1 = 2 | |
|
191 | elif word.startswith('_'): | |
|
192 | prio1 = 1 | |
|
202 | 193 | |
|
203 | if word[:1] == "%": | |
|
194 | if word.startswith('%%'): | |
|
195 | # If there's another % in there, this is something else, so leave it alone | |
|
196 | if not "%" in word[2:]: | |
|
197 | word = word[2:] | |
|
198 | prio2 = 2 | |
|
199 | elif word.startswith('%'): | |
|
204 | 200 | if not "%" in word[1:]: |
|
205 |
|
|
|
201 | word = word[1:] | |
|
202 | prio2 = 1 | |
|
206 | 203 | |
|
207 | return word | |
|
204 | return prio1, word, prio2 | |
|
208 | 205 | |
|
209 | 206 | |
|
210 | 207 | @undoc |
@@ -1206,8 +1203,7 b' class IPCompleter(Completer):' | |||
|
1206 | 1203 | # simply collapse the dict into a list for readline, but we'd have |
|
1207 | 1204 | # richer completion semantics in other evironments. |
|
1208 | 1205 | |
|
1209 | # use penalize_magics_key to put magics after variables with same name | |
|
1210 | self.matches = sorted(set(self.matches), key=penalize_magics_key) | |
|
1206 | self.matches = sorted(set(self.matches), key=completions_sorting_key) | |
|
1211 | 1207 | |
|
1212 | 1208 | #io.rprint('COMP TEXT, MATCHES: %r, %r' % (text, self.matches)) # dbg |
|
1213 | 1209 | return text, self.matches |
General Comments 0
You need to be logged in to leave comments.
Login now