cmap now accepts all expressions (#686)

This commit is contained in:
SPFab 2021-08-25 17:28:47 +02:00 committed by GitHub
parent 05a48ea315
commit 0edf0823b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 15 deletions

View File

@ -436,10 +436,10 @@ func (e *mapExpr) eval(app *app, args []string) {
} }
func (e *cmapExpr) eval(app *app, args []string) { func (e *cmapExpr) eval(app *app, args []string) {
if e.cmd == "" { if e.expr == nil {
delete(gOpts.cmdkeys, e.key) delete(gOpts.cmdkeys, e.key)
} else { } else {
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1} gOpts.cmdkeys[e.key] = e.expr
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }

View File

@ -218,7 +218,7 @@ var gEvalTests = []struct {
{ {
"cmap <c-g> cmd-escape", "cmap <c-g> cmd-escape",
[]string{"cmap", "<c-g>", "cmd-escape", "\n"}, []string{"cmap", "<c-g>", "cmd-escape", "\n"},
[]expr{&cmapExpr{"<c-g>", "cmd-escape"}}, []expr{&cmapExpr{"<c-g>", &callExpr{"cmd-escape", nil, 1}}},
}, },
{ {

View File

@ -14,7 +14,7 @@ package main
// //
// MapExpr = 'map' <keys> Expr // MapExpr = 'map' <keys> Expr
// //
// CMapExpr = 'cmap' <key> <cmd> ';' // CMapExpr = 'cmap' <key> Expr
// //
// CmdExpr = 'cmd' <name> Expr // CmdExpr = 'cmd' <name> Expr
// //
@ -58,11 +58,11 @@ type mapExpr struct {
func (e *mapExpr) String() string { return fmt.Sprintf("map %s %s", e.keys, e.expr) } func (e *mapExpr) String() string { return fmt.Sprintf("map %s %s", e.keys, e.expr) }
type cmapExpr struct { type cmapExpr struct {
key string key string
cmd string expr expr
} }
func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.cmd) } func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.expr) }
type cmdExpr struct { type cmdExpr struct {
name string name string
@ -191,23 +191,19 @@ func (p *parser) parseExpr() expr {
result = &mapExpr{keys, expr} result = &mapExpr{keys, expr}
case "cmap": case "cmap":
var cmd string var expr expr
s.scan() s.scan()
key := s.tok key := s.tok
s.scan() s.scan()
if s.typ != tokenSemicolon { if s.typ != tokenSemicolon {
if s.typ != tokenIdent { expr = p.parseExpr()
p.err = fmt.Errorf("expected command: %s", s.tok) } else {
}
cmd = s.tok
s.scan() s.scan()
} }
s.scan() result = &cmapExpr{key, expr}
result = &cmapExpr{key, cmd}
case "cmd": case "cmd":
var expr expr var expr expr