-
Notifications
You must be signed in to change notification settings - Fork 3
/
macro.go
62 lines (53 loc) · 1.25 KB
/
macro.go
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
package main
import glisp "github.com/glycerine/zygomys/zygo"
type EditorAction struct {
HasUniversal bool
Universal int
Command *CommandFunc
}
type EditorMacro []*EditorAction
var macro EditorMacro
var macrorec bool = false
func runMacroOnce(env *glisp.Zlisp, m []*EditorAction) {
if m == nil || len(m) <= 0 {
Global.Input = "Zero length or unset macro"
return
}
for _, act := range m {
if act != nil && act.Command != nil && act.Command.Com != nil {
Global.Universal = act.Universal
Global.SetUniversal = act.HasUniversal
act.Command.Com(env)
Global.SetUniversal = false
}
}
}
func micromode(repeatkey string, msg string, env *glisp.Zlisp, f func(*glisp.Zlisp)) {
f(env)
Global.Input = msg
editorRefreshScreen()
key := editorGetKey()
for key == repeatkey {
f(env)
editorRefreshScreen()
key = editorGetKey()
}
Global.SetUniversal = false
RunCommandForKey(key, env)
editorRefreshScreen()
}
func doRunMacro(env *glisp.Zlisp) {
stopRecMacro()
micromode("e", "Press e to run macro again", env, func(e *glisp.Zlisp) {
runMacroOnce(e, macro)
})
}
func recMacro() {
macrorec = true
macro = EditorMacro{}
Global.Input = "Recording macro..."
}
func stopRecMacro() {
macrorec = false
Global.Input = "Stopped recording"
}