My Emacs Workflow
Published 2012-06-06 @ 12:00
Tagged productivity, emacs
My emacs workflow is a lot harder to write about because after 20+ years, it is a lot more ingrained than omnifocus that I’m not even aware of a lot of what I do. I used to do everything in emacs including mail and much of my web (before the days of everything being flash or ajax). IMAP, flash, and javascript have put the latter two on hold.
That said, I still spend much of my time in emacs. I use it to:
- (Obviously) edit nearly everything.
- Edit filenames and permissions. Dired allows you to edit both of these and commit your changes en masse. Having regular expression search & replace makes this a joy.
- Run multiple shells. I wish more people understood the power of having your shell in an emacs buffer. The ability to move up into output and grab stuff is immense.
- Talk on IRC. Having IRC integrated into your text editor means you can easily discuss the code you’re working on.
- Running tests. I generally don’t run my tests inside of a shell. Instead, it is fully integrated into emacs and provides hyperlinked paths in all backtraces.
- Not flipping back and forth between applications all day. I can spend a lot more time focused on the task at hand. This is seriously underestimated. Even watching power vim users switch back and forth between terminal and vim is painfully inefficient.
- Focus on my work. Having no visual distractions is a joy. Since I have everything integrated within emacs, this is my first and still pretty much only app that I fullscreen in.
To help with this I’ve written some libraries and adopted many more.
My Libraries
I have couple of libraries available on my page on emacswiki. I’ll be specifically talking about autotest.el and toggle.el in following posts.
Fullscreen & Splits
Emacs on OSX has only recently gotten fullscreen mode. It isn’t fully baked yet. I use the following code to help manage it a bit better:
1 2 3 4 5 6 7 8 |
(setq ns-is-fullscreen nil) (defadvice ns-toggle-fullscreen (before record-state compile activate) (setq ns-is-fullscreen (not ns-is-fullscreen))) (defun rwd-ns-fullscreen () (interactive) (or ns-is-fullscreen (ns-toggle-fullscreen))) |
I usually combine full-screen mode with a vertical split with a shell on the left and edit buffers on the right. I use functions to position emacs for particular purposes like the following:
1 2 3 4 5 |
(defun rwd-resize-presentation () "Create a giant font window suitable for doing live demos." (interactive) (rwd-arrange-frame 92 34 t) (rwd-set-font-size 20)) |
With the following supporting functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
(defun rwd-set-font-size (size) (interactive "nSize: ") (rwd-set-mac-font "DejaVu Sans Mono" size)) (defun rwd-set-mac-font (name size) (interactive (list (completing-read "font-name: " (mapcar (lambda (p) (list p p)) (font-family-list)) nil t) (read-number "size: " 12))) (set-face-attribute 'default nil :family name :slant 'normal :weight 'normal :width 'normal :height (* 10 size)) (frame-parameter nil 'font)) (defun rwd-arrange-frame (w h &optional nosplit) "Rearrange the current frame to a custom width and height and split unless prefix." (let ((frame (selected-frame))) (when (memq (framep frame) '(mac ns)) (delete-other-windows) (set-frame-position frame 5 25) (set-frame-size frame w h) (if (not nosplit) (split-window-horizontally))))) |
Colors
The amount of time that people spend tweaking on colorschemes and the like has always seemed like mentarbation to me. I pretty much use the default emacs colorscheme with a minimal number of tweaks (which you can actually see here, because I adapted my syntax highlighting CSS to match emacs):
1 2 3 |
'(font-lock-comment-face (:foreground "Dark Blue")) '(font-lock-constant-face (:foreground "SlateBlue4")) '(font-lock-string-face (:foreground "Forest Green")) |
Specifically, by default in emacs comments are Firebrick (red) and strings are VioletRed4. In my opinion, things should only be red if I need to pay attention to them right now. The constant face seems to be used a lot less now, but it defaults to aquamarine and that’s not enough contrast on a white background for my eyes.
I also use something called blank-mode
that highlights trailing
whitespace and lines that are too long. It makes my code much cleaner
and your code much more annoying to read. :)
1 2 3 |
'(blank-chars (quote (tabs trailing lines-tail space-before-tab))) '(blank-line-length 82) '(blank-style (quote (color))) |
with the following faces:
Version Control
I use a combination of emacs’ built-in vc
modes, p4.el, and magit.el
because I still find 80+% of git to be bewilderingly unusable. I would
use vc-p4.el but I can’t for the life of me get it to work and the
original author has abandoned it.
Particularly, I find VC’s C-x v =
to quickly display diffs, C-x v
g
to run an annotated blame with heatmap, and C-x v v
(vc-next-action
) to do whatever is next to do
(lock/unlock/commit/merge) as simply brilliant. Between those three
commands, you can do 80% of what you need to do throughout the day.
IRC
I use erc
to do all IRC stuffs. Being able to hit C-c C-SPC
to
flip across unread IRC buffers and back to the buffer I was working in
makes it a joy to use. I have almost no tweaks for this because their
module system is so powerful and complete. The only thing I’ve added
are some commands to talk to dircproxy so I can get backlog when I log
in after an extended absence.
Tags
I don’t know how many times I’ve said this… but if you’re not using exuberant ctags, you suck as a developer. Period. I have a ruby script called “rtag” that is pretty much just a slightly-more-complex version of this:
1 |
system "#{ctags} -Re --languages=#{langs} --exclude='#{excls}' ."
|
After that, M-.
will quickly whisk you off to the definition of
whatever function you have under point and M-*
pops you back one
level.
You. Need. This.
If you work in emacs or vim… you simply need this. If you work in something else and it doesn’t support tags, you should seriously reconsider your text editor. And no, you adorable textmate users, nothing you have even comes close.
SSH / Remote Editing
I use M-x ssh
and tramp
to go to remote machines and edit remote
files. I don’t do it as often as I do local files, but it is nice to
have. Oh, and they’re integrated, so if you ssh to a box inside emacs
and then try to edit a file on that side, tramp will automatically
kick in and pull down the file. It makes it a lot easier than trying
to remember the stupid path syntax.
That’s all I can think of… did I miss anything?