Wednesday, November 19, 2008

WMII

Update (2008/11/20): Some basic information added to "Customizing WMII".

Preparing for the move to a university, I began setting up a mousless Linux system, that will be comfortable when I finally manage to buy a notepad (in the near future, hopefully). Mouseless editors I've been using for a long time, no problem there. Browser: check (Vimperator or Conkeror will do nicely). Music player: check (mpd + keybindings in the WM). What remains is the DE/WM itself. I've been keeping an eye on tabbing window managers for a while and decided to give WMII a go. I have to say, I'm seriously in love.
It's lightweight and does everything I need from a WM.

Customizing WMII

WMII has a rather unique (compared to Gnome/KDE) and refreshing attitude to settings. It provides a Plan9 virtual filesystem for interacting with all the features. This means you can write customizations in anything from sh to Python, compiled C or even PHP. It has to be an executable, and it has to manipulate this virtual filesystem. The way to do so is through wmiir, a wrapper around ixpc to directly access the WMII filesystem. See wmiir (without arguments) or man ixpc for the details.

The first thing you can do to shape your WMII the way you want is modify your wmiirc or rc.wmii. See the WMII homepage for details on which to choose. Whenever you see wmiirc in the following, you can safely read "wmiirc or rc.wmii".
The system default is usually found in /etc/wmii-$version or /etc/X11/wmii-$version. A file with the same name in your ~/.wmii-$version overrides this, so copy the default there and get hacking. This is a shell script, but as mentiond above, it could be any executable. And I mean executable, that is chmod +x wmiirc.

You can also create custom scripts run by the WM, actions in WMII lingo. These should be in the same directory as the wmiirc executable. They must themselves be executable, that is in /etc/[X11]/wmii-$version, and just like your wmiirc, they can be anything from a shell script to compiled C++. If there's a way to automatically start one on WMII startup, I haven't found it; I currently include them in my wmiirc.

Pitfall: don't forget to add an & after anything you launch from your wmiirc, even in keybindings. It will otherwise wait for the new process to finish before processing anything else.

Examples

One thing I missed at first was a notification area for my music player and Pidgin. The Pidgin problem I haven't solved yet, but the music player is nicely covered. There's mention of a status-mpd script in several places, but I couldn't find a downloadable version anywhere. Well, except for in a malformed cat output in some Russian forum. The result of some tinkering is that I now have the following in in my statusbar:

[p] Metallica - Attitude 0:31/5:16
I can also switch tracks with Alt-Shift-n and Alt-Shift-p, and pause/continue playing with Alt-Shift-w, thanks to mpc.

The somewhat modified status-mpd:

#!/bin/sh

xwrite() {
    file="$1";
    shift
    echo -n "$@" | wmiir write "$file"
}

wmiir remove /rbar/mpd 2>/dev/null && sleep 2
wmiir create /rbar/mpd


while [ 1 ]
do
    FILE=`mpc | sed -n '1p'`
    STATUS=`mpc | sed -n '2s/\[\(.*\)\].*/\1/;2s/playing/p/p;2s/paused/s/p;2s/stopped/t/p'`
    TIME=`mpc | sed -n '2s/.*   \([^ ]*\).*/\1/p'`
    xwrite /rbar/mpd "[$STATUS] $FILE $TIME"
    sleep 1 
done

And the lines that take care of the keybindings controlling mpd (add them below the default Key stuff):

Key $MODKEY-Shift-n
 mpc next > /dev/null
Key $MODKEY-Shift-p
 mpc prev > /dev/null
Key $MODKEY-Shift-w
 mpc toggle > /dev/null

The first listing, btw, was this time created by the VIM :TOhtml command.

Sunday, November 16, 2008

Editor wars

Of course it's the usual Vim vs. Emacs stuff. Some time ago I thought I had left Vim for good. But. There's a comment somewhere on the net along the lines of "Use Vim and Emacs. Vim is the better text editor, Emacs is the better programmable environment." So, what the hell, I picked up O'Reillys "Learning the vi and Vim Editors", and after three or four days I have to say, that comment was right on the spot.

As we all know, they both have their strengths and weaknesses. Also, I haven't been in business long enough to be sure, but IMHO the (not so?) friendly competition between the editors seem to lead to a very similar feature-set for the end-user (that is, me). (X)HTML+CSS+JavaScript+PHP+XSL+Whatnot is, for example, better suited for Vim, due to the awkwardness of multiple major modes in Emacs. Mumamo is great most of the time. OTOH, I still haven't seen anything resembling the LaTeX preview mode of Emacs in Vim (that might be just my ignorance though).

Conkeror and Vimperator

Talk about similar feature-sets... Not part of the editors proper, but both the Vim and Emacs crowds have created a Firefox plugin (later stand-alone browser in the case of Conkeror), that fit their philosophies and the bindings of their favorite editor. Apart from some differences (Conkeror uses the XULRunner backend) they're really pretty similar - and also, quite perfect, me has to add :) They fit perfectly into WMII. What I like the most is that they both have an "It's all text"-like behavior with their respective text editor. (21/02/2009: which can be overridden. I use Vimperator with Emacs as the external editor.)

Point is, you don't have to choose one over the other. Sure, both Emacs and Vim have a rather steep learning curve (that isn't so steep looking back, but still). But they aren't so steep as to limit you to either one. It's the classical example of the hammer-and-nails problem - just use the one that fits the job. Or, if you like, the one that doesn't hurt. I love Emacs, but nxhtml-mumamo just made me want to cry at times. Nope, I ain't biased, this is just my experience :)

Update 21/02/2009: I've been using Nxhtml-mumamo since originally publishing the post, and my opinion has changed. It's actually quite really good at what it does. Also, about using Vim and Emacs: there's viper-mode in Emacs, that lets you use vi-like keybindings for moving and editing inside Emacs - very useful. Vimpulse, although apparently abandoned at the moment, adds some nice Vim features.

Links (in no particular order)

Emacs home
Vim home
Vimperator
Conkeror