Show More
@@ -177,6 +177,45 b' def compress_user(path, tilde_expand, tilde_val):' | |||||
177 | return path |
|
177 | return path | |
178 |
|
178 | |||
179 |
|
179 | |||
|
180 | ||||
|
181 | def penalize_magics_key(word): | |||
|
182 | """key for sorting that penalizes magic commands in the ordering | |||
|
183 | ||||
|
184 | Normal words are left alone. | |||
|
185 | ||||
|
186 | Magic commands have the initial % moved to the end, e.g. | |||
|
187 | %matplotlib is transformed as follows: | |||
|
188 | ||||
|
189 | %matplotlib -> matplotlib% | |||
|
190 | ||||
|
191 | [The choice of the final % is arbitrary.] | |||
|
192 | ||||
|
193 | Since "matplotlib" < "matplotlib%" as strings, | |||
|
194 | "timeit" will appear before the magic "%timeit" in the ordering | |||
|
195 | ||||
|
196 | For consistency, move "%%" to the end, so cell magics appear *after* | |||
|
197 | line magics with the same name. | |||
|
198 | ||||
|
199 | A check is performed that there are no other "%" in the string; | |||
|
200 | if there are, then the string is not a magic command and is left unchanged. | |||
|
201 | ||||
|
202 | """ | |||
|
203 | ||||
|
204 | # Move any % signs from start to end of the key | |||
|
205 | # provided there are no others elsewhere in the string | |||
|
206 | ||||
|
207 | if word[:2] == "%%": | |||
|
208 | if not "%" in word[2:]: | |||
|
209 | return word[2:] + "%%" | |||
|
210 | ||||
|
211 | if word[:1] == "%": | |||
|
212 | if not "%" in word[1:]: | |||
|
213 | return word[1:] + "%" | |||
|
214 | ||||
|
215 | return word | |||
|
216 | ||||
|
217 | ||||
|
218 | ||||
180 | class Bunch(object): pass |
|
219 | class Bunch(object): pass | |
181 |
|
220 | |||
182 |
|
221 | |||
@@ -888,7 +927,10 b' class IPCompleter(Completer):' | |||||
888 | # different types of objects. The rlcomplete() method could then |
|
927 | # different types of objects. The rlcomplete() method could then | |
889 | # simply collapse the dict into a list for readline, but we'd have |
|
928 | # simply collapse the dict into a list for readline, but we'd have | |
890 | # richer completion semantics in other evironments. |
|
929 | # richer completion semantics in other evironments. | |
891 | self.matches = sorted(set(self.matches)) |
|
930 | ||
|
931 | # use penalize_magics_key to put magics after variables with same name | |||
|
932 | self.matches = sorted(set(self.matches), key=penalize_magics_key) | |||
|
933 | ||||
892 | #io.rprint('COMP TEXT, MATCHES: %r, %r' % (text, self.matches)) # dbg |
|
934 | #io.rprint('COMP TEXT, MATCHES: %r, %r' % (text, self.matches)) # dbg | |
893 | return text, self.matches |
|
935 | return text, self.matches | |
894 |
|
936 |
General Comments 0
You need to be logged in to leave comments.
Login now