New keybinding parser

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. Enjoy! -Brent

byorgey:
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.
Enjoy!
This is a great idea. Good work Brent! -- Don

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

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.

Spencer Janssen wrote:
On Tue, Feb 26, 2008 at 06:05:00PM -0500, David Roundy 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
On Tue, Feb 26, 2008 at 05:39:23PM -0500, Brent Yorgey wrote: 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 shepheb

* Braden Shepherdson
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.
This was possible before, using XMonad.Actions.Submap. As Brent said, he just wrote keybindings parser (i.e. introduced convenient emacs-style syntax). BTW, last night on IRC I saw several emacs users discussing impossibility of redefining keys in vi (I guess that discussion was related to this patch). I had no time to response then, but yes, in Vim (current de-facto standard implementation of vi) user can (re-)define keybindings, including even different bindings for different modes. -- Roman I. Cheplyaka (aka Feuerbach @ IRC)

On Feb 27, 2008, at 0:04 , Roman Cheplyaka wrote:
BTW, last night on IRC I saw several emacs users discussing impossibility of redefining keys in vi (I guess that discussion was related to this patch).
As someone who uses both: nonsense. Only the very earliest UC Berkeley CSRG releases of the original vi lacked ":map!". -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

allbery:
On Feb 27, 2008, at 0:04 , Roman Cheplyaka wrote:
BTW, last night on IRC I saw several emacs users discussing impossibility of redefining keys in vi (I guess that discussion was related to this patch).
As someone who uses both: nonsense. Only the very earliest UC Berkeley CSRG releases of the original vi lacked ":map!".
Even yi 0.0 supported :map :)

On Feb 27, 2008, at 0:26 , Don Stewart wrote:
allbery:
On Feb 27, 2008, at 0:04 , Roman Cheplyaka wrote:
BTW, last night on IRC I saw several emacs users discussing impossibility of redefining keys in vi (I guess that discussion was related to this patch).
As someone who uses both: nonsense. Only the very earliest UC Berkeley CSRG releases of the original vi lacked ":map!".
Even yi 0.0 supported :map
Hm, right, braino, :map was vi commands, :map! input mode substitutions. (I was originally misremembering :map as ex-mode. Bad brain day.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Tue, Feb 26, 2008 at 11:16 PM, Braden Shepherdson < Braden.Shepherdson@gmail.com> wrote:
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.
Yup, this was possible before, as Roman pointed out -- indeed, the keybinding parser uses XMonad.Actions.Submap under the hood -- but now it's super-easy. In fact, after switching all my keybindings over, I went and changed a bunch of them into submaps -- I have a lot of keybindings, so it's a lot nicer with submaps (easier to remember, too), but I hadn't bothered before since it would have been more of a pain to change. For anyone else reading who'd like to try this out, I just uploaded my current xmonad.hshttp://haskell.org/haskellwiki/Xmonad/Config_archive/Brent_Yorgey%27s_darcs_...to the wiki which you can use as an example. Looks like oxymor00n has done the samehttp://haskell.org/haskellwiki/Xmonad/Config_archive/oxymor00n%27s_xmonad.hs . -Brent

On Tue, Feb 26, 2008 at 6:05 PM, David Roundy
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.
Well, you're right that it is more elegant, of course. It does add some safety, but I'm not sure how valuable that safety is, especially since keybindings are one of those things that you mostly leave alone after initially setting them up. I also included a function to check the validity of your keybindings on startup (popping up a little warning message if any parse failures or duplicates are detected) for exactly this reason. So in the end, for me personally at least, the added safety in exchange for having to write extra syntax ($ and &&& or whatever everywhere) is not a good trade-off. That's just my opinion though -- if someone else wants to write an extension implementing David's suggestion as another keybinding alternative, awesome. Mine is not necessarily the end-all be-all of keybinding specifications. =) -Brent
participants (7)
-
Braden Shepherdson
-
Brandon S. Allbery KF8NH
-
Brent Yorgey
-
David Roundy
-
Don Stewart
-
Roman Cheplyaka
-
Spencer Janssen