Mental context switches are evil. Some people handle them better than others, but not me. I handle them worse. I feel it, almost physically, when context switches whittle down my precious flow piece by piece. It hurts!

Even something as small as switching between Emacs and the shell can hurt, especially when I do it thousands of times a day. The physical movement isn’t so bad; it’s that they have different key bindings, different clipboards, and myriad deeper differences in behavior. What’s worse, only some parts are different, so my muscle memory is constantly seduced into a false sense of familiarity, only to have the rug yanked out from under it seconds later.

I put together various hacks to bring Emacs and my shell closer together, with some success, but it always felt like a chronic disease. Curing it completely was never on the table; I could only hope to manage it.

The holy grail, of course, was running shells inside Emacs. I had high hopes when I tried it eight years ago, but it didn’t work out. I tried it again recently though, and it’s still early days, but we’re pretty happy together this time. I think we might go the distance!

Here are a few remaining rough edges:

If I enter multiple commands with newlines between them, the prompt is reprinted as soon as the first command finishes. This is misleading, since the rest are still running. (This still happens if I put ; s or \ line continuations between them.)

s or line continuations between them.) If I start my shells in my .emacs , they don’t parse the ^[[K ANSI color codes in output like ls -l ‘s. (This is with ansi-color-for-comint-mode on). However, if I start them after emacs has booted, they parse fine. Huh?

, they don’t parse the ANSI color codes in output like ‘s. (This is with on). However, if I start them after emacs has booted, they parse fine. Huh? Optimize TRAMP. It’s decently fast right now, but I’m sure I could make it even faster!

Here are some things I did manage to tweak:

Here’s the code in my .emacs: