forked from govim/govim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
201 lines (166 loc) · 5.4 KB
/
command.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package govim
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
type CommandFlags struct {
Line1 *int
Line2 *int
Range *int
Count *int
Bang *bool
Reg *string
Mods CommModList
}
func (c *CommandFlags) UnmarshalJSON(b []byte) error {
var v struct {
Line1 *int `json:"line1"`
Line2 *int `json:"line2"`
Range *int `json:"range"`
Count *int `json:"count"`
Bang *string `json:"bang"`
Reg *string `json:"reg"`
Mods string `json:"mods"`
}
if err := json.Unmarshal(b, &v); err != nil {
return err
}
c.Line1 = v.Line1
c.Line2 = v.Line2
c.Range = v.Range
c.Count = v.Count
if v.Bang != nil {
b := *v.Bang == "!"
c.Bang = &b
}
for _, v := range strings.Fields(v.Mods) {
cm := CommMod(v)
switch cm {
case CommModAboveLeft, CommModBelowRight, CommModBotRight, CommModBrowse, CommModConfirm,
CommModHide, CommModKeepAlt, CommModKeepJumps, CommModKeepMarks, CommModKeepPatterns,
CommModLeftAbove, CommModLockMarks, CommModNoSwapfile, CommModRightBelow, CommModSilent,
CommModTab, CommModTopLeft, CommModVerbose, CommModVertical:
default:
return fmt.Errorf("unknown CommMod %q", cm)
}
c.Mods = append(c.Mods, cm)
}
return nil
}
type CommModList []CommMod
func (c CommModList) String() string {
var vals []string
for _, cc := range c {
vals = append(vals, string(cc))
}
return strings.Join(vals, " ")
}
type CommMod string
const (
CommModAboveLeft CommMod = "aboveleft"
CommModBelowRight CommMod = "belowright"
CommModBotRight CommMod = "botright"
CommModBrowse CommMod = "browse"
CommModConfirm CommMod = "confirm"
CommModHide CommMod = "hide"
CommModKeepAlt CommMod = "keepalt"
CommModKeepJumps CommMod = "keepjumps"
CommModKeepMarks CommMod = "keepmarks"
CommModKeepPatterns CommMod = "keeppatterns"
CommModLeftAbove CommMod = "leftabove"
CommModLockMarks CommMod = "lockmarks"
CommModNoSwapfile CommMod = "noswapfile"
CommModRightBelow CommMod = "rightbelow"
CommModSilent CommMod = "silent"
CommModTab CommMod = "tab"
CommModTopLeft CommMod = "topleft"
CommModVerbose CommMod = "verbose"
CommModVertical CommMod = "vertical"
)
type CommAttr interface {
fmt.Stringer
isCommAttr()
}
type GenAttr uint
func (g GenAttr) isCommAttr() {}
const (
AttrBang GenAttr = iota // -bang
AttrBar // -bar
AttrRegister // -register
AttrBuffer // -buffer
)
type Complete uint
func (c Complete) isCommAttr() {}
const (
CompleteArglist Complete = iota // -complete=arglist
CompleteAugroup // -complete=augroup
CompleteBuffer // -complete=buffer
CompleteBehave // -complete=behave
CompleteColor // -complete=color
CompleteCommand // -complete=command
CompleteCompiler // -complete=compiler
CompleteCscope // -complete=cscope
CompleteDir // -complete=dir
CompleteEnvironment // -complete=environment
CompleteEvent // -complete=event
CompleteExpression // -complete=expression
CompleteFile // -complete=file
CompleteFileInPath // -complete=file_in_path
CompleteFiletype // -complete=filetype
CompleteFunction // -complete=function
CompleteHelp // -complete=help
CompleteHighlight // -complete=highlight
CompleteHistory // -complete=history
CompleteLocale // -complete=locale
CompleteMapclear // -complete=mapclear
CompleteMapping // -complete=mapping
CompleteMenu // -complete=menu
CompleteMessages // -complete=messages
CompleteOption // -complete=option
CompletePackadd // -complete=packadd
CompleteShellCmd // -complete=shellcmd
CompleteSign // -complete=sign
CompleteSyntax // -complete=syntax
CompleteSyntime // -complete=syntime
CompleteTag // -complete=tag
CompleteTagListFiles // -complete=tag_listfiles
CompleteUser // -complete=user
CompleteVar // -complete=var
)
type CompleteCustom string
func (c CompleteCustom) isCommAttr() {}
func (c CompleteCustom) String() string {
return "-complete=custom," + string(c)
}
type CompleteCustomList string
func (c CompleteCustomList) isCommAttr() {}
func (c CompleteCustomList) String() string {
return "-complete=customlist," + string(c)
}
type RangeN int
func (r RangeN) isCommAttr() {}
func (r RangeN) String() string {
return strconv.Itoa(int(r))
}
type CountN int
func (c CountN) isCommAttr() {}
func (c CountN) String() string {
return fmt.Sprintf("-count=%v", int(c))
}
type Range uint
func (r Range) isCommAttr() {}
const (
RangeLine Range = iota // -range
RangeFile // -range=%
)
type NArgs uint
func (n NArgs) isCommAttr() {}
const (
NArgs0 NArgs = iota // -nargs=0
NArgs1 // -nargs=1
NArgsZeroOrMore // -nargs=*
NArgsZeroOrOne // -nargs=?
NArgsOneOrMore // -nargs=+
)