[
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2020 Untiled AI\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# jupyter_ascending.vim\n\nVim plugin to interact with `jupyter_ascending`\nCurrently only supports Jupyter Notebook.\n\n![Jupyter Ascending](./media/simple_jupyter_ascending.gif)\n\n\n## Installation\n\nFirst, you must install [jupyter_ascending](https://github.com/untitled-ai/jupyter_ascending) in the python envirenment you're working in. For example:\n```bash\n$ pyenv activate my_notebook_env\n$ pip install jupyter_ascending\n```\n\nIt is possible you won't need to run the following commands on newer version of jupyter notebook, but it's recommended that you do anyway, because installing extensions is hard. Or unless you already executed them in the previous step of installing `jupyter_ascending`.\n```bash\n$ jupyter nbextension install --py --sys-prefix jupyter_ascending\n$ jupyter nbextension     enable jupyter_ascending --sys-prefix --py\n$ jupyter serverextension enable jupyter_ascending --sys-prefix --py\n```\n\nYou can confirm it's installed by checking:\n```bash\n$ jupyter nbextension     list\n$ jupyter serverextension list\n```\n\nThen install this plugin using the vim plugin manager you like. For example:\n\n```\n  Plug 'untitled-ai/jupyter_ascending.vim'\n```\n\nOr if you use lua configs:\n```\n  use 'untitled-ai/jupyter_ascending.vim'\n```\n\n## Usage\n1) First create a Jupyter notebook notebook_name.sync.ipynb.\n2) Then generate a notebook_name.sync.py file using jupytext with \"percent format\". (see Paired notebooks in [jupytext](https://github.com/mwouts/jupytext))\n3) Edit .sync.py file in vim and Jupyter Ascending will update the .sync.ipynb every time .sync.py is saved.\n4) Send commands to Jupyter notebook via the following mappings:\n\nExecute cell\n```vim\nnmap <space><space>x <Plug>JupyterExecute\n```\n\nExecute all cells\n```vim\nnmap <space><space>X <Plug>JupyterExecuteAll\n```\n\nRestart kernel\n```vim\nnmap <space><space>r <Plug>JupyterRestart\n\n```\nNOTE: it syncs your `py` file with `ipynb` file whenever you save your `py` file.\n\nUse `# %%` to separate cells.\nUse `# %% [markdown]` to make a markdown block.\n\n\n## Settings\nSee `doc/jupyter_ascending.txt` for more information.\n"
  },
  {
    "path": "autoload/jupyter_ascending.vim",
    "content": "function! s:on_stdout(j, d, e)\n  if len(a:d) > 0 && len(a:d[0]) > 0\n    echom '[JupyterAscending]' a:d\n  endif\nendfunction\n\nfunction! s:execute(command_string) abort\n  if has('nvim')\n    call jobstart(a:command_string, {\n          \\ 'on_stdout': funcref('s:on_stdout')\n          \\ })\n  else\n    call systemlist(a:command_string)\n  end\nendfunction\n\nfunction! jupyter_ascending#sync() abort\n  let file_name = expand(\"%:p\")\n\n  if match(file_name, g:jupyter_ascending_match_pattern) < 0\n    return\n  endif\n\n  let command_string = printf(\n        \\ \"%s -m jupyter_ascending.requests.sync --filename '%s'\",\n        \\ g:jupyter_ascending_python_executable,\n        \\ file_name\n        \\ )\n\n  call s:execute(command_string)\nendfunction\n\nfunction! jupyter_ascending#execute() abort\n  let file_name = expand(\"%:p\")\n\n  if match(file_name, g:jupyter_ascending_match_pattern) < 0\n    return\n  endif\n\n  let command_string = printf(\n        \\ \"%s -m jupyter_ascending.requests.execute --filename '%s' --linenumber %s\",\n        \\ g:jupyter_ascending_python_executable,\n        \\ file_name,\n        \\ line('.')\n        \\ )\n\n  call s:execute(command_string)\nendfunction\n\nfunction! jupyter_ascending#execute_all() abort\n  let file_name = expand(\"%:p\")\n\n  if match(file_name, g:jupyter_ascending_match_pattern) < 0\n    return\n  endif\n\n  let command_string = printf(\n        \\ \"%s -m jupyter_ascending.requests.execute_all --filename '%s'\",\n        \\ g:jupyter_ascending_python_executable,\n        \\ file_name\n        \\ )\n\n  call s:execute(command_string)\nendfunction\n\n\nfunction! jupyter_ascending#restart() abort\n  let file_name = expand(\"%:p\")\n\n  if match(file_name, g:jupyter_ascending_match_pattern) < 0\n    return\n  endif\n\n  let command_string = printf(\n        \\ \"%s -m jupyter_ascending.requests.restart --filename '%s'\",\n        \\ g:jupyter_ascending_python_executable,\n        \\ file_name\n        \\ )\n\n  call s:execute(command_string)\nendfunction\n"
  },
  {
    "path": "doc/jupyter_ascending.txt",
    "content": "===============================================================================\njupyter_ascending                                           *jupyter_ascending*\n\nEasily interact with the python package `jupyter_ascending`\n\n\nVim Package   : https://github.com/untitled-ai/jupyter_ascending.vim/\n\nPython Package: https://github.com/untitled-ai/jupyter_ascending\n\n===============================================================================\njupyter_ascending_config                              *jupter_ascending_config*\n\njupyter_ascending_python_executable     *g:jupyter_ascending_python_executable*\n    The path/executable that can be used to execute Python.\n\n    If using virtual environment, make sure to have the virtual environment\n    enabled or accessible to Vim.\n\n    Default: ~\n        \"python\"\n\njupyter_ascending_match_pattern             *g:jupyter_ascending_match_pattern*\n\n    Only files that match this file pattern will be synced and/or executed\n    with the `jupyter_ascending` package.\n\n    Default: ~\n        \".sync.py\"\n\njupyter_ascending_auto_write                   *g:jupyter_ascending_auto_write*\n\n    If true, will auto write and sync the file to Jupyter Notebook whenever\n    you save in Vim.\n\n    Default: ~\n        `v:true`\n\n\n vim:tw=78:et:ft=help:norl:\n"
  },
  {
    "path": "plugin/jupyter_ascending.vim",
    "content": "let g:jupyter_ascending_python_executable = get(g:, 'jupyter_ascending_python_executable', 'python')\nlet g:jupyter_ascending_match_pattern     = get(g:, 'jupyter_ascending_match_pattern', '.sync.py')\nlet g:jupyter_ascending_auto_write        = get(g:, 'jupyter_ascending_auto_write', v:true)\n\naugroup JupyterAscending\n  au!\n\n  if g:jupyter_ascending_auto_write\n    autocmd BufWritePost * :call jupyter_ascending#sync()\n  endif\naugroup END\n\n\nnnoremap <Plug>JupyterExecute    :call jupyter_ascending#execute()<CR>\nnnoremap <Plug>JupyterExecuteAll :call jupyter_ascending#execute_all()<CR>\nnnoremap <Plug>JupyterRestart    :call jupyter_ascending#restart()<CR>\n\n\nif get(g:, 'jupyter_ascending_default_mappings', v:true)\n  nmap <space><space>x <Plug>JupyterExecute\n  nmap <space><space>X <Plug>JupyterExecuteAll\n  nmap <space><space>r <Plug>JupyterRestart\nendif\n"
  }
]