From 016e6d771c602a163603c9a7db42f25935a99517 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Mon, 17 Oct 2011 13:17:23 -0400 Subject: [PATCH] Add an example for old-style keys. --- .../scribblings/drracket/keybindings.scrbl | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/collects/scribblings/drracket/keybindings.scrbl b/collects/scribblings/drracket/keybindings.scrbl index 71bd454679..319b4f4c7a 100644 --- a/collects/scribblings/drracket/keybindings.scrbl +++ b/collects/scribblings/drracket/keybindings.scrbl @@ -229,6 +229,35 @@ s-exp framework/keybinding-lang (keybinding "c:a" (λ (editor evt) (send editor insert "!"))) ] +Since the file contains plain Racket code, you can write keybindings +files that use DrRacket's @seclink[#:doc '(lib +"scribblings/tools/tools.scrbl") "implementing-tools"]{Extension API}. +For example, the following file binds ``control-t'' and ``control-='' to +a execute the program and open a new tab respectively, as they were used +before version 5.2. + +@racketmod[ +s-exp framework/keybinding-lang + +(require drracket/tool-lib) + +(define-syntax-rule (frame-key key command) + (keybinding + (format "~a:~a" + (case (get-default-shortcut-prefix) + [(ctl) "c"] [(cmd) "d"] [(alt meta) "m"] + [(shift) "s"] [(option) "a"]) + key) + (λ (ed evt) + (when (is-a? ed text:basic<%>) + (define fr (send ed get-top-level-window)) + ;; note: fr could be #f + (when fr (send fr command)))))) + +(frame-key "t" execute-callback) +(frame-key "=" create-new-tab) +] + Another example, this file rebinds ``control-w'' to delete the word behind the insertion point, but it does it by setting a new key to be an existing keyboard shortcut. If you see a key in the