Magma is a NeoVim plugin for running code interactively with Jupyter.

Overview

Magma

Magma is a NeoVim plugin for running code interactively with Jupyter.

Requirements

  • NeoVim 0.5+
  • Python 3.8+
  • Required Python packages:
    • pynvim (for the Remote Plugin API)
    • jupyter_client (for interacting with Jupyter)
    • ueberzug (for displaying images)
    • Pillow (also for displaying images, should be installed with ueberzug)
    • cairosvg (for displaying SVG images)
    • pnglatex (for displaying TeX formulas)
    • plotly and kaleido (for displaying Plotly figures)

You can do a :checkhealth to see if you are ready to go.

Note: Python packages which are used only for the display of some specific kind of output are only imported when that output actually appears.

Installation

Use your favourite package/plugin manager.

If you use packer.nvim,

use { 'dccsillag/magma-nvim', run = ':UpdateRemotePlugins' }

If you use vim-plug,

Plug 'dccsillag/magma-nvim', { 'do': ':UpdateRemotePlugins' }

Note that you will still need to configure keymappings -- see Keybindings.

Suggested settings

If you want a quickstart, these are the author's suggestions of mappings and options (beware of potential conflicts of these mappings with your own!):

nnoremap  r  :MagmaEvaluateOperator
nnoremap        rr :MagmaEvaluateLine
xnoremap        r  :MagmaEvaluateVisual
nnoremap        rc :MagmaReevaluateCell
nnoremap        rd :MagmaDelete
nnoremap        ro :MagmaShowOutput

let g:magma_automatically_open_output = v:false

Note: Key mappings are not defined by default because of potential conflicts -- the user should decide which keys they want to use (if at all).

Note: The options that are altered here don't have these as their default values in order to provide a simpler (albeit perhaps a bit more inconvenient) UI for someone who just added the plugin without properly reading the README.

Usage

The plugin provides a bunch of commands to enable interaction. It is recommended to map most of them to keys, as explained in Keybindings. However, this section will refer to the commands by their names (so as to not depend on some specific mappings).

Interface

When you execute some code, it will create a cell. You can recognize a cell because it will be highlighted when your cursor is in it.

A cell is delimited using two extmarks (see :help api-extended-marks), so it will adjust to you editing the text within it.

When your cursor is in a cell (i.e., you have an active cell), a floating window may be shown below the cell, reporting output. This is the display window, or output window. (To see more about whether a window is shown or not, see :MagmaShowOutput and g:magma_automatically_open_output). When you cursor is not in any cell, no cell is active.

Also, the active cell is searched for from newest to oldest. That means that you can have a cell within another cell, and if the one within is newer, then that one will be selected. (Same goes for merely overlapping cells).

The output window has a header, containing the execution count and execution state (i.e., whether the cell is waiting to be run, running, has finished successfully or has finished with an error). Below the header are shown the outputs.

Jupyter provides a rich set of outputs. To see what we can currently handle, see Output Chunks.

Commands

MagmaInit

This command initializes a runtime for the current buffer.

It can take a single argument, the Jupyter kernel's name. For example,

:MagmaInit python3

will initialize the current buffer with a python3 kernel.

It can also be called with no arguments, as such:

:MagmaInit

This will prompt you for which kernel you want to launch (from the list of available kernels).

MagmaDeinit

This command deinitializes the current buffer's runtime and magma instance.

:MagmaDeinit

Note You don't need to run this, as deinitialization will happen automatically upon closing Vim or the buffer being unloaded. This command exists in case you just want to make Magma stop running.

MagmaEvaluateLine

Evaluate the current line.

Example usage:

:MagmaEvaluateLine

MagmaEvaluateVisual

Evaluate the selected text.

Example usage (after having selected some text):

:MagmaEvaluateVisual

MagmaEvaluateOperator

Evaluate the text given by some operator.

This won't do much outside of an mapping. Example usage:

nnoremap  r nvim_exec('MagmaEvaluateOperator', v:true)

Upon using this mapping, you will enter operator mode, with which you will be able to select text you want to execute. You can, of course, hit ESC to cancel, as usual with operator mode.

MagmaReevaluateCell

Reevaluate the currently selected cell.

:MagmaReevaluateCell

MagmaDelete

Delete the currently selected cell. (If there is no selected cell, do nothing.)

Example usage:

:MagmaDelete

MagmaShowOutput

This only makes sense when you have g:magma_automatically_open_output = v:false. See Customization.

Running this command with some active cell will open the output window.

Example usage:

:MagmaShowOutput

MagmaSave

Save the current cells and evaluated outputs into a JSON file, which can then be loaded back with :MagmaLoad.

It has two forms; first, receiving a parameter, specifying where to save to:

:MagmaSave file_to_save.json

If that parameter is omitted, then one will be automatically generated using the g:magma_save_path option.

:MagmaSave

MagmaLoad

Load the cells and evaluated outputs stored in a given JSON file, which should have been generated with :MagmaSave.

Like MagmaSave, It has two forms; first, receiving a parameter, specifying where to save to:

:MagmaLoad file_to_load.json

If that parameter is omitted, then one will be automatically generated using the g:magma_save_path option.

Keybindings

It is recommended to map all the evaluate commands to the same mapping (in different modes). For example, if we wanted to bind evaluation to r:

nnoremap  r  nvim_exec('MagmaEvaluateOperator', v:true)
nnoremap        rr :MagmaEvaluateLine
xnoremap        r  :MagmaEvaluateVisual
nnoremap        rc :MagmaReevaluateCell

This way, r will behave just like standard keys such as y and d.

You can, of course, also map other commands:

nnoremap  rd :MagmaDelete
nnoremap  ro :MagmaShowOutput

Customization

Customization is done via variables.

g:magma_automatically_open_output

Defaults to v:true.

If this is true, then whenever you have an active cell its output window will be automatically shown.

If this is false, then the output window will only be automatically shown when you've just evaluated the code. So, if you take your cursor out of the cell, and then come back, the output window won't be opened (but the cell will be highlighted). This means that there will be nothing covering your code. You can then open the output window at will using :MagmaShowOutput.

g:magma_cell_highlight_group

Defaults to "CursorLine".

The highlight group to be used for highlighting cells.

g:magma_save_path

Defaults to stdpath("data") .. "/magma".

Where to save/load with :MagmaSave and :MagmaLoad (with no parameters).

The generated file is placed in this directory, with the filename itself being the buffer's name, with % replaced by %% and / replaced by %, and postfixed with the extension .json.

[DEBUG] g:magma_show_mimetype_debug

Defaults to v:false.

If this is true, then before any non-iostream output chunk, Magma shows the mimetypes it received for it.

This is meant for debugging and adding new mimetypes.

Extras

Output Chunks

In the Jupyter protocol, most output-related messages provide a dictionary of mimetypes which can be used to display the data. Theoretically, a text/plain field (i.e., plain text) is always present, so we (theoretically) always have that fallback.

Here is a list of the currently handled mimetypes:

  • text/plain: Plain text. Shown as text in the output window's buffer.
  • image/png: A PNG image. Shown with Ueberzug.
  • image/svg+xml: A SVG image. Rendered into a PNG with CairoSVG and shown with Ueberzug.
  • application/vnd.plotly.v1+json: A Plotly figure. Rendered into a PNG with Plotly + Kaleido and shown with Ueberzug.
  • text/latex: A LaTeX formula. Rendered into a PNG with pnglatex and shown with Ueberzug.

This already provides quite a bit of basic functionality. As development continues, more mimetypes will be added.

Notifications

We use the vim.notify API. This means that you can use plugins such as rcarriga/nvim-notify for pretty notifications.

License

This code is licensed under the GPLv3 (due to Ueberzug using it).

Owner
Daniel Csillag
Daniel Csillag
Commandline script to interact with volkswagencarnet library

volkswagencarnet-client command line script to interact with volkswagencarnet library Table of Contents General Info Setup Usage Example Acknowledgeme

3 Jan 19, 2022
Colab-xterm allows you to open a terminal in a cell

colab-xterm Colab-xterm allows you to open a terminal in a cell. Usage Install package and load the extension !pip install git+https://github.com/popc

InfuseAI 194 Dec 29, 2022
A Terminal UI for Discord

ToastCord ToastCord is a Discord Terminal UI. At the moment you can only look at Direct messages. TODO: - Add support for guilds - Message sending sup

toast 82 Dec 18, 2022
f90nml - A Fortran namelist parser, generator, and editor

f90nml - A Fortran namelist parser, generator, and editor A Python module and command line tool for parsing Fortran namelist files Documentation The c

Marshall Ward 110 Dec 14, 2022
Generate an ASCII Art from keyword put in the cli

ascii-art-generator-cli Generate an ASCII Art from keyword put in the cli Install git clone https://github.com/Nathanlauga/ascii-art-generator-cli cd

Nathan Lauga 1 Nov 14, 2021
Interact with Replit remotely with the Replit CLI

Replit CLI pip install repl-cli Welcome to Replit CLI! With the Replit CLI Application, you can work with your repls locally, including clone, pull,

Shuchir Jain 4 Aug 18, 2022
Colors in Terminal - Python Lang

🎨 Colorate - Python 🎨 About Colorate is an Open Source project that makes it easy to use Python color coding in your projects. After downloading the

0110 Henrique 1 Dec 01, 2021
Stream comments, submissions from subreddits and users across reddit right in your terminal

reddit_from_terminal stream comments, submissions from subreddits and users across reddit right in your terminal Alert! : Can't watch media contents(p

Pritam Dhara 2 Dec 30, 2021
A simple command line tool written in python to manage a to-do list

A simple command line tool written in python to manage a to-do list Dependencies: python Commands: todolist (-a | --add) [(-p | --priority)] [(-l | --

edwloef 0 Nov 02, 2021
Magnificent app which corrects your previous console command.

The Fuck The Fuck is a magnificent app, inspired by a @liamosaur tweet, that corrects errors in previous console commands. Is The Fuck too slow? Try t

Vladimir Iakovlev 75k Jan 02, 2023
Library and command-line utility for rendering projects templates.

A library for rendering project templates. Works with local paths and git URLs. Your project can include any file and Copier can dynamically replace v

808 Jan 04, 2023
3DigitDev 29 Jan 17, 2022
Pynavt is a cli tool to create clean architecture app for you including Fastapi, bcrypt and jwt.

Pynavt _____ _ | __ \ | | | |__) | _ _ __ __ ___ _| |_ | ___/ | | | '_ \ / _` \ \ / /

Alejandro Castillo 1 Dec 13, 2021
A terminal utility to sort image files based on their characteristics.

About A terminal utility to sort image files based on their characteristics. Motivation This program was developed after I've realized that I had too

José Ferreira 1 Dec 10, 2022
An open source terminal project made in python

Calamity-Terminal An open source terminal project made in python. Calamity Terminal is a free and open source lightweight terminal. Its made 100% off

1 Mar 08, 2022
Command Line Based Todo Script

Todo-CLI Features Full-Fledged Command Line Based Todo List with the following features planned: Interactive Interface OS Notifications Save and Remov

DSC IIEST 5 Nov 17, 2021
🌍 Harness the power of whatsmydns from the command-line.

chkdns Harness the power of whatsmydns from the command-line. Installing with pip pip install chkdns Run chkdns --host github.com Alternatively you ca

Craig Gumbley 3 Oct 29, 2022
Python script to tabulate data formats like json, csv, html, etc

pyT PyT is a a command line tool and as well a library for visualising various data formats like: JSON HTML Table CSV XML, etc. Features Print table o

Mobolaji Abdulsalam 1 Dec 30, 2021
Bryce Geiser 4 Aug 04, 2022
Python API and CLI for the ikea IDÅSEN desk.

idasen This is a heavily modified fork of rhyst/idasen-controller. The IDÅSEN is an electric sitting standing desk with a Linak controller sold by ike

Alex 79 Dec 14, 2022