forked from facebook/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow-types.el
68 lines (59 loc) · 1.67 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
(setq flow_binary "$TOPDIR/facebook/flow/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 flow_status (s)
"Run flow"
(interactive "sRoot directory: ")
(compile (format "%s status %s --from emacs; exit 0" flow_binary s))
)
;;(setq compilation-scroll-output t)
(global-set-key "\C-c\C-c" 'flow_status)
(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
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)