all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#24110: [PATCH] Fix python.el completion with IPython 5.0 and python 2
@ 2016-07-30  1:01 James Porter
  2017-07-03 15:15 ` npostavs
  0 siblings, 1 reply; 2+ messages in thread
From: James Porter @ 2016-07-30  1:01 UTC (permalink / raw)
  To: 24110

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)





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#24110: [PATCH] Fix python.el completion with IPython 5.0 and python 2
  2016-07-30  1:01 bug#24110: [PATCH] Fix python.el completion with IPython 5.0 and python 2 James Porter
@ 2017-07-03 15:15 ` npostavs
  0 siblings, 0 replies; 2+ messages in thread
From: npostavs @ 2017-07-03 15:15 UTC (permalink / raw)
  To: James Porter; +Cc: 24110

close 24110 
quit

James Porter <james@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)))))







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-03 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-30  1:01 bug#24110: [PATCH] Fix python.el completion with IPython 5.0 and python 2 James Porter
2017-07-03 15:15 ` npostavs

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.