[plt-scheme] Keybindings in DrScheme: (keybinding "F9" ???)

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Mon Mar 26 17:56:15 EDT 2007

> I'm trying to set a few of my own keybindings, but I'm not running 
> across any documentation that I.  I realize that the keybinding function 
> takes as its second argument a lambda that takes an editor and an event. 
> But beyond that I'm unsure what the second argument should be.

Hi Ethan,

That second argument is the function that gets called when the button is 
pressed.  That function takes in the keystroke, as well as the "editor" 
object: we're expected to call the right methods on editors.

Editors have a set of methods, which we can see here:


> What I want to do is map put-previous-sexp and put-next-sexp to a couple 
> of keys.  I think put-previous-sexp is a function, is this so?  It's 
> that is currently mapped to the ESC-p chord.

[code cut]

There must be an easier way to do this, but here's something that should 
help you get started:

(module ethan-keybindings (lib "keybinding-lang.ss" "framework")
   (keybinding "f8"
               (lambda (editor event)
                 (send (send editor get-keymap)
                       "put-previous-sexp" editor event #t))))

the thing is that put-previous-sexp is the name of a function in the 
keymap of the editor --- there's one level of indirection here --- so the 
code first asks the editor for the keymap.  That's where the GET-KEYMAP 
stuff comes in:


Once we have the keymap, then we can start calling functions like 
"put-previous-sexp" or "put-next-sexp" that you saw in the active 
keybindings list.

Best of wishes!

Posted on the users mailing list.