aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2014-11-26 23:45:24 -0300
committerFabián Ezequiel Gallina2014-11-26 23:45:24 -0300
commit7bf7edf53f65752f408d0f5e9d0af56bfcf683f5 (patch)
tree4ed89a4fd78933d181a30d1d97ea0acc308e7790
parent47f573a4bf6b5126884286690ce1e8818ada74ee (diff)
downloademacs-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/ChangeLog6
-rw-r--r--lisp/progmodes/python.el17
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 @@
12014-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
12014-11-26 Stephen Berman <stephen.berman@gmx.net> 72014-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__
2657except ImportError: 2657except ImportError:
2658 # Python 3
2659 import builtins as __builtin__
2660try:
2661 import readline, rlcompleter
2662except:
2658 def __PYTHON_EL_get_completions(text): 2663 def __PYTHON_EL_get_completions(text):
2659 return [] 2664 return []
2660else: 2665else:
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