forked from facebook/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow-types.el
126 lines (110 loc) · 3.03 KB
/
flow-types.el
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(setq flow_binary "flow")
(defun column-number-at-pos (pos)
"column number at pos"
(save-excursion (goto-char pos) (current-column))
)
(defun string-of-region ()
"string of region"
(if (use-region-p)
(let ((begin (region-beginning))
(end (region-end)))
(format ":%d:%d,%d:%d"
(line-number-at-pos begin)
(column-number-at-pos begin)
(line-number-at-pos end)
(column-number-at-pos end)))
"")
)
(defun get-assoc-value (key alist)
"get assoc value"
(setq blah (assoc key alist))
(if blah
(cdr blah)
nil)
)
(setq flow_root_dir nil)
(defun flow_init (s)
"Initialize flow"
(interactive "sRoot directory: ")
(setq flow_root_dir s)
(shell-command (format "%s start %s" flow_binary s))
(compile (format "%s status --from emacs; exit 0" flow_binary))
)
;;(setq compilation-scroll-output t)
(global-set-key "\C-c\C-c" 'flow_init)
(defun show-type ()
"show type"
(interactive)
(let ((file (buffer-file-name))
(line (line-number-at-pos))
(col (current-column))
(buffer (current-buffer)))
(switch-to-buffer-other-window "*Shell Command Output*")
(shell-command
(format "%s type-at-pos %s %d %d"
flow_binary
file
line
(1+ col)))
(compilation-mode)
(switch-to-buffer-other-window buffer))
)
(global-set-key (kbd "M-t") 'show-type)
(defun fill-types ()
"fill types"
(interactive)
(let ((file (buffer-file-name))
(region (string-of-region))
(buffer (current-buffer)))
(switch-to-buffer-other-window "*Shell Command Output*")
(shell-command
(format "%s suggest %s%s"
flow_binary
file
region))
(compilation-mode)
(switch-to-buffer-other-window buffer))
;;(revert-buffer)
)
(global-set-key (kbd "C-t") 'fill-types)
(defun jump-def ()
"jump to definition"
(interactive)
(let ((file (buffer-file-name))
(line (line-number-at-pos))
(col (current-column))
(buffer (current-buffer)))
(switch-to-buffer-other-window "*Shell Command Output*")
(shell-command
(format "%s get-def --from emacs %s %d %d"
flow_binary
file
line
(1+ col)))
(compilation-mode))
;;(switch-to-buffer-other-window buffer)
)
(global-set-key "\C-x\C-l" 'jump-def)
(defun auto-complete ()
"autocomplete"
(interactive)
(let ((file (buffer-file-name))
(line (line-number-at-pos))
(col (current-column))
(buffer (current-buffer)))
(switch-to-buffer-other-window "*Shell Command Output*")
(shell-command
(format "%s autocomplete %s %d %d < %s"
flow_binary
file
line
(1+ col)
file))
(compilation-mode)
(switch-to-buffer-other-window buffer))
)
(global-set-key (kbd "C-l") 'auto-complete)
(add-hook 'kill-emacs-hook
(lambda ()
(if flow_root_dir
(shell-command (format "%s stop %s" flow_binary flow_root_dir)))))