Thanks. It makes it really easy to re-use any existing menu options with custom keybindings. There was a minor bug on the internal define of the new event shadowing the passed in evt. As a result the get-time-stamp message was failing with an undefined object in the send. I renamed it menu-evt below.<br>
<br> (define menu-evt<br>
(new control-event%<br>
[event-type 'menu]<br>
[time-stamp<br>
(send evt get-time-stamp)])) ;; evt passed in<br>
(send item command menu-evt)))))))<br><br>
Thanks for extending the doc, I'm re-reading the keybindings stuff in its entirety.<br><br><div class="gmail_quote">On Fri, May 11, 2012 at 8:14 AM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ah, good point. I've added some example code to the docs that shows<br>
how to bind menu items. Here's the code.<br>
<br>
Robby<br>
<br>
#lang s-exp framework/keybinding-lang<br>
<br>
(define (menu-bind key menu-item)<br>
(keybinding<br>
key<br>
(ë (ed evt)<br>
(define canvas (send ed get-canvas))<br>
(when canvas<br>
(define menu-bar (find-menu-bar canvas))<br>
(when menu-bar<br>
(define item (find-item menu-bar menu-item))<br>
(when item<br>
(define evt<br>
(new control-event%<br>
[event-type 'menu]<br>
[time-stamp<br>
(send evt get-time-stamp)]))<br>
(send item command evt)))))))<br>
<br>
(define/contract (find-menu-bar c)<br>
(-> (is-a?/c area<%>) (or/c #f (is-a?/c menu-bar%)))<br>
(let loop ([c c])<br>
(cond<br>
[(is-a? c frame%) (send c get-menu-bar)]<br>
[(is-a? c area<%>) (loop (send c get-parent))]<br>
[else #f])))<br>
<br>
(define/contract (find-item menu-bar label)<br>
(-> (is-a?/c menu-bar%)<br>
string?<br>
(or/c (is-a?/c selectable-menu-item<%>) #f))<br>
(let loop ([o menu-bar])<br>
(cond<br>
[(is-a? o selectable-menu-item<%>)<br>
(and (equal? (send o get-plain-label) label)<br>
o)]<br>
[(is-a? o menu-item-container<%>)<br>
(for/or ([i (in-list (send o get-items))])<br>
(loop i))]<br>
[else #f])))<br>
<br>
(menu-bind "c:a" "Run")<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, May 10, 2012 at 8:22 PM, Ray Racine <<a href="mailto:ray.racine@gmail.com">ray.racine@gmail.com</a>> wrote:<br>
> I'm caught in a bit of Catch-22. From the doc.<br>
><br>
> If you are most familiar with Emacs-style key bindings (especially on<br>
> windows or some linux installations where the control key is, by default,<br>
> for the menu shortcuts), you should uncheck the Enable keybindings in<br>
> menus preference. Many of the keybindings below are inspired by Emacs.<br>
><br>
> So I've disabled keybindings in menu and thereby lose crtl-r Run and crtl-i<br>
> Reindent. I'd like to re-bind but I've as of yet been unable to locate what<br>
> functions Run and Reindent correspond to.<br>
><br>
> I totally missed the online check syntax option, which sounds like a very<br>
> good thing. In fact I'm still totally missing it. :) I just rechecked the<br>
> menus/preferences. Where is this mythic option found?<br>
><br>
> Thanks<br>
><br>
><br>
> On Thu, May 10, 2012 at 8:49 PM, Robby Findler <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>><br>
> wrote:<br>
>><br>
>> FWIW, run and reindent are already menu-key based shortcuts (r and i<br>
>> respectively) so they should be available already (unless you're on<br>
>> windows and you've disabled menu keyboard shortcuts). For reindent you<br>
>> can hit tab, and DrRacket re-indents the line you're on or the<br>
>> selection (if it is more than one line). For check syntax, I recommend<br>
>> you enable online check syntax and then you don't have to hit any key<br>
>> at all to get that to work.<br>
>><br>
>> hth,<br>
>> Robby<br>
>><br>
>> On Thu, May 10, 2012 at 6:38 PM, Ray Racine <<a href="mailto:ray.racine@gmail.com">ray.racine@gmail.com</a>> wrote:<br>
>> > I'm attempting this weekend to make the leap from my beloved Emacs and<br>
>> > Geiser to DrRacket. Was wondering if anyone has a cool set of custom<br>
>> > keybindings they'd like to share.<br>
>> ><br>
>> > Some I'd like to get my hands on are:<br>
>> > 1. binding for reindent / reindent all.<br>
>> > 2. binding for Check Syntax button equivalent.<br>
>> > 3. binding for Run button equivalent.<br>
>> ><br>
>> > Three below I just pieced together.<br>
>> ><br>
>> > ;; insert ë<br>
>> > (keybinding "c:\\" (ë (editor evt) (send editor insert "ë")))<br>
>> ><br>
>> > ;; close<br>
>> > (keybinding "c:q" (ë (editor evt)<br>
>> > (send (send editor get-top-level-window)<br>
>> > close-current-tab)))<br>
>> ><br>
>> > ;; open a new tab<br>
>> > (keybinding "c:t" (ë (editor evt) (send (send editor<br>
>> > get-top-level-window)<br>
>> > create-new-tab))<br>
>> ><br>
>> > ____________________<br>
>> > Racket Users list:<br>
>> > <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>