<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
#lang s-exp framework/keybinding-lang<br>
<br>
(define (get-frame obj)<br>
(cond<br>
[(is-a? obj editor<%>)<br>
(send (send obj get-canvas) get-top-level-window)]<br>
[else<br>
(send obj get-top-level-window)]))<br>
<br>
(keybinding "c:n" (λ (obj evt) (send (get-frame obj) open-in-new-tab #f)))<br></blockquote><div><br>that works! :) <br><br>For other people who might be interested in this, here are some others (on a frame%):<br>
(close-current-tab)<br>(on-tab-change from-tab to-tab)<br>(enable-evaluation)<br>(disable-evaluation)<br><br>(in PLT\collects\drscheme\private\unit.ss)<br>I guess the `on-tab-change' could be used to implement more flexible tab switching.<br>
</div><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
> I would especially like the "c:s:semicolon" to work...<br>
<br>
</div>I think you might just need the ?: prefix to make things work (see the<br>
docs for map-function for more on that). This is a messy area that<br>
needs to be cleaned up at some point, but one of the above should be<br>
made to work. I don't have a windows machine (or a french keyboard!)<br>
to try these things out so I'm kind of stuck on this one.<br></blockquote><div><br>Well, there remains a weird behavior: <br>the "?:c:s:semicolon" works fine in a little editor (see the bottom of this email), <br>
but when I use it in "mykeys.ss" for DrScheme, it does not work!<br><br>Same for (the 3 symbols are on the same key on a french layout):<br> ["$" ,(insert-string "$$$")]<br> ["?:s:$" ,(insert-string "£££")]<br>
["?:c:m:$" ,(insert-string "¤¤¤")]<br><br>These work in the little editor below, but not in DrScheme.<br>I suspect this is the same for many particular keys.<br>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 (?)).<br>
<br>I'm using DrScheme 4.2.3, not the SVN one, maybe this is also because of the menus (whose shortcuts I have disabled)?<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
> Also, reloading DrScheme for each test takes some time... isn't there a<br>
> faster way to test keybindings?<br>
<br>
</div>In the general case, no. Your keybindings can (and from what I can<br>
tell, people's often do) rely on all kinds of parts of drscheme's<br>
implementation. And if that's not loaded it can't run.<br>
<br>
You can, however, develop the implementation of your keybindings in a<br>
separate file and then just require that file into your keybindings<br>
file. For example, if your keybinding only depends on the core gui<br>
library, you can use this to help you build it:<br>
<br>
#lang scheme/gui<br>
<br>
(define (my-keybinding)<br>
(send t insert "hello!"))<br>
<br>
(define f (new frame% [label ""] [width 200] [height 200]))<br>
(define t (new text%))<br>
(define ec (new editor-canvas% [parent f] [editor t]))<br>
(define b (new button%<br>
[label "test keybinding"]<br>
[parent f]<br>
[callback (λ x (my-keybinding))]))<br>
(send ec focus)<br>
(send f show #t)<br>
<div class="im"><br></div></blockquote><div><br>Here is a modified version of the code above to also test actual keybindings:<br><br><div style="margin-left: 40px;">#lang scheme/gui<br><br>(define (km-keybinding keymap key fun)<br>
(if (string? fun)<br> (send keymap map-function key fun)<br> (let ([name (symbol->string (gensym))])<br> (send keymap add-function name fun)<br> (send keymap map-function key name))))<br><br>(define (insert-string str)<br>
(lambda (editor event)<br> (send editor insert str)))<br><br>(define f (new frame% [label "Keybinding tests"] [width 400] [height 200]))<br>(define t (new text%))<br>(define ec (new editor-canvas% [parent f] [editor t]))<br>
(define km (send t get-keymap))<br><br>; some tests (all positive) on a french keyboard layout:<br>(for-each <br> (λ(k-f)(apply km-keybinding km k-f))<br> `(["c:semicolon" ,(insert-string "uncommenting")]<br>
["?:c:s:semicolon" ,(insert-string "commenting out")] <br> ["c:_" ,(insert-string "λ")]<br> ["o" ,(insert-string "ooooo")]<br> ["$" ,(insert-string "$$$")]<br>
["?:s:$" ,(insert-string "£££")]<br>
["?:c:m:$" ,(insert-string "¤¤¤")]<br> ))<br> <br>(send ec focus)<br>(send f show #t)<br></div><br>There is probably a better way to do this, especially for the `km-keybinding' function.<br>
<br>Thanks again for the help,<br>Laurent<br><br> </div></div>