From 0c672fef6ffbac9954c286717243e265685f25a9 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Mon, 14 May 2018 01:16:01 +0300 Subject: [PATCH] add 'cmd-capitalize-word' to upcase letter --- doc.go | 39 ++++++++++++++++++++------------------- docstring.go | 39 ++++++++++++++++++++------------------- eval.go | 12 ++++++++++++ opts.go | 1 + 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/doc.go b/doc.go index 155db5b..efafd49 100644 --- a/doc.go +++ b/doc.go @@ -54,25 +54,26 @@ The following commands are provided by lf without default keybindings: The following command line commands are provided by lf with default keybindings: - cmd-escape (default '') - cmd-comp (default '') - cmd-enter (default '' and '') - cmd-hist-next (default '') - cmd-hist-prev (default '') - cmd-delete (default '' and '') - cmd-delete-back (default '' and '') - cmd-left (default '' and '') - cmd-right (default '' and '') - cmd-beg (default '' and '') - cmd-end (default '' and '') - cmd-delete-beg (default '') - cmd-delete-end (default '') - cmd-delete-word (default '') - cmd-put (default '') - cmd-transpose (default '') - cmd-interrupt (default '') - cmd-word (default '') - cmd-word-back (default '') + cmd-escape (default '') + cmd-comp (default '') + cmd-enter (default '' and '') + cmd-hist-next (default '') + cmd-hist-prev (default '') + cmd-delete (default '' and '') + cmd-delete-back (default '' and '') + cmd-left (default '' and '') + cmd-right (default '' and '') + cmd-beg (default '' and '') + cmd-end (default '' and '') + cmd-delete-beg (default '') + cmd-delete-end (default '') + cmd-delete-word (default '') + cmd-put (default '') + cmd-transpose (default '') + cmd-interrupt (default '') + cmd-word (default '') + cmd-word-back (default '') + cmd-capitalize-word (default '') The following options can be used to customize the behavior of lf: diff --git a/docstring.go b/docstring.go index 7d4e1e2..a1e2a83 100644 --- a/docstring.go +++ b/docstring.go @@ -58,25 +58,26 @@ The following commands are provided by lf without default keybindings: The following command line commands are provided by lf with default keybindings: - cmd-escape (default '') - cmd-comp (default '') - cmd-enter (default '' and '') - cmd-hist-next (default '') - cmd-hist-prev (default '') - cmd-delete (default '' and '') - cmd-delete-back (default '' and '') - cmd-left (default '' and '') - cmd-right (default '' and '') - cmd-beg (default '' and '') - cmd-end (default '' and '') - cmd-delete-beg (default '') - cmd-delete-end (default '') - cmd-delete-word (default '') - cmd-put (default '') - cmd-transpose (default '') - cmd-interrupt (default '') - cmd-word (default '') - cmd-word-back (default '') + cmd-escape (default '') + cmd-comp (default '') + cmd-enter (default '' and '') + cmd-hist-next (default '') + cmd-hist-prev (default '') + cmd-delete (default '' and '') + cmd-delete-back (default '' and '') + cmd-left (default '' and '') + cmd-right (default '' and '') + cmd-beg (default '' and '') + cmd-end (default '' and '') + cmd-delete-beg (default '') + cmd-delete-end (default '') + cmd-delete-word (default '') + cmd-put (default '') + cmd-transpose (default '') + cmd-interrupt (default '') + cmd-word (default '') + cmd-word-back (default '') + cmd-capitalize-word (default '') The following options can be used to customize the behavior of lf: diff --git a/eval.go b/eval.go index 5d3d178..b468a0a 100644 --- a/eval.go +++ b/eval.go @@ -6,6 +6,7 @@ import ( "os" "strconv" "strings" + "unicode" "unicode/utf8" ) @@ -630,6 +631,17 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.cmdAccRight = append(app.ui.cmdAccLeft[ind:], app.ui.cmdAccRight...) app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind] } + case "cmd-capitalize-word": + if len(app.ui.cmdAccRight) > 0 { + app.ui.cmdAccRight[0] = unicode.ToUpper(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:] + } default: cmd, ok := gOpts.cmds[e.name] if !ok { diff --git a/opts.go b/opts.go index 66a04d9..ee35ff2 100644 --- a/opts.go +++ b/opts.go @@ -144,6 +144,7 @@ func init() { gOpts.cmdkeys[""] = &callExpr{"cmd-interrupt", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-word", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-word-back", nil, 1} + gOpts.cmdkeys[""] = &callExpr{"cmd-capitalize-word", nil, 1} // TODO: implement the rest of readline keys