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-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!