emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-24 7bf7edf: * lisp/progmodes/python.el (python-shell


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] emacs-24 7bf7edf: * 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.
Date: Thu, 27 Nov 2014 02:45:34 +0000

branch: emacs-24
commit 7bf7edf53f65752f408d0f5e9d0af56bfcf683f5
Author: Fabián Ezequiel Gallina <address@hidden>
Date:   Wed Nov 26 23:45:24 2014 -0300

    * 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 5947c76..af75f8d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-27  Fabián Ezequiel Gallina  <address@hidden>
+
+       * 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  <address@hidden>
 
        * calendar/todo-mode.el: Handle calling revert-buffer (bug#19187).
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4c27136..48d80b9 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]