Winner Mode

In my Two From Phil post I mentioned that Phil had urged me to try winner-mode and that I was going to give it a try. For those who came in late, winner-mode captures the current window configuration and allows you to restore it after it gets changed by some Emacs action.

I was a little skeptical but I enabled winner-mode and 10 minutes later I was hopelessly addicted. This all comes at a good time because I have lately been setting Emacs to be 162 characters wide so that I can have two columns of “standard sized” windows1. That set up makes it really easy to mess up your window configuration. For example, if you bring up a help screen, the focus remains in the original window as usual but now it's hard to get rid of the *Help* window. If you type 【Ctrl+x 1】 you blow away all your other windows. You can switch into the *Help* window and type 【q】 but that's a pain. With winner-mode you simply restore the previous window configuration and you're back to where you were before invoking help.

If you aren't currently using winner-mode, do yourself a favor and give it a spin. It's built-in functionality so all you have to do to try it is type 【Meta+xwinner-mode and you're all set. Now 【Ctrl+c 】 will restore the previous window configuration and 【Ctrl+c 】 will redo the configuration you just destroyed.

Try it like this for a bit and see if you aren't addicted too. If you are, just add

(winner-mode 1)

to your .emacs or init.el file and it will always be their for you. If you don't like it, just turn it off with 【Meta+-1 Meta+xwinner-mode. I had intended to try it for a week or so to see how I liked it but, as I say, I enabled it permanently almost immediately. Really, you should try it out.


1 I know, I know but I'm an old-timey guy and can't get over the notion that the proper size for a (source code) screen is 80 characters. It makes no sense, I admit, but there it is.

This entry was posted in General and tagged . Bookmark the permalink.
  • Phil

    Personally I recommend that people go ahead and enable it permanently, purely for its safety-net property.

    Even if you're not using it regularly in your workflow and forget the key binding, so long as you can remember M-x winner-undo (or just "winner" -- the tab completions are few) you will really appreciate it the next time that an elaborate window configuration gets messed up, and you remember that you can get it all back again with a single command!

    For me, that was the original reason to add it to my init file; however it also quickly worked its way into my regular workflow, in much the same way that jcs found :)

    In addition, as it's not clear from the article, note that it's not just the previous configuration which is remembered. winner-mode maintains a list of all previous configurations -- up to a configurable maximum -- and you can step back through them all with repeated calls to winner-undo. This means you can take quite a 'detour' from the configuration you wish to return to, and still use winner-undo to get back to where you started. For example, you might jump to some TAGs in other files, or execute a grep and then follow some matches, and afterwards you can always use winner-undo to return to the buffers you were originally looking at.

    Conversely winner-redo doesn't step through the list, but always returns you directly to the most recent configuration. I actually find this slightly annoying if I 'overshoot' with multiple winner-undo commands, so it's probably a good candidate for customisation.