* 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.
parent 47f573a4
2014-11-27 Fabián Ezequiel Gallina <fgallina@gnu.org>
* 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.
2014-11-26 Stephen Berman <stephen.berman@gmx.net> 2014-11-26 Stephen Berman <stephen.berman@gmx.net>
* calendar/todo-mode.el: Handle calling revert-buffer (bug#19187). * calendar/todo-mode.el: Handle calling revert-buffer (bug#19187).
......
...@@ -2653,25 +2653,30 @@ This function takes the list of setup code to send from the ...@@ -2653,25 +2653,30 @@ This function takes the list of setup code to send from the
(defcustom python-shell-completion-setup-code (defcustom python-shell-completion-setup-code
"try: "try:
import readline, rlcompleter import __builtin__
except ImportError: except ImportError:
# Python 3
import builtins as __builtin__
try:
import readline, rlcompleter
except:
def __PYTHON_EL_get_completions(text): def __PYTHON_EL_get_completions(text):
return [] return []
else: else:
def __PYTHON_EL_get_completions(text): def __PYTHON_EL_get_completions(text):
builtins = dir(__builtin__)
completions = [] completions = []
try: try:
splits = text.split() splits = text.split()
is_module = splits and splits[0] in ('from', 'import') is_module = splits and splits[0] in ('from', 'import')
is_ipython = getattr( is_ipython = ('__IPYTHON__' in builtins or
__builtins__, '__IPYTHON__', '__IPYTHON__active' in builtins)
getattr(__builtins__, '__IPYTHON__active', False))
if is_module: if is_module:
from IPython.core.completerlib import module_completion from IPython.core.completerlib import module_completion
completions = module_completion(text.strip()) completions = module_completion(text.strip())
elif is_ipython and getattr(__builtins__, '__IP', None): elif is_ipython and '__IP' in builtins:
completions = __IP.complete(text) completions = __IP.complete(text)
elif is_ipython and getattr(__builtins__, 'get_ipython', None): elif is_ipython and 'get_ipython' in builtins:
completions = get_ipython().Completer.all_completions(text) completions = get_ipython().Completer.all_completions(text)
else: else:
i = 0 i = 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment