-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkeybindings.rkt
71 lines (64 loc) · 2.05 KB
/
keybindings.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;;
;; **************************************************************
;; Copyright (c) 2020
;; Raymond Li <racket@raymond.li>
;; Kaustubh Prabhakar <kaustubh3973@gmail.com>
;; Keybindings for DrRacket
;; Last updated 2020-09-19
;; Modified from Racket documentation
;; **************************************************************
;;
#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 menu-evt
(new control-event%
[event-type 'menu]
[time-stamp
(send evt get-time-stamp)]))
(send item command menu-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])))
(define (rebind key command)
(keybinding
key
(λ (ed evt)
(send (send ed get-keymap) call-function
command ed evt #t))))
(menu-bind "m:r" "Run")
(menu-bind ":?:s:c:F" "Reindent All")
(menu-bind "c:h" "Show Replace")
(menu-bind ":?:s:c:R" "Replace All")
(menu-bind "c:/" "Comment Out with Semicolons")
(rebind "c:backspace" "backward-kill-word")
(rebind "c:del" "kill-word")
(rebind "m:up" "shift-focus")
(rebind "m:down" "shift-focus")
;(rebind "up" "put-previous-sexp")
;(rebind "down" "put-next-sexp")