My Daily Development Workflow with Emacs and GNU Screen

I like to share my development workflow since it has greatly improve my efficiency as a programmer. Four tools have become indispensable for me as a developer, bash shell, SSH, GNU Screen, and Emacs. I work via remote machines. This has the benefit of a centralized and consistent environment. It provides the flexibility for me to jump from one local thin client to another. At the same time, preconfigured remote development machines save me time from replicating environments in my local boxes.

I start by opening a terminal on my laptop/desktop, SSH into one of the remote machines where I have previously started a GNU Screen session. For the unfamiliar, GNU Screen can multiplex virtual consoles and allow user to run multiple terminals over remote sessions. Within these GNU Screen sessions, I usually have multiple tabs. One tab with an Emacs session, and other tabs with bash shells. These screen sessions persist between SSH sessions. I can disconnect, reconnect from another box and re-attach the same screen sessions and everything would be there. This setup gives the benefit of quickly resuming where I left off. With all the command histories intact, I can pick up my train of thought from the previous work session.

In GNU Screen, I use the following configuration file, ~/.screenrc

# turn off screen's startup message
startup_message off

# tab bar with a clock
hardstatus alwayslastline "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "

shell -$SHELL

# change default screen escape key to C-z since C-a is one of my favorite key sequence in emacs (go to beginning of line
escape ^za

autodetach on

# I don't like the flashes
vbell off

# one tab with bash, another with emacs
screen -t Shell 0 bash
screen -t Emacs emacs

Some quick tips to get started with GNU Screen assuming the escape key is remapped to C-z

# start a new screen session

# detach/re-attach a screen session
screen -rD

# Some basic Hotkeys to navigate and issue commands within screen
# go to next tab
C-z n

# go to previous tab
C-z p

# skip to tab where num is 0 to 9
C-z num

# jump between last viewed tab and current tab
C-z z

# create a new tab
C-z c

In the Emacs session, I usually have a 3-way screen split. A half/half vertical split of two buffers with the primary source code on the left. The right half of the split is further horizontally split, where the top half contains a secondary source code file and the bottom half with a shell M-x shell.

Emacs 3-way screen split
3-way Emacs buffer split

When I don't need the shell and need more screen space for a secondary source code file reference, I would simply do a 2-way vertical split. Personally, I found it best to use a maximum of 3 splits (50% left, 25% top-right, and 25% bottom-right) and a minimum of 2 splits (50% left and 50% right) because I can quickly tab through two/three buffers. Use the following key sequences in Emacs to setup and navigate the split buffers.

# vertical 50/50 split
M-x 3

# horizontal 50/50 split
M-x 2

# unsplit current buffer
M-x 0

# jump to next buffer (left to right, top to bottom, in cycles)
M-x o

Other useful features I enable in Emacs is iswitchb-mode. This mode changes C-b x, buffer selection command, to substring match buffer names. You don't need to type full name of a buffer, just any substring of the buffer to filter out none matching ones, then C-s to select next or C-r to select previous. I'll leave Emacs tips at that since there are many external resources covering basic Emacs.

We all have our own set of favorite tools and incorporate them into our workflow. Sometimes whatever gets the work done with the least resistant wins, but venturing and learning something new can come with pleasant surprises. If you have never tried Emacs/GNU Screen, give them a try.