emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master ab9252a: python.el: Do not break IPython magic comp


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] master ab9252a: python.el: Do not break IPython magic completions.
Date: Mon, 06 Apr 2015 22:19:46 +0000

branch: master
commit ab9252a01a61d08cc866dfc73dbed95523523556
Author: Fabián Ezequiel Gallina <address@hidden>
Commit: Fabián Ezequiel Gallina <address@hidden>

    python.el: Do not break IPython magic completions.
    
    Fixes: debbugs:19736
    
    * lisp/progmodes/python.el (python-shell-completion-setup-code):
    Cleaner setup; import rlcompleter as last resource.
---
 lisp/ChangeLog           |    7 +++++++
 lisp/progmodes/python.el |   35 +++++++++++++++++++++--------------
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d2f01c3..7060258 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2015-04-06  Fabián Ezequiel Gallina  <address@hidden>
+
+       python.el: Do not break IPython magic completions.  (Bug#19736)
+
+       * progmodes/python.el (python-shell-completion-setup-code):
+       Cleaner setup; import rlcompleter as last resource.
+
 2015-04-06  Artur Malabarba  <address@hidden>
 
        * emacs-lisp/package.el: Fix lack of "new" packages.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 50b9d1b..c89241b 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2962,25 +2962,25 @@ This function takes the list of setup code to send from 
the
 
 (defcustom python-shell-completion-setup-code
   "try:
-    import __builtin__
-except ImportError:
-    # Python 3
-    import builtins as __builtin__
-try:
-    import readline, rlcompleter
+    import readline
 except:
     def __PYTHON_EL_get_completions(text):
         return []
 else:
     def __PYTHON_EL_get_completions(text):
+        try:
+            import __builtin__
+        except ImportError:
+            # Python 3
+            import builtins as __builtin__
         builtins = dir(__builtin__)
         completions = []
+        is_ipython = ('__IPYTHON__' in builtins or
+                      '__IPYTHON__active' in builtins)
+        splits = text.split()
+        is_module = splits and splits[0] in ('from', 'import')
         try:
-            splits = text.split()
-            is_module = splits and splits[0] in ('from', 'import')
-            is_ipython = ('__IPYTHON__' in builtins or
-                          '__IPYTHON__active' in builtins)
-            if is_module:
+            if is_ipython and is_module:
                 from IPython.core.completerlib import module_completion
                 completions = module_completion(text.strip())
             elif is_ipython and '__IP' in builtins:
@@ -2988,13 +2988,20 @@ else:
             elif is_ipython and 'get_ipython' in builtins:
                 completions = get_ipython().Completer.all_completions(text)
             else:
+                # Try to reuse current completer.
+                completer = readline.get_completer()
+                if not completer:
+                    # importing rlcompleter sets the completer, use it as a
+                    # last resort to avoid breaking customizations.
+                    import rlcompleter
+                    completer = readline.get_completer()
                 i = 0
                 while True:
-                    res = readline.get_completer()(text, i)
-                    if not res:
+                    completion = completer(text, i)
+                    if not completion:
                         break
                     i += 1
-                    completions.append(res)
+                    completions.append(completion)
         except:
             pass
         return completions"



reply via email to

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