Show More
@@ -136,6 +136,7 b' from traitlets.config.configurable import Configurable' | |||||
136 | from IPython.core.error import TryNext |
|
136 | from IPython.core.error import TryNext | |
137 | from IPython.core.inputsplitter import ESC_MAGIC |
|
137 | from IPython.core.inputsplitter import ESC_MAGIC | |
138 | from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol |
|
138 | from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol | |
|
139 | from IPython.core.oinspect import InspectColors | |||
139 | from IPython.utils import generics |
|
140 | from IPython.utils import generics | |
140 | from IPython.utils.dir2 import dir2, get_real_method |
|
141 | from IPython.utils.dir2 import dir2, get_real_method | |
141 | from IPython.utils.process import arg_split |
|
142 | from IPython.utils.process import arg_split | |
@@ -1049,11 +1050,14 b' class IPCompleter(Completer):' | |||||
1049 | self.matchers = [ |
|
1050 | self.matchers = [ | |
1050 | self.python_matches, |
|
1051 | self.python_matches, | |
1051 | self.file_matches, |
|
1052 | self.file_matches, | |
1052 | self.magic_config_matches, |
|
|||
1053 | self.magic_matches, |
|
1053 | self.magic_matches, | |
1054 | self.python_func_kw_matches, |
|
1054 | self.python_func_kw_matches, | |
1055 | self.dict_key_matches, |
|
1055 | self.dict_key_matches, | |
1056 | ] |
|
1056 | ] | |
|
1057 | self.magic_arg_matchers = [ | |||
|
1058 | self.magic_config_matches, | |||
|
1059 | self.magic_color_matches, | |||
|
1060 | ] | |||
1057 |
|
1061 | |||
1058 | # This is set externally by InteractiveShell |
|
1062 | # This is set externally by InteractiveShell | |
1059 | self.custom_completers = None |
|
1063 | self.custom_completers = None | |
@@ -1181,13 +1185,11 b' class IPCompleter(Completer):' | |||||
1181 |
|
1185 | |||
1182 | return comp |
|
1186 | return comp | |
1183 |
|
1187 | |||
1184 |
def magic_config_matches(self, |
|
1188 | def magic_config_matches(self, line_buffer): | |
1185 | """ Match class names and attributes for %config magic """ |
|
1189 | """ Match class names and attributes for %config magic """ | |
1186 | # use line buffer instead of text (which is a word) |
|
1190 | texts = line_buffer.strip().split() | |
1187 | texts = self.line_buffer.strip().split() |
|
|||
1188 |
|
1191 | |||
1189 | if len(texts) > 0 and \ |
|
1192 | if len(texts) > 0 and (texts[0] == 'config' or texts[0] == '%config'): | |
1190 | ('config'.startswith(texts[0]) or '%config'.startswith(texts[0])): |
|
|||
1191 | # get all configuration classes |
|
1193 | # get all configuration classes | |
1192 | classes = sorted(set([ c for c in self.shell.configurables |
|
1194 | classes = sorted(set([ c for c in self.shell.configurables | |
1193 | if c.__class__.class_traits(config=True) |
|
1195 | if c.__class__.class_traits(config=True) | |
@@ -1218,6 +1220,16 b' class IPCompleter(Completer):' | |||||
1218 | if attr.startswith(texts[1]) ] |
|
1220 | if attr.startswith(texts[1]) ] | |
1219 | return [] |
|
1221 | return [] | |
1220 |
|
1222 | |||
|
1223 | def magic_color_matches(self, line_buffer): | |||
|
1224 | """ Match color schemes for %colors magic""" | |||
|
1225 | texts = line_buffer.strip().split() | |||
|
1226 | ||||
|
1227 | if len(texts) > 0 and (texts[0] == 'colors' or texts[0] == '%colors'): | |||
|
1228 | prefix = texts[1] if len(texts) > 1 else '' | |||
|
1229 | return [ color for color in InspectColors.keys() | |||
|
1230 | if color.startswith(prefix) ] | |||
|
1231 | return [] | |||
|
1232 | ||||
1221 | def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str): |
|
1233 | def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str): | |
1222 | """ |
|
1234 | """ | |
1223 |
|
1235 | |||
@@ -1878,6 +1890,14 b' class IPCompleter(Completer):' | |||||
1878 | self.line_buffer = line_buffer |
|
1890 | self.line_buffer = line_buffer | |
1879 | self.text_until_cursor = self.line_buffer[:cursor_pos] |
|
1891 | self.text_until_cursor = self.line_buffer[:cursor_pos] | |
1880 |
|
1892 | |||
|
1893 | # Do magic arg matches | |||
|
1894 | for matcher in self.magic_arg_matchers: | |||
|
1895 | matches = [(m, matcher.__qualname__) for m in matcher(line_buffer)] | |||
|
1896 | if matches: | |||
|
1897 | matches2 = [m[0] for m in matches] | |||
|
1898 | origins = [m[1] for m in matches] | |||
|
1899 | return text, matches2, origins, {} | |||
|
1900 | ||||
1881 | # Start with a clean slate of completions |
|
1901 | # Start with a clean slate of completions | |
1882 | matches = [] |
|
1902 | matches = [] | |
1883 | custom_res = self.dispatch_custom_completer(text) |
|
1903 | custom_res = self.dispatch_custom_completer(text) |
@@ -578,21 +578,22 b' def test_magic_completion_shadowing():' | |||||
578 | nt.assert_equal(matches, ["%matplotlib"]) |
|
578 | nt.assert_equal(matches, ["%matplotlib"]) | |
579 |
|
579 | |||
580 |
|
580 | |||
581 |
|
||||
582 | def test_magic_config(): |
|
581 | def test_magic_config(): | |
583 | ip = get_ipython() |
|
582 | ip = get_ipython() | |
584 | c = ip.Completer |
|
583 | c = ip.Completer | |
585 |
|
584 | |||
586 | s, matches = c.complete(None, 'conf') |
|
585 | s, matches = c.complete(None, 'conf') | |
587 | nt.assert_in('%config', matches) |
|
586 | nt.assert_in('%config', matches) | |
|
587 | s, matches = c.complete(None, 'conf') | |||
|
588 | nt.assert_not_in('AliasManager', matches) | |||
588 | s, matches = c.complete(None, 'config ') |
|
589 | s, matches = c.complete(None, 'config ') | |
589 | nt.assert_in('AliasManager', matches) |
|
590 | nt.assert_in('AliasManager', matches) | |
590 | s, matches = c.complete(None, '%config ') |
|
591 | s, matches = c.complete(None, '%config ') | |
591 | nt.assert_in('AliasManager', matches) |
|
592 | nt.assert_in('AliasManager', matches) | |
592 | s, matches = c.complete(None, 'config Ali') |
|
593 | s, matches = c.complete(None, 'config Ali') | |
593 |
nt.assert_ |
|
594 | nt.assert_list_equal(['AliasManager'], matches) | |
594 | s, matches = c.complete(None, '%config Ali') |
|
595 | s, matches = c.complete(None, '%config Ali') | |
595 |
nt.assert_ |
|
596 | nt.assert_list_equal(['AliasManager'], matches) | |
596 | s, matches = c.complete(None, 'config AliasManager') |
|
597 | s, matches = c.complete(None, 'config AliasManager') | |
597 | nt.assert_list_equal(['AliasManager'], matches) |
|
598 | nt.assert_list_equal(['AliasManager'], matches) | |
598 | s, matches = c.complete(None, '%config AliasManager') |
|
599 | s, matches = c.complete(None, '%config AliasManager') | |
@@ -602,9 +603,27 b' def test_magic_config():' | |||||
602 | s, matches = c.complete(None, '%config AliasManager.') |
|
603 | s, matches = c.complete(None, '%config AliasManager.') | |
603 | nt.assert_in('AliasManager.default_aliases', matches) |
|
604 | nt.assert_in('AliasManager.default_aliases', matches) | |
604 | s, matches = c.complete(None, 'config AliasManager.de') |
|
605 | s, matches = c.complete(None, 'config AliasManager.de') | |
605 |
nt.assert_ |
|
606 | nt.assert_list_equal(['AliasManager.default_aliases'], matches) | |
606 | s, matches = c.complete(None, 'config AliasManager.de') |
|
607 | s, matches = c.complete(None, 'config AliasManager.de') | |
607 |
nt.assert_ |
|
608 | nt.assert_list_equal(['AliasManager.default_aliases'], matches) | |
|
609 | ||||
|
610 | ||||
|
611 | def test_magic_color(): | |||
|
612 | ip = get_ipython() | |||
|
613 | c = ip.Completer | |||
|
614 | ||||
|
615 | s, matches = c.complete(None, 'colo') | |||
|
616 | nt.assert_in('%colors', matches) | |||
|
617 | s, matches = c.complete(None, 'colo') | |||
|
618 | nt.assert_not_in('NoColor', matches) | |||
|
619 | s, matches = c.complete(None, 'colors ') | |||
|
620 | nt.assert_in('NoColor', matches) | |||
|
621 | s, matches = c.complete(None, '%colors ') | |||
|
622 | nt.assert_in('NoColor', matches) | |||
|
623 | s, matches = c.complete(None, 'colors NoCo') | |||
|
624 | nt.assert_list_equal(['NoColor'], matches) | |||
|
625 | s, matches = c.complete(None, '%colors NoCo') | |||
|
626 | nt.assert_list_equal(['NoColor'], matches) | |||
608 |
|
627 | |||
609 |
|
628 | |||
610 | def test_match_dict_keys(): |
|
629 | def test_match_dict_keys(): |
General Comments 0
You need to be logged in to leave comments.
Login now