forked from agzam/spacehammer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammarly.fnl
52 lines (49 loc) · 2.08 KB
/
grammarly.fnl
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
;; somehow Grammarly doesn't let you easily copy or cut the text out of its
;; window. so I need to emulate a click event first.
(fn click-in-window []
(let [app (-> (hs.window.focusedWindow) (: :application))
win (: app :mainWindow)
frame (: win :frame)
{:_x x :_y y} frame
coords {:x (+ x 100) :y (+ y 100)}]
(: (hs.eventtap.event.newMouseEvent
hs.eventtap.event.types.leftMouseDown
coords) :post)
(: (hs.eventtap.event.newMouseEvent
hs.eventtap.event.types.leftMouseUp
coords) :post)))
(fn back-to-emacs [fsm]
(let [windows (require :windows)
run-str (.. "/usr/local/bin/emacsclient"
" -e "
"'(with-current-buffer (window-buffer (selected-window)) "
" (if (region-active-p)"
" (delete-region (region-beginning) (region-end))"
" (erase-buffer))"
" (clipboard-yank))" "'")
app (-> (hs.window.focusedWindow) (: :application))]
(click-in-window)
(: app :selectMenuItem [:Edit "Select All"])
(: app :selectMenuItem [:Edit :Cut])
(hs.timer.usleep 200000)
(io.popen run-str)
(hs.application.launchOrFocus :Emacs)
(: fsm :toIdle)))
(fn add-app-specific []
(let [keybindings (require :keybindings)]
(keybindings.add-app-specific
:Grammarly
{:launched (fn []
;; there's a bug, when new instance of Grammarly, doesn't
;; activate local modal key, unless rejiggered - de-focused
;; and activated again. Here I'm simply enforcing it
(let [keybindings (require :keybindings)]
(hs.timer.doAfter 2 keybindings.initialize-local-modals)))
:app-local-modal
(fn [self fsm]
(let [modal (require :modal)]
(: self :bind [:ctrl] :c (partial back-to-emacs fsm))
(: self :bind nil :escape (fn [] (: fsm :toIdle)))
(fn self.entered []
(modal.display-modal-text "C-c \t- return to Emacs"))))})))
{:add-app-specific add-app-specific}