-
Notifications
You must be signed in to change notification settings - Fork 30
/
tool.rkt
97 lines (79 loc) · 3.18 KB
/
tool.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#lang racket/unit
(require drracket/tool
framework
racket/class
racket/gui
"private/text.rkt")
(import drracket:tool^)
(export drracket:tool-exports^)
(define vim-frame-mixin
(mixin (drracket:unit:frame<%>) ()
(unless (preferences:default-set? 'drracket:vim-emulation?)
(preferences:set-default 'drracket:vim-emulation? #f boolean?))
(define vim-emulation?
(preferences:get 'drracket:vim-emulation?))
(define/public (vim?) vim-emulation?)
(define/private (toggle-vim!)
(preferences:set 'drracket:vim-emulation? (not vim-emulation?))
(set! vim-emulation? (not vim-emulation?))
(when (not vim-emulation?)
(send (get-definitions-text) turn-off-vim-effects!)
(send (get-interactions-text) turn-off-vim-effects!))
;; trigger redraws to get rid of vim effects
(send (get-definitions-text) invalidate-bitmap-cache)
(send (get-interactions-text) invalidate-bitmap-cache))
(inherit get-definitions-text
get-interactions-text)
(define/override (edit-menu:between-find-and-preferences edit-menu)
(super edit-menu:between-find-and-preferences edit-menu)
(new checkable-menu-item%
[label "Vim Mode"]
[parent edit-menu]
[callback (λ (i e) (toggle-vim!))]
[checked (vim?)]))
;; for the vim status (mode text, etc.)
;; TODO: this pattern is really horrible
(define vim-status-parent-panel 'uninitialized)
(define vim-status-panel 'uninitialized)
(define vim-status-message 'uninitialized)
;; overriden to add a status panel
(define/override (make-root-area-container cls parent)
(set! vim-status-parent-panel
(super make-root-area-container vertical-panel% parent))
(define root (new cls [parent vim-status-parent-panel]))
(set! vim-status-panel
(new horizontal-panel%
[style '(border)]
[stretchable-height #f]
[parent vim-status-parent-panel]))
(set! vim-status-message
(new message%
[parent vim-status-panel]
[auto-resize #t]
[label ""]))
root)
(define/public (set-vim-status-message str)
(send vim-status-message set-label str))
(super-new)))
(define vim-tab-mixin
(λ (cls)
(class cls
(define initialized? #f)
(inherit get-frame get-ints get-defs)
(super-new)
;; overriden just to inform us when the tab becomes active
(define/override (enable-evaluation)
(super enable-evaluation)
(unless initialized?
;; initialize editor state
(set-field! parent-frame (get-defs) (get-frame))
(set-field! parent-frame (get-ints) (get-frame))
(send (get-defs) on-initialization)
(set! initialized? #t))))))
(define (phase1) (void))
(define (phase2) (void))
(preferences:set-default 'drracket:vim-emulation? #f boolean?)
(drracket:get/extend:extend-definitions-text vim-emulation-mixin)
(drracket:get/extend:extend-interactions-text vim-emulation-mixin)
(drracket:get/extend:extend-unit-frame vim-frame-mixin)
(drracket:get/extend:extend-tab vim-tab-mixin)