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

Distraction free programming with GNU emacs

Editors

Since becoming a switcher in 2004 I exclusively did my work in Textmate. Early summer 2008 I started to explore other options. I spent a couple of months in Vim, MacVim to be precise, and really enjoyed it. After I got comfortable with MacVim, it's tabs and use of NerdTree for file management started to feel a lot like Textmate. That's not necessarily a bad thing, just not what I was really looking for.

emacs

During my Vim use, I launched emacs (Carbon Emacs) a few times and was turned off by the key combinations. However, the more I played with it, the more I liked it and the key combos quickly became a non-issue; almost second nature. If i wanted to cheat, i can turn on mac-key-mode for shortcuts that behave like Mac programs. Emacs runs on windows and linux so I decided to take the plunge and learn key combos the emacs way in case I have to jump to Ubuntu.

A Distraction Free Work Environment

For distraction-prone people like me, emacs excels in the full-screen department. When I think full screen I think Writeroom, Aperture and Lightroom, where everything is gone including the menu bar leaving me with nothing except the task I'm working on. This is something I could not effectively do with Textmate and I found myself constantly switching between Textmate and Terminal to get my work done, with an occasional jump to Twitterific, NetNewsWire and irc.

emacs-fullscreen-clean-th.png
[Full-screen capture: this is all i see when I'm working in emacs.]
emacs-fullscreen-menu-th.png
[Full-screen: mouse-over menu bar]
emacs-fullscreen-alt-th.png
[Full-screen: alternate layout]

Explanation of screenshots

Windows in emacs are backwards from what you expect them to be. Emacs calls the collection of windows or a single window a frame and a frame can be split horizontally or vertically in a number of ways to create multiple windows. Depicted in the screenshots I have everything I need. The top window is the code I'm currently working on. In the lower left window I have dired for my file management and terminal (or shell) in the lower right so I never have to switch between emacs and Terminal. The third screenshot is simply a illustration of another way I find myself splitting the frame.

Snippet for full screen toggling

I have my full screen toggle tied to the key combo Meta-[RET]. That's command+return on a mac. To use this add the following to your .emacs file and restart or refresh emacs.


;; full screen toggle using command+[RET]
(defun toggle-fullscreen () 
  (interactive) 
  (set-frame-parameter nil 'fullscreen (if (frame-parameter nil 'fullscreen) 
                                           nil 
                                           'fullboth)))
(global-set-key [(meta return)] 'toggle-fullscreen) 

In the coming posts in this emacs series I'll break down dired and the use of shell (or terminal) and how to use these tools effectively.

[Update: i've made my dotemacs available in case anyone wants to take a peek. Suggestions are welcome]

8 Comments

Nice post. I must admit that once I got my hands on this snippet, it was great. On my 17" screen, I can comfortably split a window so it tiles 3 wide by 2 deep. The biggest problem I have with that is that emacs's movement commands aren't as fluid as vim's. By saying that, I really mean I haven't figured out a way to configure emacs's movement keys to do what I want. :) Can't wait for the rest of these posts!

Thanks Jlilly.

On my 24" i do the same thing, split it many ways. On my 15" MBP i use one of the configs above. I do agree, it's a tad cumbersome jumping windows with keystrokes but I tend to use my mouse and/or trackpad for that so I haven't really found a need to come up with my own shortcuts... yet.

In MacVim, just hit ⌘⇧F to toggle fullscreen mode.

I never had good luck with full screen on my 24" monitor in macvim. It left a section of vim in the center of my monitor with scrollbars and about 5 inches on both sides of black. Wasn't very effective for me.

Now you made me want full screen for GVIM! Derrrr....


Csmr

Nice article. I agree VIM rocks and full-screen mode is the best.

Nice series. I just stumbled on your blog via github by way of del.icio.us.

Do you have code that puts emacs in those layouts? Or do you do it by hand each time?

Hi Seth. Thanks.

The commands C-x-3 (control+x 3) will split your frame vertically and C-x-2 will split your screen horizontally. Within emacs you can do that as many times as you want provided you have a large enough monitor.

Leave a comment