diff options
| author | Fabián Ezequiel Gallina | 2015-04-06 19:18:46 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2015-04-06 19:18:46 -0300 |
| commit | ab9252a01a61d08cc866dfc73dbed95523523556 (patch) | |
| tree | c5e50df3b9c1762d4700ab782ad19e0bea12c273 | |
| parent | c91fd97dfb54863365e7153d0ccde144c79bb54f (diff) | |
| download | emacs-ab9252a01a61d08cc866dfc73dbed95523523556.tar.gz emacs-ab9252a01a61d08cc866dfc73dbed95523523556.zip | |
python.el: Do not break IPython magic completions.
Fixes: debbugs:19736
* lisp/progmodes/python.el (python-shell-completion-setup-code):
Cleaner setup; import rlcompleter as last resource.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 35 |
2 files changed, 28 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d2f01c34c22..70602581cba 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2015-04-06 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | python.el: Do not break IPython magic completions. (Bug#19736) | ||
| 4 | |||
| 5 | * progmodes/python.el (python-shell-completion-setup-code): | ||
| 6 | Cleaner setup; import rlcompleter as last resource. | ||
| 7 | |||
| 1 | 2015-04-06 Artur Malabarba <bruce.connor.am@gmail.com> | 8 | 2015-04-06 Artur Malabarba <bruce.connor.am@gmail.com> |
| 2 | 9 | ||
| 3 | * emacs-lisp/package.el: Fix lack of "new" packages. | 10 | * emacs-lisp/package.el: Fix lack of "new" packages. |
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" |