[racket] Custom Key Bindings - Post Your File
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.
(define menu-evt
(new control-event%
[event-type 'menu]
[time-stamp
(send evt get-time-stamp)])) ;; evt passed in
(send item command menu-evt)))))))
Thanks for extending the doc, I'm re-reading the keybindings stuff in its
entirety.
On Fri, May 11, 2012 at 8:14 AM, Robby Findler
<robby at eecs.northwestern.edu>wrote:
> Ah, good point. I've added some example code to the docs that shows
> how to bind menu items. Here's the code.
>
> Robby
>
> #lang s-exp framework/keybinding-lang
>
> (define (menu-bind key menu-item)
> (keybinding
> key
> (λ (ed evt)
> (define canvas (send ed get-canvas))
> (when canvas
> (define menu-bar (find-menu-bar canvas))
> (when menu-bar
> (define item (find-item menu-bar menu-item))
> (when item
> (define evt
> (new control-event%
> [event-type 'menu]
> [time-stamp
> (send evt get-time-stamp)]))
> (send item command evt)))))))
>
> (define/contract (find-menu-bar c)
> (-> (is-a?/c area<%>) (or/c #f (is-a?/c menu-bar%)))
> (let loop ([c c])
> (cond
> [(is-a? c frame%) (send c get-menu-bar)]
> [(is-a? c area<%>) (loop (send c get-parent))]
> [else #f])))
>
> (define/contract (find-item menu-bar label)
> (-> (is-a?/c menu-bar%)
> string?
> (or/c (is-a?/c selectable-menu-item<%>) #f))
> (let loop ([o menu-bar])
> (cond
> [(is-a? o selectable-menu-item<%>)
> (and (equal? (send o get-plain-label) label)
> o)]
> [(is-a? o menu-item-container<%>)
> (for/or ([i (in-list (send o get-items))])
> (loop i))]
> [else #f])))
>
> (menu-bind "c:a" "Run")
>
>
> On Thu, May 10, 2012 at 8:22 PM, Ray Racine <ray.racine at gmail.com> wrote:
> > I'm caught in a bit of Catch-22. From the doc.
> >
> > If you are most familiar with Emacs-style key bindings (especially on
> > windows or some linux installations where the control key is, by default,
> > for the menu shortcuts), you should uncheck the Enable keybindings in
> > menus preference. Many of the keybindings below are inspired by Emacs.
> >
> > So I've disabled keybindings in menu and thereby lose crtl-r Run and
> crtl-i
> > Reindent. I'd like to re-bind but I've as of yet been unable to locate
> what
> > functions Run and Reindent correspond to.
> >
> > I totally missed the online check syntax option, which sounds like a very
> > good thing. In fact I'm still totally missing it. :) I just rechecked
> the
> > menus/preferences. Where is this mythic option found?
> >
> > Thanks
> >
> >
> > On Thu, May 10, 2012 at 8:49 PM, Robby Findler <
> robby at eecs.northwestern.edu>
> > wrote:
> >>
> >> FWIW, run and reindent are already menu-key based shortcuts (r and i
> >> respectively) so they should be available already (unless you're on
> >> windows and you've disabled menu keyboard shortcuts). For reindent you
> >> can hit tab, and DrRacket re-indents the line you're on or the
> >> selection (if it is more than one line). For check syntax, I recommend
> >> you enable online check syntax and then you don't have to hit any key
> >> at all to get that to work.
> >>
> >> hth,
> >> Robby
> >>
> >> On Thu, May 10, 2012 at 6:38 PM, Ray Racine <ray.racine at gmail.com>
> wrote:
> >> > I'm attempting this weekend to make the leap from my beloved Emacs and
> >> > Geiser to DrRacket. Was wondering if anyone has a cool set of
> custom
> >> > keybindings they'd like to share.
> >> >
> >> > Some I'd like to get my hands on are:
> >> > 1. binding for reindent / reindent all.
> >> > 2. binding for Check Syntax button equivalent.
> >> > 3. binding for Run button equivalent.
> >> >
> >> > Three below I just pieced together.
> >> >
> >> > ;; insert λ
> >> > (keybinding "c:\\" (λ (editor evt) (send editor insert "λ")))
> >> >
> >> > ;; close
> >> > (keybinding "c:q" (λ (editor evt)
> >> > (send (send editor get-top-level-window)
> >> > close-current-tab)))
> >> >
> >> > ;; open a new tab
> >> > (keybinding "c:t" (λ (editor evt) (send (send editor
> >> > get-top-level-window)
> >> > create-new-tab))
> >> >
> >> > ____________________
> >> > Racket Users list:
> >> > http://lists.racket-lang.org/users
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120512/93874dd1/attachment.html>