Today was a good emacs day. Actually, any day I spend in emacs is good, but today was especially good, since I found three new little gems to stick in my init.el.
/* ---[ Show only one buffer on startup ]--- */
First, I wanted emacs to only open with a single buffer showing when I pass multiple files to it on the command line. A few minutes later, solution #1 found:
[Update 20-Aug-2012]: gist updated with shorter version based on feedback from Steven Purcell.
/* ---[ Override a paredit keybinding ]--- */
I've come to love paredit when working in Clojure and emacs-lisp. Except for one problem: for years I've used Cntl-<left>
and Cntl-<right>
a lot to quickly navigate around. Those keystrokes are deeply ingrained in my motor memory. The paredit author's way of working differs from mine though, since he bound those to "barf" and "slurp" (mmmmm), respectively. When you then try to zip quickly around the screen using Cntl-<left>
and Cntl-<right>
with paredit-mode enabled, your cursor goes nowhere and instead you make a holy mess of your parens and brackets in the file.
So I wanted to rebind barf and slurp to Meta-<left>
and Meta-<right>
and unbind the existing mappings with the Control key. For a while I've just been editing the paredit.el file, but now that we have a package system in emacs24, that will get overridden when I upgrade. Thus, I need a clean way to do this that works for any future upgrades. So, a few minutes later, solution #2 found:
I hadn't seen the eval-after-load
function before. It is a particularly satisfying way to override bindings in another package.
/* ---[ Toggle between multiple windows and a single window ]--- */
I've been teaching emacs to an intern at my job and today after showing him macros, how to toggle comment blocks and ace-jump-mode (which is awesome!), he asked: currently, I've got 4 buffers showing, but what if I want to expand one window to fill the window, work on it and then restore emacs back to having the 4 buffers I had showing before?
My response: blink, blink.
Umm, that would awesome, why didn't I think of that? So a few minutes later, thanks to Ignacio Paz Posse (about the coolest name I've ever seen), beautiful solution #3:
This is my favorite emacs thing now.
That is, until I find the next shiny bit of emacs-lisp to make my day happier than usual.
[Update 20-Aug-2012]: Steve Purcell in the comments pointed out that there is another way to restore your window configuration that has been built into emacs since version 20: Winner Mode.
So if you have trouble with the toggle-windows-split
or would rather use something built-in, try this instead. In your .emacs or init.el add:
(winner-mode 1)
Then when you have multiple buffers showing and you want to maximize one of them enter C-x 1
as usual to close all other windows except the one with cursor focus. To restore your previous window configuration enter C-c <left>
. Sweetness.