implement 'cmd-word' and 'cmd-word-back' commands

Related #67
This commit is contained in:
Gokcehan committed 2018-05-05 19:37:14 +03:00
1 parent 7543b2256c
commit ef709b5611
5 files changed
+31 -1

No files matched your search

+2
View File
@@ -71,6 +71,8 @@ keybindings:
cmd-put (default '<c-y>')
cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>')
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
The following options can be used to customize the behavior of lf:
+2
View File
@@ -75,6 +75,8 @@ keybindings:
cmd-put (default '<c-y>')
cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>')
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
The following options can be used to customize the behavior of lf:
+20
View File
@@ -610,6 +610,26 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case "cmd-word":
if len(app.ui.cmdAccRight) > 0 {
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
if loc == nil {
return
}
ind := loc[0] + 1
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
}
case "cmd-word-back":
if len(app.ui.cmdAccLeft) > 0 {
locs := reWordBeg.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
if locs == nil {
return
}
ind := locs[len(locs)-1][1] - 1
app.ui.cmdAccRight = append(app.ui.cmdAccLeft[ind:], app.ui.cmdAccRight...)
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
}
default:
cmd, ok := gOpts.cmds[e.name]
if !ok {
+3
View File
@@ -195,6 +195,9 @@ func naturalLess(s1, s2 string) bool {
return len(parts1) < len(parts2)
}
var reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`)
var reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`)
func min(a, b int) int {
if a < b {
return a
+4 -1
View File
@@ -117,7 +117,6 @@ func init() {
gOpts.cmdkeys = make(map[string]expr)
// TODO: rest of the keys
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil, 1}
@@ -143,6 +142,10 @@ func init() {
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil, 1}
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
gOpts.cmdkeys["<a-f>"] = &callExpr{"cmd-word", nil, 1}
gOpts.cmdkeys["<a-b>"] = &callExpr{"cmd-word-back", nil, 1}
// TODO: implement the rest of readline keys
gOpts.cmds = make(map[string]expr)