[xmonad] Re: New keybinding parser

Braden Shepherdson Braden.Shepherdson at gmail.com
Tue Feb 26 23:16:24 EST 2008

Spencer Janssen wrote:
> On Tue, Feb 26, 2008 at 06:05:00PM -0500, David Roundy wrote:
>> On Tue, Feb 26, 2008 at 05:39:23PM -0500, Brent Yorgey wrote:
>>> Hi all,
>>> I've just pushed (what I hope is) an exciting patch to XMonad.Util.EZConfig.
>>> It now exports a bunch of functions for parsing keybindings, emacs-style.
>>> That's right, instead of typing
>>>   ((modMask x .|. shiftMask .|. controlMask, xK_F12), action)
>>> or other such boilerplate drudgery, you can now just say
>>>   ("M-S-C-<F12>", action).
>>> Submaps are also supported -- just do something like
>>>   ("M-x p", action1)
>>>   ("M-x q", action2)
>>> and it does the right thing.  Detailed documentation is included, so look
>>> there for a more thorough explanation and examples.  As always, comments,
>>> bug reports, and patches welcome.
>> This sounds nice, but I can't help but wonder if we can't do one up, and
>> provide our users with a handy interface that doesn't allow them to run
>> into run-time parse errors.  Something like
>>   (m 'q', action0)
>>   (m $ s $ c f12, action1)
>>   (m $ s $ c 'x', action2)
>> should be trivial to implement (albeit eating up the namespace rather
>> ferociously), and would give a bit more safety with only a
>> slightly-less-pretty syntax.  Submaps would require a bit more syntax, but
>> something like
>>   (m x &&& 'q')
>> should be implementable.  I'm not sure if this would be deemed worthwhile,
>> but it seems to me a bit more elegant than parsing strings into key
>> bindings.
>> David
> Of course the character literals can still cause parse failure at runtime.

One handy use of this that occurred to me (I'm not sure if this is 
possible under the original system) is to have "namespaces" of sorts. I 
wanted to add a bunch of "execute this app" (or maybe runOrRaise) key 
bindings, but a lot of keys were taken when just using mod and 
mod+shift. Now I can use
M-x f   for Firefox
M-x t   for Thunderbird
M-x p   for Pidgin
and so on. I think of this as using M-x as a namespace for execute, and 
then I have all 26 letters and all 10 numbers free to launch whatever 
apps I like.

This could also see use for people with tons of workspaces:
M-0 1 -- the tenth workspace
M-0 2 -- the eleventh
M-0 9 -- the eighteenth
and even a second "digit"
M-0 0 1 -- the nineteenth
all the way to
M-0 0 0 0 8 -- who cares what number this one is.
and so on.

An awesome patch, byorgey, many thanks!

Braden Shepherdson

More information about the xmonad mailing list