handle keys of push command while scanning

This commit is contained in:
Gokcehan committed 2016-10-15 21:46:31 +03:00
1 parent cecd3f9904
commit a3965ca1d9
7 files changed
+50 -6

No files matched your search

+1 -1
View File
@@ -122,7 +122,7 @@ with a command count.
Second, it can be used to avoid typing the name when a command takes arguments. Second, it can be used to avoid typing the name when a command takes arguments.
map r :push :rename<space> map r push :rename<space>
One thing to be careful is that since "push" command works with keys instead of One thing to be careful is that since "push" command works with keys instead of
commands it is possible to accidentally create recursive bindings. commands it is possible to accidentally create recursive bindings.
+1 -1
View File
@@ -132,7 +132,7 @@ command with a command count.
Second, it can be used to avoid typing the name when a command takes Second, it can be used to avoid typing the name when a command takes
arguments. arguments.
map r :push :rename<space> map r push :rename<space>
One thing to be careful is that since "push" command works with keys instead One thing to be careful is that since "push" command works with keys instead
of commands it is possible to accidentally create recursive bindings. of commands it is possible to accidentally create recursive bindings.
+1 -1
View File
@@ -74,7 +74,7 @@ cmd open-file ${{
# rename current file without overwrite # rename current file without overwrite
cmd rename $[ -e "$1" ] || mv "$f" "$1" cmd rename $[ -e "$1" ] || mv "$f" "$1"
map r :push :rename<space> map r push :rename<space>
# show disk usage # show disk usage
cmd usage $du -h . | less cmd usage $du -h . | less
+1 -1
View File
@@ -337,7 +337,7 @@ func (e *CallExpr) eval(app *App, args []string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
case "push": case "push":
if len(e.args) > 0 { if len(e.args) > 0 {
app.ui.keysbuf = append(app.ui.keysbuf, splitKeys(strings.Join(e.args, ""))...) app.ui.keysbuf = append(app.ui.keysbuf, splitKeys(e.args[0])...)
} }
default: default:
cmd, ok := gOpts.cmds[e.name] cmd, ok := gOpts.cmds[e.name]
+30
View File
@@ -113,6 +113,36 @@ var gTests = []struct {
[]Expr{&MapExpr{"u", &ListExpr{[]Expr{&CallExpr{"usage", nil}}}}}, []Expr{&MapExpr{"u", &ListExpr{[]Expr{&CallExpr{"usage", nil}}}}},
}, },
{
"map r push :rename<space>",
[]string{"map", "r", "push", ":rename<space>", "\n"},
[]Expr{&MapExpr{"r", &CallExpr{"push", []string{":rename<space>"}}}},
},
{
"map r push :rename<space>;",
[]string{"map", "r", "push", ":rename<space>;", "\n"},
[]Expr{&MapExpr{"r", &CallExpr{"push", []string{":rename<space>;"}}}},
},
{
"map r push :rename<space> # trailing comments area allowed after a space",
[]string{"map", "r", "push", ":rename<space>", "\n"},
[]Expr{&MapExpr{"r", &CallExpr{"push", []string{":rename<space>"}}}},
},
{
"map r :push :rename<space>",
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
[]Expr{&MapExpr{"r", &ListExpr{[]Expr{&CallExpr{"push", []string{":rename<space>"}}}}}},
},
{
"map r :push :rename<space> ; set hidden",
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
[]Expr{&MapExpr{"r", &ListExpr{[]Expr{&CallExpr{"push", []string{":rename<space>"}}, &SetExpr{"hidden", ""}}}}},
},
{ {
"map u $du -h . | less", "map u $du -h . | less",
[]string{"map", "u", "$", "du -h . | less", "\n"}, []string{"map", "u", "$", "du -h . | less", "\n"},
+1 -1
View File
@@ -22,7 +22,7 @@ package main
// //
// Prefix = '$' | '!' | '&' | '/' | '?' // Prefix = '$' | '!' | '&' | '/' | '?'
// //
// ListExpr = ':' ListExpr '\n' // ListExpr = ':' ListRest '\n'
// | ':' '{{' ListRest '}}' ';' // | ':' '{{' ListRest '}}' ';'
// //
// ListRest = Nil // ListRest = Nil
+15 -1
View File
@@ -30,6 +30,7 @@ type Scanner struct {
sem bool // insert semicolon sem bool // insert semicolon
nln bool // insert newline nln bool // insert newline
eof bool // buffer ended eof bool // buffer ended
key bool // scanning keys
blk bool // scanning block blk bool // scanning block
cmd bool // scanning command cmd bool // scanning command
typ TokenType // scanned token type typ TokenType // scanned token type
@@ -93,7 +94,6 @@ func isPrefix(b byte) bool {
} }
func (s *Scanner) scan() bool { func (s *Scanner) scan() bool {
// log.Println("scanning:", s.tok)
scan: scan:
switch { switch {
case s.eof: case s.eof:
@@ -111,6 +111,14 @@ scan:
return true return true
} }
return false return false
case s.key:
beg := s.off
for !s.eof && !isSpace(s.chr) {
s.next()
}
s.typ = TokenIdent
s.tok = string(s.buf[beg:s.off])
s.key = false
case s.blk: case s.blk:
// return here by setting s.cmd to false // return here by setting s.cmd to false
// after scanning the command in the loop below // after scanning the command in the loop below
@@ -233,6 +241,12 @@ scan:
} }
s.typ = TokenIdent s.typ = TokenIdent
s.tok = string(s.buf[beg:s.off]) s.tok = string(s.buf[beg:s.off])
if s.tok == "push" {
s.key = true
for isSpace(s.chr) {
s.next()
}
}
s.sem = true s.sem = true
} }