From 0edf0823b74e81afdd004a4bd7de4b3b85b0f7f6 Mon Sep 17 00:00:00 2001 From: SPFab <42518661+SPFabGerman@users.noreply.github.com> Date: Wed, 25 Aug 2021 17:28:47 +0200 Subject: [PATCH] cmap now accepts all expressions (#686) --- eval.go | 4 ++-- eval_test.go | 2 +- parse.go | 20 ++++++++------------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/eval.go b/eval.go index 6e32d7a..d46a8c9 100644 --- a/eval.go +++ b/eval.go @@ -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) } diff --git a/eval_test.go b/eval_test.go index 5bd8e31..48cb445 100644 --- a/eval_test.go +++ b/eval_test.go @@ -218,7 +218,7 @@ var gEvalTests = []struct { { "cmap cmd-escape", []string{"cmap", "", "cmd-escape", "\n"}, - []expr{&cmapExpr{"", "cmd-escape"}}, + []expr{&cmapExpr{"", &callExpr{"cmd-escape", nil, 1}}}, }, { diff --git a/parse.go b/parse.go index cb84903..e6abeb0 100644 --- a/parse.go +++ b/parse.go @@ -14,7 +14,7 @@ package main // // MapExpr = 'map' Expr // -// CMapExpr = 'cmap' ';' +// CMapExpr = 'cmap' Expr // // CmdExpr = 'cmd' 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