diff options
| author | Fabián Ezequiel Gallina | 2014-11-26 23:45:24 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-11-26 23:45:24 -0300 |
| commit | 7bf7edf53f65752f408d0f5e9d0af56bfcf683f5 (patch) | |
| tree | 4ed89a4fd78933d181a30d1d97ea0acc308e7790 | |
| parent | 47f573a4bf6b5126884286690ce1e8818ada74ee (diff) | |
| download | emacs-7bf7edf53f65752f408d0f5e9d0af56bfcf683f5.tar.gz emacs-7bf7edf53f65752f408d0f5e9d0af56bfcf683f5.zip | |
* lisp/progmodes/python.el (python-shell-completion-setup-code): Use
__builtin__ module (or builtins in Python 3) and catch all errors
when importing readline and rlcompleter.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 17 |
2 files changed, 17 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5947c76ac17..af75f8db368 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-11-27 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | * progmodes/python.el (python-shell-completion-setup-code): Use | ||
| 4 | __builtin__ module (or builtins in Python 3) and catch all errors | ||
| 5 | when importing readline and rlcompleter. | ||
| 6 | |||
| 1 | 2014-11-26 Stephen Berman <stephen.berman@gmx.net> | 7 | 2014-11-26 Stephen Berman <stephen.berman@gmx.net> |
| 2 | 8 | ||
| 3 | * calendar/todo-mode.el: Handle calling revert-buffer (bug#19187). | 9 | * calendar/todo-mode.el: Handle calling revert-buffer (bug#19187). |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 4c27136f3b5..48d80b99c6a 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2653,25 +2653,30 @@ This function takes the list of setup code to send from the | |||
| 2653 | 2653 | ||
| 2654 | (defcustom python-shell-completion-setup-code | 2654 | (defcustom python-shell-completion-setup-code |
| 2655 | "try: | 2655 | "try: |
| 2656 | import readline, rlcompleter | 2656 | import __builtin__ |
| 2657 | except ImportError: | 2657 | except ImportError: |
| 2658 | # Python 3 | ||
| 2659 | import builtins as __builtin__ | ||
| 2660 | try: | ||
| 2661 | import readline, rlcompleter | ||
| 2662 | except: | ||
| 2658 | def __PYTHON_EL_get_completions(text): | 2663 | def __PYTHON_EL_get_completions(text): |
| 2659 | return [] | 2664 | return [] |
| 2660 | else: | 2665 | else: |
| 2661 | def __PYTHON_EL_get_completions(text): | 2666 | def __PYTHON_EL_get_completions(text): |
| 2667 | builtins = dir(__builtin__) | ||
| 2662 | completions = [] | 2668 | completions = [] |
| 2663 | try: | 2669 | try: |
| 2664 | splits = text.split() | 2670 | splits = text.split() |
| 2665 | is_module = splits and splits[0] in ('from', 'import') | 2671 | is_module = splits and splits[0] in ('from', 'import') |
| 2666 | is_ipython = getattr( | 2672 | is_ipython = ('__IPYTHON__' in builtins or |
| 2667 | __builtins__, '__IPYTHON__', | 2673 | '__IPYTHON__active' in builtins) |
| 2668 | getattr(__builtins__, '__IPYTHON__active', False)) | ||
| 2669 | if is_module: | 2674 | if is_module: |
| 2670 | from IPython.core.completerlib import module_completion | 2675 | from IPython.core.completerlib import module_completion |
| 2671 | completions = module_completion(text.strip()) | 2676 | completions = module_completion(text.strip()) |
| 2672 | elif is_ipython and getattr(__builtins__, '__IP', None): | 2677 | elif is_ipython and '__IP' in builtins: |
| 2673 | completions = __IP.complete(text) | 2678 | completions = __IP.complete(text) |
| 2674 | elif is_ipython and getattr(__builtins__, 'get_ipython', None): | 2679 | elif is_ipython and 'get_ipython' in builtins: |
| 2675 | completions = get_ipython().Completer.all_completions(text) | 2680 | completions = get_ipython().Completer.all_completions(text) |
| 2676 | else: | 2681 | else: |
| 2677 | i = 0 | 2682 | i = 0 |