Created
December 19, 2018 18:01
-
-
Save mattn/00236f847e6af5a8be2dc785142c957c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"argv": [ | |
"python", | |
"c:/Users/mattn/AppData/Roaming/jupyter/kernels/vimkernel/vimkernel.py", | |
"-f", | |
"{connection_file}" | |
], | |
"display_name": "Vim" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ipykernel.kernelbase import Kernel | |
from subprocess import Popen, STDOUT, PIPE | |
class Vim(Kernel): | |
implementation = 'Vim' | |
implementation_version = '0.1' | |
language = 'no-op' | |
language_version = '0.1' | |
language_info = {'name': 'Vim', 'mimetype': 'text/plain'} | |
banner = 'Vim script' | |
_d = {} | |
def do_execute(self, code, silent, store_history=True, | |
user_expressions=None, allow_stdin=False): | |
with open('prog.vim', 'w') as f: | |
f.write("\n".join(code.splitlines())) | |
p = Popen(['vim', '-X', '-N', '-u', 'NONE', '-i', 'NONE', '-V1', '-e', '-s', '-S', 'prog.vim', '+qall!'], stdout=PIPE, stderr=STDOUT, shell=True) | |
p.wait() | |
exitcode = p.returncode | |
output = p.communicate()[0].decode() | |
self.send_response(self.iopub_socket, 'stream', {'name': 'stdout', 'text': output}) | |
return {'status': 'ok', | |
'execution_count': self.execution_count, | |
'payload': [], | |
'user_expressions': {}, | |
} | |
if __name__ == '__main__': | |
from ipykernel.kernelapp import IPKernelApp | |
IPKernelApp.launch_instance(kernel_class=Vim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment