From 5ac3a8a6c4a9ef9ac79f1fc28f0a86153b68b450 Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Wed, 28 May 2014 11:21:05 +0200 Subject: [PATCH 1/2] ENH Start a new Ipython kernel from vim This is a bit hacky, but it works well enough: 1. generate a new random ID 2. use the subprocess to start a completely new IPython kernel process with that ID. This may not even be the same Python version that vim is running (this is a feature, not a bug) 3. connect to this kernel Currently, the kernel is automatically killed at exit. --- README.rst | 1 + ftplugin/python/ipy.vim | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.rst b/README.rst index 7ffe375..c7ff5f2 100644 --- a/README.rst +++ b/README.rst @@ -292,6 +292,7 @@ pull request with your attribution. * @flacjacket for pointing out and providing fix for IPython API change * @memeplex for fixing the identifier grabbing on e.g. non-PEP8 compliant code * @pydave for IPythonTerminate (sending SIGTERM using our hack) +* @luispedro for IPythonNew Similar Projects ---------------- diff --git a/ftplugin/python/ipy.vim b/ftplugin/python/ipy.vim index 5c88db7..d43936f 100644 --- a/ftplugin/python/ipy.vim +++ b/ftplugin/python/ipy.vim @@ -111,6 +111,19 @@ instance using IPython's own machinery. It does *not* mean that the IPython instance with which you communicate via vim-ipython needs to be running the same version of Python. """ + + +def new_ipy(): + from random import random + from subprocess import Popen, PIPE + from time import sleep + import atexit + fname = "vim.ipython.%s.json" % (int(random()*100000)) + p = Popen(["ipython", "kernel", "-f", fname], shell=False, stdout=PIPE, stdin=PIPE, stderr=PIPE) + atexit.register(p.kill) + sleep(3) + return km_from_string(fname) + def km_from_string(s=''): """create kernel manager from IPKernelApp string such as '--shell=47378 --iopub=39859 --stdin=36778 --hb=52668' for IPython 0.11 @@ -749,6 +762,7 @@ endif command! -nargs=* IPython :py km_from_string("") command! -nargs=0 IPythonClipboard :py km_from_string(vim.eval('@+')) command! -nargs=0 IPythonXSelection :py km_from_string(vim.eval('@*')) +command! -nargs=0 IPythonNew :py new_ipy() command! -nargs=* IPythonInterrupt :py interrupt_kernel_hack("") command! -nargs=0 IPythonTerminate :py terminate_kernel_hack() From 3cf69de42bdd6298ca0e4fe1d45baee45ecb6dd4 Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Wed, 9 Sep 2015 17:00:28 +0200 Subject: [PATCH 2/2] DOC Fix documentation in README The mappings use (and not ). --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 26e556a..a7ae04d 100644 --- a/README.rst +++ b/README.rst @@ -120,9 +120,9 @@ IPython's object? Functionality If you're using gvim, mouse-over a variable to see IPython's ``?`` equivalent. If you're using vim from a terminal, or want to copy something from the -docstring, type ``d``. ```` is usually ``\`` (the backslash -key). This will open a quickpreview window, which can be closed by hitting -``q`` or ````. +docstring, type ``d``. ```` is usually ``\`` (the +backslash key). This will open a quickpreview window, which can be closed by +hitting ``q`` or ````. -------------------------------------- IPython's tab-completion Functionality @@ -143,7 +143,7 @@ IPython, and what IPython sends back in response. updated on every sent command (default: True). If at any later time you wish to bring this shell up, including if you've set -``monitor_subchannel=False``, hit ``s``. +``monitor_subchannel=False``, hit ``s``. **NEW since IPython 0.12** For local kernels (kernels running on the same machine as vim), `Ctrl-C` in