-
Notifications
You must be signed in to change notification settings - Fork 6
/
commands_util.ahk
97 lines (86 loc) · 2.32 KB
/
commands_util.ahk
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
;; This script provides: command skeletons
;; <function>
;; command_simple(str, [causechange 0], [repeatable 0])
;; ... send string as a command (when causechange is t, call after_change_hook)
;; command_motion(str, [repeatable 0])
;; ... send string as a command that can expand the region
;; -----------------
;; command skeletons
;; -----------------
;; command_str(str, moves = 0, changes = 0, repeatable = 0, prestr = "", poststr = "")
;; { Global
;; Local sendstr = make_str(str, (arg && repeatable) ? arg 1)
;; If (moves && mark)
;; sendstr = {shift down}%sendstr%{shift up}
;; run_hooks("pre_command_hook")
;; send(sendstr)
;; run_hooks("post_command_hook")
;; }
;; command_function(fnname, changes = 0, repeatable = 0)
;; { Global
;; run_hooks("pre_command_hook")
;; Loop, % (arg && repeatable) ? arg : 1
;; funcall(fnname)
;; If changes
;; run_hooks("after_change_hook")
;; run_hooks("post_command_hook")
;; }
;; command that simply sends a key or calls a function
;; WILL BE OBSOLETE
command_simple(str, changes, repeatable)
{ Global
run_hooks("pre_command_hook")
If isFunc(str)
Loop, % (arg && repeatable) ? arg : 1
%str%()
Else
Loop, % (arg && repeatable) ? arg : 1
send(str)
If changes
run_hooks("after_change_hook")
run_hooks("post_command_hook")
}
;; a command that moves cursor position
;; WILL BE OBSOLETE
command_motion(str, repeatable)
{ Global
run_hooks("pre_command_hook")
If mark
str = {shift down}%str%{shift up}
Loop, % (arg && repeatable) ? arg : 1
send(str)
run_hooks("post_command_hook")
}
;; WILL BE OBSOLETE
command_abc(a, b, c, change)
{ Global
run_hooks("pre_command_hook")
send(a)
Loop, % arg ? arg : 1
send(b)
send(c)
If change
run_hooks("after_change_hook")
run_hooks("post_command_hook")
}
;; command that inserts a balanced expression
command_pair(str)
{ Global
run_hooks("pre_command_hook")
If mark
send("^x")
Loop, % arg ? arg : 1
send(str)
If mark
send("^v")
run_hooks("after_change_hook")
run_hooks("post_command_hook")
}
;; command that selects something
command_mark(str)
{
run_hooks("pre_command_hook")
send(str)
set_mark()
run_hooks("post_command_hook")
}