Sunday, February 10, 2008

Terminals? In MY Emacs?

Graphical text editors are fine. I'm okay with them. But when I'm in a terminal, I want something that will edit text while inside that terminal. Previously, this has been vim's task, and to a great extent it still is. But I've been mucking around in Emacs, and recently discovered M-x term.

Not too much to say about it: it's a fully-featured terminal emulator inside Emacs. The main reason I've turned to it was because I realised the version control facilities inside Emacs insofar as git is concerned are inadequate. Branching is a mess, commits for a single set of files appear as multiple commits in the system... git is a lot easier to manage via the command line. I suppose it's not entirely Emacs's fault: its version control system seems closely tied to the anachronism that is CVS. Or maybe I just don't understand it and need more time. The fact of the matter is that it's not working for me at the moment, not in the way I'd like it.

So, git. Most easily interacted with via the terminal. And I like being able to edit text while in those terminals. Since I'm developing a system in Common Lisp inside Emacs, which happens to support a terminal mode, it makes sense for me to do that editing inside Emacs. However, at a normal terminal, I still like editing stuff in vim, because it's quick and easy for me. It's possible and very easy to set this up:

Edit your ~/.bashrc or equivalent to include something like this:

if [ "$INSIDE_EMACS" ]; then
export EDITOR=emacsclient
else
export EDITOR=vim
fi

Then add this to your ~/.emacs

(server-start)

Or just run M-x server-start which does the same thing.

Now if a program invokes the EDITOR, it'll bring up an Emacs buffer while in the terminal in Emacs, which you can save/discard using C-x #, while opting for vim when using the terminal anywhere else.

No comments: