Show More
@@ -476,6 +476,64 b' def _safe_isinstance(obj, module, class_name):' | |||
|
476 | 476 | |
|
477 | 477 | |
|
478 | 478 | |
|
479 | def back_unicode_name_matches(text): | |
|
480 | u"""Match unicode characters back to unicode name | |
|
481 | ||
|
482 | This does ☃ -> \\snowman | |
|
483 | ||
|
484 | Note that snowman is not a valid python3 combining character but will be expanded. | |
|
485 | Though it will not recombine back to the snowman character by the completion machinery. | |
|
486 | ||
|
487 | This will not either back-complete standard sequences like \n, \b ... | |
|
488 | ||
|
489 | Used on Python 3 only. | |
|
490 | """ | |
|
491 | if len(text)<2: | |
|
492 | return u'', () | |
|
493 | maybe_slash = text[-2] | |
|
494 | if maybe_slash != '\\': | |
|
495 | return u'', () | |
|
496 | ||
|
497 | char = text[-1] | |
|
498 | # no expand on quote for completion in strings. | |
|
499 | # nor backcomplete standard ascii keys | |
|
500 | if char in string.ascii_letters or char in ['"',"'"]: | |
|
501 | return u'', () | |
|
502 | try : | |
|
503 | unic = unicodedata.name(char) | |
|
504 | return '\\'+char,['\\'+unic] | |
|
505 | except KeyError as e: | |
|
506 | pass | |
|
507 | return u'', () | |
|
508 | ||
|
509 | def back_latex_name_matches(text): | |
|
510 | u"""Match latex characters back to unicode name | |
|
511 | ||
|
512 | This does ->\\sqrt | |
|
513 | ||
|
514 | Used on Python 3 only. | |
|
515 | """ | |
|
516 | if len(text)<2: | |
|
517 | return u'', () | |
|
518 | maybe_slash = text[-2] | |
|
519 | if maybe_slash != '\\': | |
|
520 | return u'', () | |
|
521 | ||
|
522 | ||
|
523 | char = text[-1] | |
|
524 | # no expand on quote for completion in strings. | |
|
525 | # nor backcomplete standard ascii keys | |
|
526 | if char in string.ascii_letters or char in ['"',"'"]: | |
|
527 | return u'', () | |
|
528 | try : | |
|
529 | latex = reverse_latex_symbol[char] | |
|
530 | # '\\' replace the \ as well | |
|
531 | return '\\'+char,[latex] | |
|
532 | except KeyError as e: | |
|
533 | pass | |
|
534 | return u'', () | |
|
535 | ||
|
536 | ||
|
479 | 537 | class IPCompleter(Completer): |
|
480 | 538 | """Extension of the completer class with IPython-specific features""" |
|
481 | 539 | |
@@ -980,62 +1038,6 b' class IPCompleter(Completer):' | |||
|
980 | 1038 | pass |
|
981 | 1039 | return u'', [] |
|
982 | 1040 | |
|
983 | def back_unicode_name_matches(self, text): | |
|
984 | u"""Match unicode characters back to unicode name | |
|
985 | ||
|
986 | This does ☃ -> \\snowman | |
|
987 | ||
|
988 | Note that snowman is not a valid python3 combining character but will be expanded. | |
|
989 | Though it will not recombine back to the snowman character by the completion machinery. | |
|
990 | ||
|
991 | This will not either back-complete standard sequences like \n, \b ... | |
|
992 | ||
|
993 | Used on Python 3 only. | |
|
994 | """ | |
|
995 | if len(text)<2: | |
|
996 | return u'', () | |
|
997 | maybe_slash = text[-2] | |
|
998 | if maybe_slash != '\\': | |
|
999 | return u'', () | |
|
1000 | ||
|
1001 | char = text[-1] | |
|
1002 | # no expand on quote for completion in strings. | |
|
1003 | # nor backcomplete standard ascii keys | |
|
1004 | if char in string.ascii_letters or char in ['"',"'"]: | |
|
1005 | return u'', () | |
|
1006 | try : | |
|
1007 | unic = unicodedata.name(char) | |
|
1008 | return '\\'+char,['\\'+unic] | |
|
1009 | except KeyError as e: | |
|
1010 | pass | |
|
1011 | return u'', () | |
|
1012 | ||
|
1013 | def back_latex_name_matches(self, text): | |
|
1014 | u"""Match latex characters back to unicode name | |
|
1015 | ||
|
1016 | This does ->\\sqrt | |
|
1017 | ||
|
1018 | Used on Python 3 only. | |
|
1019 | """ | |
|
1020 | if len(text)<2: | |
|
1021 | return u'', () | |
|
1022 | maybe_slash = text[-2] | |
|
1023 | if maybe_slash != '\\': | |
|
1024 | return u'', () | |
|
1025 | ||
|
1026 | ||
|
1027 | char = text[-1] | |
|
1028 | # no expand on quote for completion in strings. | |
|
1029 | # nor backcomplete standard ascii keys | |
|
1030 | if char in string.ascii_letters or char in ['"',"'"]: | |
|
1031 | return u'', () | |
|
1032 | try : | |
|
1033 | latex = reverse_latex_symbol[char] | |
|
1034 | # '\\' replace the \ as well | |
|
1035 | return '\\'+char,[latex] | |
|
1036 | except KeyError as e: | |
|
1037 | pass | |
|
1038 | return u'', () | |
|
1039 | 1041 | |
|
1040 | 1042 | |
|
1041 | 1043 | |
@@ -1148,13 +1150,10 b' class IPCompleter(Completer):' | |||
|
1148 | 1150 | return latex_text, latex_matches |
|
1149 | 1151 | name_text = '' |
|
1150 | 1152 | name_matches = [] |
|
1151 |
for meth in (self.unicode_name_matches, |
|
|
1152 |
|
|
|
1153 |
if |
|
|
1154 |
name_text |
|
|
1155 | name_matches.extend(_name_matches) | |
|
1156 | if name_text: | |
|
1157 | return name_text, name_matches | |
|
1153 | for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches): | |
|
1154 | name_text, name_matches = meth(base_text) | |
|
1155 | if name_text: | |
|
1156 | return name_text, name_matches | |
|
1158 | 1157 | |
|
1159 | 1158 | # if text is either None or an empty string, rely on the line buffer |
|
1160 | 1159 | if not text: |
@@ -148,6 +148,45 b' def test_latex_completions():' | |||
|
148 | 148 | nt.assert_in('\\aleph', matches) |
|
149 | 149 | |
|
150 | 150 | |
|
151 | ||
|
152 | ||
|
153 | @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3') | |
|
154 | def test_back_latex_completion(): | |
|
155 | ip = get_ipython() | |
|
156 | ||
|
157 | # do not return more than 1 matches fro \beta, only the latex one. | |
|
158 | name, matches = ip.complete('\\β') | |
|
159 | nt.assert_equal(len(matches), 1) | |
|
160 | nt.assert_equal(matches[0], '\\beta') | |
|
161 | ||
|
162 | @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3') | |
|
163 | def test_back_unicode_completion(): | |
|
164 | ip = get_ipython() | |
|
165 | ||
|
166 | name, matches = ip.complete('\\Ⅴ') | |
|
167 | nt.assert_equal(len(matches), 1) | |
|
168 | nt.assert_equal(matches[0], '\\ROMAN NUMERAL FIVE') | |
|
169 | ||
|
170 | ||
|
171 | @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3') | |
|
172 | def test_forward_unicode_completion(): | |
|
173 | ip = get_ipython() | |
|
174 | ||
|
175 | name, matches = ip.complete('\\ROMAN NUMERAL FIVE') | |
|
176 | nt.assert_equal(len(matches), 1) | |
|
177 | nt.assert_equal(matches[0], 'Ⅴ') | |
|
178 | ||
|
179 | @dec.onlyif(sys.version_info[0] >= 3, 'This test only apply on python3') | |
|
180 | def test_no_ascii_back_completion(): | |
|
181 | ip = get_ipython() | |
|
182 | # single ascii letter that don't have yet completions | |
|
183 | for letter in 'fjqyJMQVWY' : | |
|
184 | name, matches = ip.complete('\\'+letter) | |
|
185 | nt.assert_equal(len(matches), 0) | |
|
186 | ||
|
187 | ||
|
188 | ||
|
189 | ||
|
151 | 190 | class CompletionSplitterTestCase(unittest.TestCase): |
|
152 | 191 | def setUp(self): |
|
153 | 192 | self.sp = completer.CompletionSplitter() |
General Comments 0
You need to be logged in to leave comments.
Login now