diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 50b9d1b0eee..c89241bbaa0 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2962,25 +2962,25 @@ This function takes the list of setup code to send from the | |||
| 2962 | 2962 | ||
| 2963 | (defcustom python-shell-completion-setup-code | 2963 | (defcustom python-shell-completion-setup-code |
| 2964 | "try: | 2964 | "try: |
| 2965 | import __builtin__ | 2965 | import readline |
| 2966 | except ImportError: | ||
| 2967 | # Python 3 | ||
| 2968 | import builtins as __builtin__ | ||
| 2969 | try: | ||
| 2970 | import readline, rlcompleter | ||
| 2971 | except: | 2966 | except: |
| 2972 | def __PYTHON_EL_get_completions(text): | 2967 | def __PYTHON_EL_get_completions(text): |
| 2973 | return [] | 2968 | return [] |
| 2974 | else: | 2969 | else: |
| 2975 | def __PYTHON_EL_get_completions(text): | 2970 | def __PYTHON_EL_get_completions(text): |
| 2971 | try: | ||
| 2972 | import __builtin__ | ||
| 2973 | except ImportError: | ||
| 2974 | # Python 3 | ||
| 2975 | import builtins as __builtin__ | ||
| 2976 | builtins = dir(__builtin__) | 2976 | builtins = dir(__builtin__) |
| 2977 | completions = [] | 2977 | completions = [] |
| 2978 | is_ipython = ('__IPYTHON__' in builtins or | ||
| 2979 | '__IPYTHON__active' in builtins) | ||
| 2980 | splits = text.split() | ||
| 2981 | is_module = splits and splits[0] in ('from', 'import') | ||
| 2978 | try: | 2982 | try: |
| 2979 | splits = text.split() | 2983 | if is_ipython and is_module: |
| 2980 | is_module = splits and splits[0] in ('from', 'import') | ||
| 2981 | is_ipython = ('__IPYTHON__' in builtins or | ||
| 2982 | '__IPYTHON__active' in builtins) | ||
| 2983 | if is_module: | ||
| 2984 | from IPython.core.completerlib import module_completion | 2984 | from IPython.core.completerlib import module_completion |
| 2985 | completions = module_completion(text.strip()) | 2985 | completions = module_completion(text.strip()) |
| 2986 | elif is_ipython and '__IP' in builtins: | 2986 | elif is_ipython and '__IP' in builtins: |
| @@ -2988,13 +2988,20 @@ else: | |||
| 2988 | elif is_ipython and 'get_ipython' in builtins: | 2988 | elif is_ipython and 'get_ipython' in builtins: |
| 2989 | completions = get_ipython().Completer.all_completions(text) | 2989 | completions = get_ipython().Completer.all_completions(text) |
| 2990 | else: | 2990 | else: |
| 2991 | # Try to reuse current completer. | ||
| 2992 | completer = readline.get_completer() | ||
| 2993 | if not completer: | ||
| 2994 | # importing rlcompleter sets the completer, use it as a | ||
| 2995 | # last resort to avoid breaking customizations. | ||
| 2996 | import rlcompleter | ||
| 2997 | completer = readline.get_completer() | ||
| 2991 | i = 0 | 2998 | i = 0 |
| 2992 | while True: | 2999 | while True: |
| 2993 | res = readline.get_completer()(text, i) | 3000 | completion = completer(text, i) |
| 2994 | if not res: | 3001 | if not completion: |
| 2995 | break | 3002 | break |
| 2996 | i += 1 | 3003 | i += 1 |
| 2997 | completions.append(res) | 3004 | completions.append(completion) |
| 2998 | except: | 3005 | except: |
| 2999 | pass | 3006 | pass |
| 3000 | return completions" | 3007 | return completions" |