##// END OF EJS Templates
Allow showing dict keys only
Steven Silvester -
Show More
@@ -350,7 +350,7 b' class Completion:'
350 Completion object used and return by IPython completers.
350 Completion object used and return by IPython completers.
351
351
352 .. warning:: Unstable
352 .. warning:: Unstable
353
353
354 This function is unstable, API may change without warning.
354 This function is unstable, API may change without warning.
355 It will also raise unless use in proper context manager.
355 It will also raise unless use in proper context manager.
356
356
@@ -591,7 +591,7 b' class Completer(Configurable):'
591 'information for experimental jedi integration.')\
591 'information for experimental jedi integration.')\
592 .tag(config=True)
592 .tag(config=True)
593
593
594 backslash_combining_completions = Bool(True,
594 backslash_combining_completions = Bool(True,
595 help="Enable unicode completions, e.g. \\alpha<tab> . "
595 help="Enable unicode completions, e.g. \\alpha<tab> . "
596 "Includes completion of latex commands, unicode names, and expanding "
596 "Includes completion of latex commands, unicode names, and expanding "
597 "unicode characters back to latex commands.").tag(config=True)
597 "unicode characters back to latex commands.").tag(config=True)
@@ -693,7 +693,7 b' class Completer(Configurable):'
693
693
694 # Another option, seems to work great. Catches things like ''.<tab>
694 # Another option, seems to work great. Catches things like ''.<tab>
695 m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
695 m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
696
696
697 if m:
697 if m:
698 expr, attr = m.group(1, 3)
698 expr, attr = m.group(1, 3)
699 elif self.greedy:
699 elif self.greedy:
@@ -703,7 +703,7 b' class Completer(Configurable):'
703 expr, attr = m2.group(1,2)
703 expr, attr = m2.group(1,2)
704 else:
704 else:
705 return []
705 return []
706
706
707 try:
707 try:
708 obj = eval(expr, self.namespace)
708 obj = eval(expr, self.namespace)
709 except:
709 except:
@@ -738,7 +738,7 b' def get__all__entries(obj):'
738 words = getattr(obj, '__all__')
738 words = getattr(obj, '__all__')
739 except:
739 except:
740 return []
740 return []
741
741
742 return [w for w in words if isinstance(w, str)]
742 return [w for w in words if isinstance(w, str)]
743
743
744
744
@@ -887,14 +887,14 b' def _safe_isinstance(obj, module, class_name):'
887
887
888 def back_unicode_name_matches(text):
888 def back_unicode_name_matches(text):
889 u"""Match unicode characters back to unicode name
889 u"""Match unicode characters back to unicode name
890
890
891 This does ``β˜ƒ`` -> ``\\snowman``
891 This does ``β˜ƒ`` -> ``\\snowman``
892
892
893 Note that snowman is not a valid python3 combining character but will be expanded.
893 Note that snowman is not a valid python3 combining character but will be expanded.
894 Though it will not recombine back to the snowman character by the completion machinery.
894 Though it will not recombine back to the snowman character by the completion machinery.
895
895
896 This will not either back-complete standard sequences like \\n, \\b ...
896 This will not either back-complete standard sequences like \\n, \\b ...
897
897
898 Used on Python 3 only.
898 Used on Python 3 only.
899 """
899 """
900 if len(text)<2:
900 if len(text)<2:
@@ -917,7 +917,7 b' def back_unicode_name_matches(text):'
917
917
918 def back_latex_name_matches(text:str):
918 def back_latex_name_matches(text:str):
919 """Match latex characters back to unicode name
919 """Match latex characters back to unicode name
920
920
921 This does ``\\β„΅`` -> ``\\aleph``
921 This does ``\\β„΅`` -> ``\\aleph``
922
922
923 Used on Python 3 only.
923 Used on Python 3 only.
@@ -991,7 +991,7 b' def _make_signature(completion)-> str:'
991
991
992 class IPCompleter(Completer):
992 class IPCompleter(Completer):
993 """Extension of the completer class with IPython-specific features"""
993 """Extension of the completer class with IPython-specific features"""
994
994
995 @observe('greedy')
995 @observe('greedy')
996 def _greedy_changed(self, change):
996 def _greedy_changed(self, change):
997 """update the splitter and readline delims when greedy is changed"""
997 """update the splitter and readline delims when greedy is changed"""
@@ -999,36 +999,39 b' class IPCompleter(Completer):'
999 self.splitter.delims = GREEDY_DELIMS
999 self.splitter.delims = GREEDY_DELIMS
1000 else:
1000 else:
1001 self.splitter.delims = DELIMS
1001 self.splitter.delims = DELIMS
1002
1002
1003 dict_keys_only = Bool(False,
1004 help="""Whether to show dict key matches only""")
1005
1003 merge_completions = Bool(True,
1006 merge_completions = Bool(True,
1004 help="""Whether to merge completion results into a single list
1007 help="""Whether to merge completion results into a single list
1005
1008
1006 If False, only the completion results from the first non-empty
1009 If False, only the completion results from the first non-empty
1007 completer will be returned.
1010 completer will be returned.
1008 """
1011 """
1009 ).tag(config=True)
1012 ).tag(config=True)
1010 omit__names = Enum((0,1,2), default_value=2,
1013 omit__names = Enum((0,1,2), default_value=2,
1011 help="""Instruct the completer to omit private method names
1014 help="""Instruct the completer to omit private method names
1012
1015
1013 Specifically, when completing on ``object.<tab>``.
1016 Specifically, when completing on ``object.<tab>``.
1014
1017
1015 When 2 [default]: all names that start with '_' will be excluded.
1018 When 2 [default]: all names that start with '_' will be excluded.
1016
1019
1017 When 1: all 'magic' names (``__foo__``) will be excluded.
1020 When 1: all 'magic' names (``__foo__``) will be excluded.
1018
1021
1019 When 0: nothing will be excluded.
1022 When 0: nothing will be excluded.
1020 """
1023 """
1021 ).tag(config=True)
1024 ).tag(config=True)
1022 limit_to__all__ = Bool(False,
1025 limit_to__all__ = Bool(False,
1023 help="""
1026 help="""
1024 DEPRECATED as of version 5.0.
1027 DEPRECATED as of version 5.0.
1025
1028
1026 Instruct the completer to use __all__ for the completion
1029 Instruct the completer to use __all__ for the completion
1027
1030
1028 Specifically, when completing on ``object.<tab>``.
1031 Specifically, when completing on ``object.<tab>``.
1029
1032
1030 When True: only those names in obj.__all__ will be included.
1033 When True: only those names in obj.__all__ will be included.
1031
1034
1032 When False [default]: the __all__ attribute is ignored
1035 When False [default]: the __all__ attribute is ignored
1033 """,
1036 """,
1034 ).tag(config=True)
1037 ).tag(config=True)
@@ -1061,7 +1064,7 b' class IPCompleter(Completer):'
1061 secondary optional dict for completions, to
1064 secondary optional dict for completions, to
1062 handle cases (such as IPython embedded inside functions) where
1065 handle cases (such as IPython embedded inside functions) where
1063 both Python scopes are visible.
1066 both Python scopes are visible.
1064
1067
1065 use_readline : bool, optional
1068 use_readline : bool, optional
1066 DEPRECATED, ignored since IPython 6.0, will have no effects
1069 DEPRECATED, ignored since IPython 6.0, will have no effects
1067 """
1070 """
@@ -1113,6 +1116,9 b' class IPCompleter(Completer):'
1113 @property
1116 @property
1114 def matchers(self):
1117 def matchers(self):
1115 """All active matcher routines for completion"""
1118 """All active matcher routines for completion"""
1119 if self.dict_keys_only:
1120 return [self.dict_key_matches]
1121
1116 if self.use_jedi:
1122 if self.use_jedi:
1117 return [
1123 return [
1118 self.file_matches,
1124 self.file_matches,
@@ -1621,7 +1627,7 b' class IPCompleter(Completer):'
1621 closing_quote, token_offset, matches = match_dict_keys(keys, prefix, self.splitter.delims)
1627 closing_quote, token_offset, matches = match_dict_keys(keys, prefix, self.splitter.delims)
1622 if not matches:
1628 if not matches:
1623 return matches
1629 return matches
1624
1630
1625 # get the cursor position of
1631 # get the cursor position of
1626 # - the text being completed
1632 # - the text being completed
1627 # - the start of the key text
1633 # - the start of the key text
@@ -1632,13 +1638,13 b' class IPCompleter(Completer):'
1632 completion_start = key_start + token_offset
1638 completion_start = key_start + token_offset
1633 else:
1639 else:
1634 key_start = completion_start = match.end()
1640 key_start = completion_start = match.end()
1635
1641
1636 # grab the leading prefix, to make sure all completions start with `text`
1642 # grab the leading prefix, to make sure all completions start with `text`
1637 if text_start > key_start:
1643 if text_start > key_start:
1638 leading = ''
1644 leading = ''
1639 else:
1645 else:
1640 leading = text[text_start:completion_start]
1646 leading = text[text_start:completion_start]
1641
1647
1642 # the index of the `[` character
1648 # the index of the `[` character
1643 bracket_idx = match.end(1)
1649 bracket_idx = match.end(1)
1644
1650
@@ -1657,18 +1663,18 b' class IPCompleter(Completer):'
1657 # brackets were opened inside text, maybe close them
1663 # brackets were opened inside text, maybe close them
1658 if not continuation.startswith(']'):
1664 if not continuation.startswith(']'):
1659 suf += ']'
1665 suf += ']'
1660
1666
1661 return [leading + k + suf for k in matches]
1667 return [leading + k + suf for k in matches]
1662
1668
1663 def unicode_name_matches(self, text):
1669 def unicode_name_matches(self, text):
1664 u"""Match Latex-like syntax for unicode characters base
1670 u"""Match Latex-like syntax for unicode characters base
1665 on the name of the character.
1671 on the name of the character.
1666
1672
1667 This does ``\\GREEK SMALL LETTER ETA`` -> ``Ξ·``
1673 This does ``\\GREEK SMALL LETTER ETA`` -> ``Ξ·``
1668
1674
1669 Works only on valid python 3 identifier, or on combining characters that
1675 Works only on valid python 3 identifier, or on combining characters that
1670 will combine to form a valid identifier.
1676 will combine to form a valid identifier.
1671
1677
1672 Used on Python 3 only.
1678 Used on Python 3 only.
1673 """
1679 """
1674 slashpos = text.rfind('\\')
1680 slashpos = text.rfind('\\')
@@ -1686,7 +1692,7 b' class IPCompleter(Completer):'
1686
1692
1687 def latex_matches(self, text):
1693 def latex_matches(self, text):
1688 u"""Match Latex syntax for unicode characters.
1694 u"""Match Latex syntax for unicode characters.
1689
1695
1690 This does both ``\\alp`` -> ``\\alpha`` and ``\\alpha`` -> ``Ξ±``
1696 This does both ``\\alp`` -> ``\\alpha`` and ``\\alpha`` -> ``Ξ±``
1691
1697
1692 Used on Python 3 only.
1698 Used on Python 3 only.
@@ -1758,13 +1764,13 b' class IPCompleter(Completer):'
1758 Returns an iterator over the possible completions
1764 Returns an iterator over the possible completions
1759
1765
1760 .. warning:: Unstable
1766 .. warning:: Unstable
1761
1767
1762 This function is unstable, API may change without warning.
1768 This function is unstable, API may change without warning.
1763 It will also raise unless use in proper context manager.
1769 It will also raise unless use in proper context manager.
1764
1770
1765 Parameters
1771 Parameters
1766 ----------
1772 ----------
1767
1773
1768 text:str
1774 text:str
1769 Full text of the current input, multi line string.
1775 Full text of the current input, multi line string.
1770 offset:int
1776 offset:int
@@ -1793,7 +1799,7 b' class IPCompleter(Completer):'
1793 and usual IPython completion.
1799 and usual IPython completion.
1794
1800
1795 .. note::
1801 .. note::
1796
1802
1797 Completions are not completely deduplicated yet. If identical
1803 Completions are not completely deduplicated yet. If identical
1798 completions are coming from different sources this function does not
1804 completions are coming from different sources this function does not
1799 ensure that each completion object will only be present once.
1805 ensure that each completion object will only be present once.
@@ -1988,7 +1994,7 b' class IPCompleter(Completer):'
1988 if name_text:
1994 if name_text:
1989 return name_text, name_matches[:MATCHES_LIMIT], \
1995 return name_text, name_matches[:MATCHES_LIMIT], \
1990 [meth.__qualname__]*min(len(name_matches), MATCHES_LIMIT), ()
1996 [meth.__qualname__]*min(len(name_matches), MATCHES_LIMIT), ()
1991
1997
1992
1998
1993 # If no line buffer is given, assume the input text is all there was
1999 # If no line buffer is given, assume the input text is all there was
1994 if line_buffer is None:
2000 if line_buffer is None:
General Comments 0
You need to be logged in to leave comments. Login now