From abda2e2350bbc01118256e4c848c0a49bcf38227 2015-04-22 01:05:55 From: Jeff Hussmann Date: 2015-04-22 01:05:55 Subject: [PATCH] makes dictionary key completion use same delimiters as splitter --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index ca71feb..80fa4dd 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -418,7 +418,7 @@ def get__all__entries(obj): return [w for w in words if isinstance(w, string_types)] -def match_dict_keys(keys, prefix): +def match_dict_keys(keys, prefix, delims): """Used by dict_key_matches, matching the prefix to a list of keys""" if not prefix: return None, 0, [repr(k) for k in keys @@ -429,8 +429,9 @@ def match_dict_keys(keys, prefix): prefix_str = eval(prefix + quote, {}) except Exception: return None, 0, [] - - token_match = re.search(r'\w*$', prefix, re.UNICODE) + + pattern = '[^' + ''.join('\\' + c for c in delims) + ']*$' + token_match = re.search(pattern, prefix, re.UNICODE) token_start = token_match.start() token_prefix = token_match.group() @@ -973,7 +974,7 @@ class IPCompleter(Completer): keys = get_keys(obj) if not keys: return keys - closing_quote, token_offset, matches = match_dict_keys(keys, prefix) + closing_quote, token_offset, matches = match_dict_keys(keys, prefix, self.splitter.delims) if not matches: return matches diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index 470da16..b0e5fc0 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -530,6 +530,11 @@ def test_dict_key_completion_string(): _, matches = complete(line_buffer="d[\"a'") nt.assert_in("b", matches) + # need to not split at delims that readline won't split at + if '-' not in ip.Completer.splitter.delims: + ip.user_ns['d'] = {'before-after': None} + _, matches = complete(line_buffer="d['before-af") + nt.assert_in('before-after', matches) def test_dict_key_completion_contexts(): """Test expression contexts in which dict key completion occurs"""