[plt-scheme] keybinding and menus

From: Laurent (laurent.orseau at gmail.com)
Date: Wed Dec 2 09:43:13 EST 2009

> #lang s-exp framework/keybinding-lang
> (define (get-frame obj)
>  (cond
>    [(is-a? obj editor<%>)
>     (send (send obj get-canvas) get-top-level-window)]
>    [else
>     (send obj get-top-level-window)]))
> (keybinding "c:n" (λ (obj evt) (send (get-frame obj) open-in-new-tab #f)))

that works! :)

For other people who might be interested in this, here are some others (on a
(on-tab-change from-tab to-tab)

(in PLT\collects\drscheme\private\unit.ss)
I guess the `on-tab-change' could be used to implement more flexible tab

> > I would especially like the "c:s:semicolon" to work...
> I think you might just need the ?: prefix to make things work (see the
> docs for map-function for more on that). This is a messy area that
> needs to be cleaned up at some point, but one of the above should be
> made to work. I don't have a windows machine (or a french keyboard!)
> to try these things out so I'm kind of stuck on this one.

Well, there remains a weird behavior:
the "?:c:s:semicolon" works fine in a little editor (see the bottom of this
but when I use it in "mykeys.ss" for DrScheme, it does not work!

Same for (the 3 symbols are on the same key on a french layout):
   ["$" ,(insert-string "$$$")]
   ["?:s:$" ,(insert-string "£££")]
   ["?:c:m:$" ,(insert-string "¤¤¤")]

These work in the little editor below, but not in DrScheme.
I suspect this is the same for many particular keys.
I don't know if this behavior is particular to french keyboard or to foreign
ones, or if this occurs also on english keyboards (I guess not (?)).

I'm using DrScheme 4.2.3, not the SVN one, maybe this is also because of the
menus (whose shortcuts I have disabled)?

> > Also, reloading DrScheme for each test takes some time... isn't there a
> > faster way to test keybindings?
> In the general case, no. Your keybindings can (and from what I can
> tell, people's often do) rely on all kinds of parts of drscheme's
> implementation. And if that's not loaded it can't run.
> You can, however, develop the implementation of your keybindings in a
> separate file and then just require that file into your keybindings
> file. For example, if your keybinding only depends on the core gui
> library, you can use this to help you build it:
> #lang scheme/gui
> (define (my-keybinding)
>  (send t insert "hello!"))
> (define f (new frame% [label ""] [width 200] [height 200]))
> (define t (new text%))
> (define ec (new editor-canvas% [parent f] [editor t]))
> (define b (new button%
>               [label "test keybinding"]
>               [parent f]
>               [callback (λ x (my-keybinding))]))
> (send ec focus)
> (send f show #t)
Here is a modified version of the code above to also test actual

#lang scheme/gui

(define (km-keybinding keymap key fun)
  (if (string? fun)
      (send keymap map-function key fun)
      (let ([name (symbol->string (gensym))])
        (send keymap add-function name fun)
        (send keymap map-function key name))))

(define (insert-string str)
  (lambda (editor event)
    (send editor insert str)))

(define f (new frame% [label "Keybinding tests"] [width 400] [height 200]))
(define t (new text%))
(define ec (new editor-canvas% [parent f] [editor t]))
(define km (send t get-keymap))

; some tests (all positive) on a french keyboard layout:
 (λ(k-f)(apply km-keybinding km k-f))
 `(["c:semicolon" ,(insert-string "uncommenting")]
   ["?:c:s:semicolon" ,(insert-string "commenting out")]
   ["c:_" ,(insert-string "λ")]
   ["o" ,(insert-string "ooooo")]
   ["$" ,(insert-string "$$$")]
   ["?:s:$" ,(insert-string "£££")]
   ["?:c:m:$" ,(insert-string "¤¤¤")]

(send ec focus)
(send f show #t)

There is probably a better way to do this, especially for the
`km-keybinding' function.

Thanks again for the help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091202/864a7178/attachment.html>

Posted on the users mailing list.