Amazon.com Widgets
...not so private reflections of greg.newman
RSS feed - Categories & Search

Emacs Terminal Emulator

In Distraction Free Progamming with Emacs I mentioned the ability to have a shell or terminal running in a window within your workspace. This is extremely handy to run tests in Python Shell or to see when something is going wrong with your code. The emacs wiki is a great source of information but I'll give you a quick rundown on how to get up and running quickly.

First thing I did was I made sure I could make use of my bash aliases within shell or terminal inside emacs. Since .bash_profile is executed for login shells and .bashrc is executed for interactive non-login shells I made a change to my bash files. I moved all my aliases from .bash_profile to .bashrc and added the following snippet to my .bash_profile to ensure that both terminal and shell are setup and ready to go.


if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

When I use terminal within emacs I like to split the frame into multiple windows using C-x 2 for a horizontal split or C-x 3 for a vertical split and resize my windows for a small terminal session, usually in a corner--away from my work. To start the terminal session simply use the key combination M-x term and if you want to use /bin/bash for your session confirm when prompted or you can change it to your liking (tcsh users). To jump to another window simply execute C-x o or even simpler, use your mouse.

[Note: if you prefer shell, use M-x shell instead of term.]

A minor modes that makes my terminal use a little nicer is multi-term which allows me to start multiple terminal sessions with the key combo M-x multi-term, and allow you to page through them with M-x multi-term-next and M-x multi-term-previous. M-x multi-term-list will give you a listing of all your terminal session to choose from. To use multi-term download the minor mode and add the following to your .emacs.


(require 'multi-term)
(multi-term-keystroke-setup) 
(setq multi-term-program "/bin/bash") 

The multi-term-program flag above stops the annoying prompt for /bin/bash everytime I initiate a terminal session.

Now this is distraction free programming. Never having to jump between an editor and terminal!

3 Comments

Hi, I'm author of multi-term.el.

Thanks for use multi-term.el :)

I think you have to use version 0.2
But above link is version 0.1 and not handle conflict keystroke with term-mode.

And the link of 0.2 is at:
Link to 0.2 download

One thing that's important to point out is that, at least for me, shell didn't give me color support or the ability to use gnu screen.

I'm going to have to check out multi-term. Do you have any keyboard shortcuts to switch your term?

Andy Stewart
Thank you. I didn't realize there was a newer version. I've updated the link to multi-term. Searching around and can't find this in a repo for easy tracking. And worth pointing out that version 0.2 has better key bindings from glancing at the underlying code.

Justin Lilly
You're right, ansi-color sucks in shell mode.
Take a look at the newer version of multi-term that Andy pointed out. It has keybindings from what I can see.

Leave a comment