[plt-scheme] Keybindings in DrScheme: (keybinding "F9" ???)
> 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:
http://download.plt-scheme.org/doc/360/html/mred/mred-Z-H-639.html#node_sec_9.3
> 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)
call-function
"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:
http://download.plt-scheme.org/doc/360/html/mred/mred-Z-H-680.html#node_tag_Temp_681
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!