What Emacs is to editors, Stumpwm is to window managers
Tuesday, April 29, 2008
In case I haven't been clear in my earlier blog posts (see
some of them here), I like Emacs a lot. ;-) The thing I *really, really* like
about it is that I can customize it with Lisp. I'll be working away
and suddenly I will think of something I wish that I was able to do
in Emacs. Usually, a quick google will show me that someone else has
already thought of the same thing and written an elisp library for
it. However, if there isn't something already out there, I will usually dive in and write
it myself. The ability to dynamically change your working environment
is one of the key reasons why so many programmers "live" in Emacs.
Until recently I haven't really played around much with different
window/desktop managers in Linux. My primary desktop machine has
always run either Windows or Mac OS X and any Linux work that I did was
server-based. However, when I got
my OLPC XO laptop, that changed. Since it was such a cheap laptop
and I used it mostly while traveling (when I frequently have free time
to burn on planes, airports, and hotel rooms), I played around a bit with different
implementations of Linux and different window and desktop
managers. At different times, I installed the Fedora, Debian, and
Ubuntu Linux distributions and tried out Sugar, XFCE, Gnome, KDE, and
Ratpoison. In the end, for the XO, I decided to stick with Sugar as it
works ok on the XO for what I need it for (when I'm traveling with it,
I'm usually just reading ebooks, surfing the Internet, reading email,
and listening to music). However,
playing around with different configurations got me more interested in
desktop Linux (I've been fairly happy as a Mac OS X user for the past few years). Of
all the Linux distributions, I liked Ubuntu the best (easiest to find
info about on the web and really well supported with frequent releases
and updates).
Of the
window/desktop managers, I really liked
Ratpoison - a "minimalist" window manager that has a similar
"feel" and "philosophy" (see
here for some of the "early inspiration" for ratpoison ;-) ) to that of
GNU screen, avoids dependency on mouse usage, and is very
Emacs-friendly. People who like the Emacs way of doing things seem to
like Ratpoison quite a lot. Ratpoison is written by Shawn Betts (who also wrote
the original
Conkeror). After using (and liking) Ratpoison, I saw that Shawn
was working on a successor to Ratpoison called
Stumpwm. Stumpwm is very much like Ratpoison (similar commands,
look-and-feel, philosophy) but is written in Common Lisp. Although I
tried
Ratpoison on my XO, it was a bit problematic (given the extremely
small keyboard and issues with the very small X11 fonts). I installed
both Ratpoison and Stumpwm on my Macbook; however (since they don't work
with Aqua), they're not as useful on OS X (see
here for some considerations if you want to try them on OS X
Leopard). If you use Mac OS X and you want to avoid using the mouse
more than you have to, a better alternative is probably
Quicksilver (which I've used for a few years now).
I've been running Ubuntu
in a Parallels VM on Mac OS X for a few months now, so I decided to try out
both Ratpoison and Stumpwm in the Ubuntu VM on my Mac. Both worked fine and I setup
Stumpwm as my primary window manager. I gradually started using the VM
more and more as I liked the ability to swap between
full-screen applications and to easily customize my environment.
Then,
recently I installed Ubuntu 8.04 and Stumpwm on an older Windows laptop
that I had. Since then, I've been really enjoying using Stumpwm/Linux
on the cheap laptop and my expensive Macbook Pro has been sitting off to the side! I
have even been toying with the idea of installing Ubuntu instead of OS
X on my Macbook Pro (we'll have to see about that one!).
Male did an excellent
Stumpwm screencast that shows what it's like to use
Stumpwm, so I won't describe that here. However, I would like to
demonstrate how it's usage (for a Lisp developer) is similar to
Emacs. First of all, lets say you're running Stumpwm on your laptop and
trying to type in Emacs. However, your hand keeps brushing the
touchpad and moving the cursor. With Stumpwm, you can just (a) add some
code to your .stumpwmrc file to toggle on/off the touchpad so that it
doesn't interfere with your typing, (b) do a "slime-connect" to connect to the
running CL and (c) evaluate the code - immediately, your window manager
disables the touchpad for all applications that are running and hides the cursor (and you can just press "C-t
T" to toggle it back on). Here's the necessary code:
(define-stumpwm-command "toggle-touchpad" ()
"Toggle the laptop touchpad on/off.
Need to have set 'Option SHMConfig' for Synaptics Touchpad
device in xorg.conf."
(let ((state (run-shell-command
"synclient -l | grep TouchpadOff | awk '{ print $3 }'" t)))
(case (string= (subseq state 0 1) "1")
(t (shell-command "synclient TouchpadOff=0"))
(otherwise (shell-command "synclient TouchpadOff=1")
(banish-pointer)))))
(define-key *root-map* (kbd "T") "toggle-touchpad")
;; Turn off Touchpad initially
(shell-command "synclient TouchpadOff=1")
;; Get rid of cursor initially
(banish-pointer)
Now, say you want to create a shortcut key (say "C-t f") to launch Firefox if it
isn't currently running or switch to it if it is running - just add
the following to your .stumpwmrc file and evaluate the code
(alternatively, if you don't want the change to be permanent, you can
just evaluate the code in a SLIME REPL in Emacs or send it to Stumpwm
via the "stumpish" shell script interface):(defcommand firefox () () "Start/Switchto Firefox." (run-or-raise "firefox" '(:class "Firefox")))Stumpwm lets you have a mode-line that can be used to show different things (e.g. - what windows/groups are open, date/time, cpu usage, etc). I normally don't want to see the mode-line (because I don't like to see mode-line info unless I want to see it) but I do want to see it when I'm running a Stumpwm command (I display window/group info in the mode-line; therefore, if I'm switching to a different window/group, it's convenient to have the mode-line display when I'm initiating something in Stumpwm). So, I created a "hook" that runs whenever the Stumpwm "escape key" (by default - "C-t") is pressed. Now, I only see the mode line when I actually need to see it:
(define-key *root-map* (kbd "f") "firefox")
(defun toggle-mode-line-hook (key key-seq cmd) (declare (ignore key key-seq cmd)) (mode-line))So, you get the picture - since your window manager is written in Lisp and you can dynamically change and/or add to the running code, the hacks never stop!
(add-hook *key-press-hook* 'toggle-mode-line-hook)
Indeed, Stumpwm is to window managers as Emacs is to editors!

