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) {
if e.cmd == "" {
if e.expr == nil {
delete(gOpts.cmdkeys, e.key)
} else {
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
gOpts.cmdkeys[e.key] = e.expr
}
app.ui.loadFileInfo(app.nav)
}

View File

@ -218,7 +218,7 @@ var gEvalTests = []struct {
{
"cmap <c-g> cmd-escape",
[]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
//
// CMapExpr = 'cmap' <key> <cmd> ';'
// CMapExpr = 'cmap' <key> 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) }
type cmapExpr struct {
key string
cmd string
key 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 {
name string
@ -191,23 +191,19 @@ func (p *parser) parseExpr() expr {
result = &mapExpr{keys, expr}
case "cmap":
var cmd string
var expr expr
s.scan()
key := s.tok
s.scan()
if s.typ != tokenSemicolon {
if s.typ != tokenIdent {
p.err = fmt.Errorf("expected command: %s", s.tok)
}
cmd = s.tok
expr = p.parseExpr()
} else {
s.scan()
}
s.scan()
result = &cmapExpr{key, cmd}
result = &cmapExpr{key, expr}
case "cmd":
var expr expr