Coder Social home page Coder Social logo

comint-mime's Introduction

comint-mime.el

This Emacs package provides a mechanism for REPLs (or comint buffers, in Emacs parlance) to display graphics and other types of special content.

comint-mime in Python

The main motivation behind this package is to display plots in the Python shell. However, it does more that that.

First, it is not constrained to graphics, and can display other “MIME attachments” such as HTML and LaTeX content. In fact, the Python backend of the package implements IPython's rich display interface. A use-case beyond the displaying of graphics would be to render dataframes as HTML tables; this opens up the possibility of typographical improvements over the usual pure-text representation. You can also easily define rich representations for your own classes.

Second, the package defines a flexible communication protocol between Emacs and the inferior process, and, consequently, can be extended to other comint types. Currently, besides Python, there is support for the regular (Unix) shell. In this case, a special command, mimecat, is provided to display content. Again, this works for images, HTML, LaTeX snippets, etc.

comint-mime in Bash

Usage

To start enjoying comint-mime, simply call M-x comint-mime-setup from a supported buffer (which, at the moment, are the M-x shell and M-x run-python buffers). To apply this permanently, add that same function to the appropriate mode hook:

(add-hook 'shell-mode-hook 'comint-mime-setup)
(add-hook 'inferior-python-mode-hook 'comint-mime-setup)

Note that for Python it is important to use the IPython interpreter. It can be configured to have the same look-and-feel as the classic python program as follows.

(when (executable-find "ipython3")
  (setq python-shell-interpreter "ipython3"
        python-shell-interpreter-args "--simple-prompt --classic"))

Extending

To add support for new MIME types, see comint-mime-renderer-alist.

To add support for new comints, an entry should be added to comint-mime-setup-function-alist. This function should arrange for the inferior process to emit an escape sequence whenever some MIME content is to be displayed.

The escape sequence has the following shape:

ESC ] 5 1 5 1 ; header LF payload ESC \

Here, header is a JSON object containing, at least, the entry type, which should be the name of a MIME type. Other header entries can be passed; the interpretation is up to the rendering function.

The payload can be either the content of the attachment, encoded in base64 (which is decoded before being passed to the selected renderer), or a file:// URL (whose content is read and passed to the renderer), or yet a tmpfile:// URL, which indicates that the file should be deleted after it is read.

Note that it can take considerable time to insert large amounts of data in a comint buffer, specially if it contains long lines. Consider using a temporary file for large data transfers.

Todos

  • It should be possible to support at least Matplotlib in the classic python interpreter.
  • Improve the HTML rendering for numeric tables

comint-mime's People

Contributors

astoff avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.