Emacs package: misTTY

There are a number of ways to run shells in Emacs. As is often the case, you can find an excellent overview of the various options over at Mastering Emacs. There is also a new entry in this space that is worth a look: misTTY.

I stumbled across misTTY the other day and have been trying it out. It’s under active development – so expect things to evolve – but the initial experience is quite smooth. I was able to load the package and get going right away. There is a manual on readthedocs that highlights some considerations for different shells (fish, bash, zsh).

(use-package mistty
  :bind ("C-c x m" . mistty))

I’ve bound a key to the primary command, mistty, which starts a terminal or switches to the buffer if already running. Without any customization I’m able to use my custom prompt themes, take advantage of shell history and auto-completion, run terminal applications, and so on.

The misTTY buffer is split into two “zones”:

  • the scrollback zone
  • the terminal zone

This approach allows for a fairly seamless Emacs integration experience. The scrollback zone has your past commands and output. Since this is Emacs, you can navigate/search/etc this text as you would in any other buffer.

The active prompt is the terminal zone, where certain keys need to get sent directly to the underlying terminal. This zone has its own key map (mistty-prompt-map), allowing you to configure keys for terminal interaction when point is at the prompt – but leave those keys working “normally” anywhere else in the misTTY buffer. The default configuration uses M- and C- modifiers in a way that lets you work with terminal applications without losing basic Emacs navigation keys. (Of course, you can customize this to meet your needs).

If you are interested in running a “full terminal” in Emacs, you may already be familiar with vterm. In vterm, terminal interaction takes precedence: you need to explicitly switch modes (vterm-copy-mode) to use your familiar Emacs bindings to search/copy/etc the scrollback text. I like misTTY’s zone approach, which makes working in terminal buffers more consistent with my Emacs workflow. But… vterm wins on performance. It’s use of a compiled C library means vterm is fast.

I would recommend giving misTTY a try. I’m keeping it in my configuration and am interested to see how it evolves over time. It may not compete with vterm on speed, but it takes an interesting approach that might fit your needs.

Update

The author of misTTY has updated the README to note:

MisTTY isn’t a terminal emulator, but rather a frontend to an existing terminal emulator, the built-in term.el. […] In theory, other terminal emulators than term.el might be used as engine for MisTTY, such as vterm and eat.

It would be quite interesting to run misTTY on top of vterm to take advantage of that performance boost.

Contents

@glucas on Mastodon