Emacs as a tmux replacement

Łukasz Korecki
2 min readFeb 20, 2017

--

Years ago I did what many developers do — built an IDE of sorts by combining Vim, Tmux and Bash. By the use of scripting, REPLs and such one can glue all these tools together to have things like “open a new shell and send this text to it” work semi-reliably.

Brave new world

Eventually I switched (back) to Emacs. After refreshing my muscle memory and building a sane config I proceeded to replace Vim with Emacs.

One of the reasons for switching was that I get to write a lot of Lisp — mostly Clojure and some Scheme (Chicken Scheme in particular, but I’m also looking at Racket).

Emacs being a Lisp machine the tooling for working with Lisps is phenomenal. Packages like CIDER and Geiser show how Emacs can become an IDE, without being a huge mess of a toolbars, popups and a taking too many resources.

Initially I’d ran a terminal version of Emacs within a tmux session. Then, I started exploring packages like inf-ruby and running terminals within Emacs (via ansi-term) more often than opening tmux windows and panes. There was simply no need for that.

The only thing that I used tmux for was persisting the session on the machine to quickly resume what I was working on. That has a major drawback — ssh-agent details get lost when that happens, which means tools like magit become less useful and require Emacs restart.

Removing tmux

Using daemon mode in Emacs one can replicate all features (and more) of tmux/screen:

  • sessions can be suspended and resumed
  • universal copy and paste between terminal any type of a buffer
  • window/pane layout management
  • tmux ‘windows’ can be emulated with packages like eyebrowse

ssh-agent issue when using magit

With a simple shell script:

if pgrep -f emacs ; then
emacs --daemon

fi

emacsclient -nw

and an extra package I can now use magit without any issues. It simply injects relevant SSH environment variables and “magically” fixes the problem.

Better navigation

Window number mode is really handy. It adds number to visible buffers/windows and dynamically creates mappings to jump between, similar to how tmux does it.

So given 3 visible buffers, pressing C-x C-j 2 will jump to 2nd visible buffer.

Issues?

Only issue I keep running into is that a long running (week?) Emacs session sometimes becomes corrupted and syntax highlighting in some major modes starts to crap out. I haven’t found a fix for this, but given my experience with Emacs so far the fix surely exists. On top of that — I don’t mind occasional Emacs server restarts.

--

--

Łukasz Korecki

CTO & Co-founder of https://collieapp.com Also living room musician, kitchen scientist. Street Fighter 6 enjoyer