GNU bug report logs - #24110
[PATCH] Fix python.el completion with IPython 5.0 and python 2

Previous Next

Package: emacs;

Reported by: James Porter <james <at> jamesporter.me>

Date: Sat, 30 Jul 2016 01:18:02 UTC

Severity: normal

Tags: patch

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24110 in the body.
You can then email your comments to 24110 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#24110; Package emacs. (Sat, 30 Jul 2016 01:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to James Porter <james <at> jamesporter.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 30 Jul 2016 01:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: James Porter <james <at> jamesporter.me>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix python.el completion with IPython 5.0 and python 2
Date: Fri, 29 Jul 2016 21:01:16 -0400
In version 5.0 of IPython, which was recently released, the
IPCompleter.all_completions method changed slightly when running under
Python 2--it returns a unicode object rather than a str object. This
causes python.el completion to fail, since it uses this function and
the string Emacs gets back from the Python subprocess is e.g. if the
two valid completions are random and range: `u'random;range'` as
opposed to `'random;range'`, which isn't parsed correctly on the Emacs
side due to the spurious leading `u`. The below patch fixes this issue
by wrapping the string sent to Python for evaluation in a call to
`print`, which avoids printing the `u` when the return value is a
unicode object.

Cheers,
James Porter


* lisp/progmodes/python.el(python-shell-completion-string-code): Wrap
in a call to print to correctly handle the case that the return value
is unicode.

---
 lisp/progmodes/python.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index ad69f87..f87052f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3258,7 +3258,7 @@ def __PYTHON_EL_get_completions(text):
   :group 'python)

 (defcustom python-shell-completion-string-code
-  "';'.join(__PYTHON_EL_get_completions('''%s'''))"
+  "print(';'.join(__PYTHON_EL_get_completions('''%s''')))"
   "Python code used to get a string of completions separated by semicolons.
 The string passed to the function is the current python name or
 the full statement in the case of imports."
--
2.6.4 (Apple Git-63)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24110; Package emacs. (Mon, 03 Jul 2017 15:14:02 GMT) Full text and rfc822 format available.

Message #8 received at 24110 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: James Porter <james <at> jamesporter.me>
Cc: 24110 <at> debbugs.gnu.org
Subject: Re: bug#24110: [PATCH] Fix python.el completion with IPython 5.0 and
 python 2
Date: Mon, 03 Jul 2017 11:15:11 -0400
close 24110 
quit

James Porter <james <at> jamesporter.me> writes:

>  (defcustom python-shell-completion-string-code
> -  "';'.join(__PYTHON_EL_get_completions('''%s'''))"
> +  "print(';'.join(__PYTHON_EL_get_completions('''%s''')))"

This patch is no longer applicable, in 25.1 there is already a 'print'
added by python-shell-completion-get-completions.

    (defun python-shell-completion-get-completions (process import input)
      "Do completion at point using PROCESS for IMPORT or INPUT.
    When IMPORT is non-nil takes precedence over INPUT for
    completion."
      (setq input (or import input))
      (with-current-buffer (process-buffer process)
        (let ((completions
               (python-util-strip-string
                (python-shell-send-string-no-output
                 (format
                  (concat python-shell-completion-setup-code
                          "\nprint (" python-shell-completion-string-code ")")
                  input) process))))
          (when (> (length completions) 2)
            (split-string completions
                          "^'\\|^\"\\|;\\|'$\\|\"$" t)))))






bug closed, send any further explanations to 24110 <at> debbugs.gnu.org and James Porter <james <at> jamesporter.me> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Mon, 03 Jul 2017 15:14:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 01 Aug 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 37 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.