Skip to content

Commit 691a736

Browse files
committed
nvim/plugin: use backtick instead of double quote
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 452bdaa commit 691a736

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

nvim/plugin/plugin.go

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ type FunctionOptions struct {
115115
// expression for the function
116116
//
117117
// func example(eval *struct{
118-
// GOPATH string `eval:"$GOPATH"`
119-
// Cwd string `eval:"getcwd()"`
118+
// GOPATH string `eval:"$GOPATH"`
119+
// Cwd string `eval:"getcwd()"`
120120
// })
121121
//
122122
// is
@@ -125,11 +125,11 @@ type FunctionOptions struct {
125125
func (p *Plugin) HandleFunction(options *FunctionOptions, fn interface{}) {
126126
m := make(map[string]string)
127127
if options.Eval != "" {
128-
m["eval"] = eval(options.Eval, fn)
128+
m[`eval`] = eval(options.Eval, fn)
129129
}
130130
p.handle(fn, &pluginSpec{
131-
sm: "0:function:" + options.Name,
132-
Type: "function",
131+
sm: `0:function:` + options.Name,
132+
Type: `function`,
133133
Name: options.Name,
134134
Sync: isSync(fn),
135135
Opts: m,
@@ -228,45 +228,45 @@ func (p *Plugin) HandleCommand(options *CommandOptions, fn interface{}) {
228228
m := make(map[string]string)
229229

230230
if options.NArgs != "" {
231-
m["nargs"] = options.NArgs
231+
m[`nargs`] = options.NArgs
232232
}
233233

234234
if options.Range != "" {
235-
if options.Range == "." {
235+
if options.Range == `.` {
236236
options.Range = ""
237237
}
238-
m["range"] = options.Range
238+
m[`range`] = options.Range
239239
} else if options.Count != "" {
240-
m["count"] = options.Count
240+
m[`count`] = options.Count
241241
}
242242

243243
if options.Bang {
244-
m["bang"] = ""
244+
m[`bang`] = ""
245245
}
246246

247247
if options.Register {
248-
m["register"] = ""
248+
m[`register`] = ""
249249
}
250250

251251
if options.Eval != "" {
252-
m["eval"] = eval(options.Eval, fn)
252+
m[`eval`] = eval(options.Eval, fn)
253253
}
254254

255255
if options.Addr != "" {
256-
m["addr"] = options.Addr
256+
m[`addr`] = options.Addr
257257
}
258258

259259
if options.Bar {
260-
m["bar"] = ""
260+
m[`bar`] = ""
261261
}
262262

263263
if options.Complete != "" {
264-
m["complete"] = options.Complete
264+
m[`complete`] = options.Complete
265265
}
266266

267267
p.handle(fn, &pluginSpec{
268-
sm: "0:command:" + options.Name,
269-
Type: "command",
268+
sm: `0:command:` + options.Name,
269+
Type: `command`,
270270
Name: options.Name,
271271
Sync: isSync(fn),
272272
Opts: m,
@@ -310,31 +310,31 @@ func (p *Plugin) HandleAutocmd(options *AutocmdOptions, fn interface{}) {
310310
pattern := ""
311311
m := make(map[string]string)
312312
if options.Group != "" {
313-
m["group"] = options.Group
313+
m[`group`] = options.Group
314314
}
315315
if options.Pattern != "" {
316-
m["pattern"] = options.Pattern
316+
m[`pattern`] = options.Pattern
317317
pattern = options.Pattern
318318
}
319319
if options.Nested {
320-
m["nested"] = "1"
320+
m[`nested`] = "1"
321321
}
322322
if options.Once {
323-
m["once"] = "1"
323+
m[`once`] = "1"
324324
}
325325
if options.Eval != "" {
326-
m["eval"] = eval(options.Eval, fn)
326+
m[`eval`] = eval(options.Eval, fn)
327327
}
328328

329329
// Compute unique path for event and pattern.
330330
ep := options.Event + ":" + pattern
331331
i := p.eventPathCounts[ep]
332332
p.eventPathCounts[ep] = i + 1
333-
sm := fmt.Sprintf("%d:autocmd:%s", i, ep)
333+
sm := fmt.Sprintf(`%d:autocmd:%s`, i, ep)
334334

335335
p.handle(fn, &pluginSpec{
336336
sm: sm,
337-
Type: "autocmd",
337+
Type: `autocmd`,
338338
Name: options.Event,
339339
Sync: isSync(fn),
340340
Opts: m,
@@ -350,16 +350,17 @@ func (p *Plugin) RegisterForTests() error {
350350
}
351351
const host = "nvim-go-test"
352352
for path, specs := range specs {
353-
if err := p.Nvim.Call("remote#host#RegisterPlugin", nil, host, path, specs); err != nil {
353+
if err := p.Nvim.Call(`remote#host#RegisterPlugin`, nil, host, path, specs); err != nil {
354354
return err
355355
}
356356
}
357-
err := p.Nvim.Call("remote#host#Register", nil, host, "x", p.Nvim.ChannelID())
357+
err := p.Nvim.Call(`remote#host#Register`, nil, host, `x`, p.Nvim.ChannelID())
358+
358359
return err
359360
}
360361

361362
func eval(eval string, f interface{}) string {
362-
if eval != "*" {
363+
if eval != `*` {
363364
return eval
364365
}
365366
ft := reflect.TypeOf(f)
@@ -403,11 +404,11 @@ func structEval(t reflect.Type) string {
403404
}
404405

405406
buf = append(buf, sep...)
406-
buf = append(buf, "'"...)
407+
buf = append(buf, `'`...)
407408
buf = append(buf, name...)
408-
buf = append(buf, "': "...)
409+
buf = append(buf, `':`...)
409410
buf = append(buf, eval...)
410-
sep = ", "
411+
sep = `, `
411412
}
412413
buf = append(buf, '}')
413414
return string(buf)
@@ -424,25 +425,25 @@ func (p *Plugin) Manifest(host string) []byte {
424425

425426
// Sort for consistent order on output.
426427
sort.Sort(byServiceMethod(p.pluginSpecs))
427-
escape := strings.NewReplacer("'", "''").Replace
428+
escape := strings.NewReplacer(`'`, `''`).Replace
428429

429430
prevPath := ""
430431
for _, spec := range p.pluginSpecs {
431432
path := spec.path()
432433
if path != prevPath {
433434
if prevPath != "" {
434-
fmt.Fprintf(&buf, "\\ )")
435+
fmt.Fprintf(&buf, `\\ )`)
435436
}
436-
fmt.Fprintf(&buf, "call remote#host#RegisterPlugin('%s', '%s', [\n", host, path)
437+
fmt.Fprintf(&buf, `call remote#host#RegisterPlugin('%s', '%s', [\n`, host, path)
437438
prevPath = path
438439
}
439440

440-
sync := "0"
441+
sync := `0`
441442
if spec.Sync {
442-
sync = "1"
443+
sync = `1`
443444
}
444445

445-
fmt.Fprintf(&buf, "\\ {'type': '%s', 'name': '%s', 'sync': %s, 'opts': {", spec.Type, spec.Name, sync)
446+
fmt.Fprintf(&buf, `\\ {'type': '%s', 'name': '%s', 'sync': %s, 'opts': {`, spec.Type, spec.Name, sync)
446447

447448
var keys []string
448449
for k := range spec.Opts {
@@ -452,14 +453,14 @@ func (p *Plugin) Manifest(host string) []byte {
452453

453454
optDelim := ""
454455
for _, k := range keys {
455-
fmt.Fprintf(&buf, "%s'%s': '%s'", optDelim, k, escape(spec.Opts[k]))
456-
optDelim = ", "
456+
fmt.Fprintf(&buf, `%s'%s': '%s'`, optDelim, k, escape(spec.Opts[k]))
457+
optDelim = `,`
457458
}
458459

459-
fmt.Fprintf(&buf, "}},\n")
460+
fmt.Fprintf(&buf, `}},\n`)
460461
}
461462
if prevPath != "" {
462-
fmt.Fprintf(&buf, "\\ ])\n")
463+
fmt.Fprintf(&buf, `\\ ])\n`)
463464
}
464465
return buf.Bytes()
465466
}

0 commit comments

Comments
 (0)