Repository: untitled-ai/jupyter_ascending.vim Branch: master Commit: 8b0f533fbf7f Files: 5 Total size: 7.1 KB Directory structure: gitextract_zzuf9woh/ ├── LICENSE ├── README.md ├── autoload/ │ └── jupyter_ascending.vim ├── doc/ │ └── jupyter_ascending.txt └── plugin/ └── jupyter_ascending.vim ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 Untiled AI Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # jupyter_ascending.vim Vim plugin to interact with `jupyter_ascending` Currently only supports Jupyter Notebook. ![Jupyter Ascending](./media/simple_jupyter_ascending.gif) ## Installation First, you must install [jupyter_ascending](https://github.com/untitled-ai/jupyter_ascending) in the python envirenment you're working in. For example: ```bash $ pyenv activate my_notebook_env $ pip install jupyter_ascending ``` It 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`. ```bash $ jupyter nbextension install --py --sys-prefix jupyter_ascending $ jupyter nbextension enable jupyter_ascending --sys-prefix --py $ jupyter serverextension enable jupyter_ascending --sys-prefix --py ``` You can confirm it's installed by checking: ```bash $ jupyter nbextension list $ jupyter serverextension list ``` Then install this plugin using the vim plugin manager you like. For example: ``` Plug 'untitled-ai/jupyter_ascending.vim' ``` Or if you use lua configs: ``` use 'untitled-ai/jupyter_ascending.vim' ``` ## Usage 1) First create a Jupyter notebook notebook_name.sync.ipynb. 2) Then generate a notebook_name.sync.py file using jupytext with "percent format". (see Paired notebooks in [jupytext](https://github.com/mwouts/jupytext)) 3) Edit .sync.py file in vim and Jupyter Ascending will update the .sync.ipynb every time .sync.py is saved. 4) Send commands to Jupyter notebook via the following mappings: Execute cell ```vim nmap x JupyterExecute ``` Execute all cells ```vim nmap X JupyterExecuteAll ``` Restart kernel ```vim nmap r JupyterRestart ``` NOTE: it syncs your `py` file with `ipynb` file whenever you save your `py` file. Use `# %%` to separate cells. Use `# %% [markdown]` to make a markdown block. ## Settings See `doc/jupyter_ascending.txt` for more information. ================================================ FILE: autoload/jupyter_ascending.vim ================================================ function! s:on_stdout(j, d, e) if len(a:d) > 0 && len(a:d[0]) > 0 echom '[JupyterAscending]' a:d endif endfunction function! s:execute(command_string) abort if has('nvim') call jobstart(a:command_string, { \ 'on_stdout': funcref('s:on_stdout') \ }) else call systemlist(a:command_string) end endfunction function! jupyter_ascending#sync() abort let file_name = expand("%:p") if match(file_name, g:jupyter_ascending_match_pattern) < 0 return endif let command_string = printf( \ "%s -m jupyter_ascending.requests.sync --filename '%s'", \ g:jupyter_ascending_python_executable, \ file_name \ ) call s:execute(command_string) endfunction function! jupyter_ascending#execute() abort let file_name = expand("%:p") if match(file_name, g:jupyter_ascending_match_pattern) < 0 return endif let command_string = printf( \ "%s -m jupyter_ascending.requests.execute --filename '%s' --linenumber %s", \ g:jupyter_ascending_python_executable, \ file_name, \ line('.') \ ) call s:execute(command_string) endfunction function! jupyter_ascending#execute_all() abort let file_name = expand("%:p") if match(file_name, g:jupyter_ascending_match_pattern) < 0 return endif let command_string = printf( \ "%s -m jupyter_ascending.requests.execute_all --filename '%s'", \ g:jupyter_ascending_python_executable, \ file_name \ ) call s:execute(command_string) endfunction function! jupyter_ascending#restart() abort let file_name = expand("%:p") if match(file_name, g:jupyter_ascending_match_pattern) < 0 return endif let command_string = printf( \ "%s -m jupyter_ascending.requests.restart --filename '%s'", \ g:jupyter_ascending_python_executable, \ file_name \ ) call s:execute(command_string) endfunction ================================================ FILE: doc/jupyter_ascending.txt ================================================ =============================================================================== jupyter_ascending *jupyter_ascending* Easily interact with the python package `jupyter_ascending` Vim Package : https://github.com/untitled-ai/jupyter_ascending.vim/ Python Package: https://github.com/untitled-ai/jupyter_ascending =============================================================================== jupyter_ascending_config *jupter_ascending_config* jupyter_ascending_python_executable *g:jupyter_ascending_python_executable* The path/executable that can be used to execute Python. If using virtual environment, make sure to have the virtual environment enabled or accessible to Vim. Default: ~ "python" jupyter_ascending_match_pattern *g:jupyter_ascending_match_pattern* Only files that match this file pattern will be synced and/or executed with the `jupyter_ascending` package. Default: ~ ".sync.py" jupyter_ascending_auto_write *g:jupyter_ascending_auto_write* If true, will auto write and sync the file to Jupyter Notebook whenever you save in Vim. Default: ~ `v:true` vim:tw=78:et:ft=help:norl: ================================================ FILE: plugin/jupyter_ascending.vim ================================================ let g:jupyter_ascending_python_executable = get(g:, 'jupyter_ascending_python_executable', 'python') let g:jupyter_ascending_match_pattern = get(g:, 'jupyter_ascending_match_pattern', '.sync.py') let g:jupyter_ascending_auto_write = get(g:, 'jupyter_ascending_auto_write', v:true) augroup JupyterAscending au! if g:jupyter_ascending_auto_write autocmd BufWritePost * :call jupyter_ascending#sync() endif augroup END nnoremap JupyterExecute :call jupyter_ascending#execute() nnoremap JupyterExecuteAll :call jupyter_ascending#execute_all() nnoremap JupyterRestart :call jupyter_ascending#restart() if get(g:, 'jupyter_ascending_default_mappings', v:true) nmap x JupyterExecute nmap X JupyterExecuteAll nmap r JupyterRestart endif