From 7bf7edf53f65752f408d0f5e9d0af56bfcf683f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Wed, 26 Nov 2014 23:45:24 -0300 Subject: [PATCH] * 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. --- lisp/ChangeLog | 6 ++++++ 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 @@ +2014-11-27 Fabián Ezequiel Gallina + + * 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 * 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 (defcustom python-shell-completion-setup-code "try: - import readline, rlcompleter + import __builtin__ except ImportError: + # Python 3 + import builtins as __builtin__ +try: + import readline, rlcompleter +except: def __PYTHON_EL_get_completions(text): return [] else: def __PYTHON_EL_get_completions(text): + builtins = dir(__builtin__) completions = [] try: splits = text.split() is_module = splits and splits[0] in ('from', 'import') - is_ipython = getattr( - __builtins__, '__IPYTHON__', - getattr(__builtins__, '__IPYTHON__active', False)) + is_ipython = ('__IPYTHON__' in builtins or + '__IPYTHON__active' in builtins) if is_module: from IPython.core.completerlib import module_completion completions = module_completion(text.strip()) - elif is_ipython and getattr(__builtins__, '__IP', None): + elif is_ipython and '__IP' in builtins: 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) else: i = 0 -- 2.11.4.GIT