From 791dfff8dc4f804f81c1f5e821e642096f7250c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Peter=20Dhall=C3=A9?= <62998174+janpeterd@users.noreply.github.com> Date: Sun, 3 Sep 2023 18:52:07 +0200 Subject: [PATCH] Add `cmd-delete-word-back` command (#1409) * add `cmd-delete-word-back` Implementation of zsh-like backwards word deletion. * add unixwords option and evaluate, short description in doc * remove unixwords configuration option * remove yank, bind delete word back to alt-backspace, update docs * minor changes to docs * small fixes --- complete.go | 1 + doc.go | 5 +++++ docstring.go | 5 +++++ eval.go | 11 +++++++++++ lf.1 | 7 +++++++ opts.go | 2 ++ 6 files changed, 31 insertions(+) diff --git a/complete.go b/complete.go index e31a3caa..7e300024 100644 --- a/complete.go +++ b/complete.go @@ -101,6 +101,7 @@ var ( "cmd-delete-home", "cmd-delete-end", "cmd-delete-unix-word", + "cmd-delete-word-back", "cmd-yank", "cmd-transpose", "cmd-transpose-word", diff --git a/doc.go b/doc.go index cec820a1..6ecd8562 100644 --- a/doc.go +++ b/doc.go @@ -111,6 +111,7 @@ The following command line commands are provided by lf: cmd-word (default '') cmd-word-back (default '') cmd-delete-word (default '') + cmd-delete-word-back (default '' and '') cmd-capitalize-word (default '') cmd-uppercase-word (default '') cmd-lowercase-word (default '') @@ -632,6 +633,10 @@ Move the cursor by one word in forward/backward direction. Delete the next word in forward direction. + cmd-delete-word-back (default '' and '') + +Delete the previous word in backward direction. + cmd-capitalize-word (default '') cmd-uppercase-word (default '') cmd-lowercase-word (default '') diff --git a/docstring.go b/docstring.go index 36893927..92335026 100644 --- a/docstring.go +++ b/docstring.go @@ -114,6 +114,7 @@ The following command line commands are provided by lf: cmd-word (default '') cmd-word-back (default '') cmd-delete-word (default '') + cmd-delete-word-back (default '' and '') cmd-capitalize-word (default '') cmd-uppercase-word (default '') cmd-lowercase-word (default '') @@ -661,6 +662,10 @@ Move the cursor by one word in forward/backward direction. Delete the next word in forward direction. + cmd-delete-word-back (default '' and '') + +Delete the previous word in backward direction. + cmd-capitalize-word (default '') cmd-uppercase-word (default '') cmd-lowercase-word (default '') diff --git a/eval.go b/eval.go index 0c38c793..79036e12 100644 --- a/eval.go +++ b/eval.go @@ -2665,6 +2665,17 @@ func (e *callExpr) eval(app *app, args []string) { ind := loc[3] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:]) update(app) + case "cmd-delete-word-back": + if len(app.ui.cmdAccLeft) == 0 { + return + } + locs := reWordBeg.FindAllStringSubmatchIndex(string(app.ui.cmdAccLeft), -1) + if locs == nil { + return + } + ind := locs[len(locs)-1][3] + app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind] + update(app) case "cmd-uppercase-word": if len(app.ui.cmdAccRight) == 0 { return diff --git a/lf.1 b/lf.1 index c325374a..1394e70a 100644 --- a/lf.1 +++ b/lf.1 @@ -128,6 +128,7 @@ The following command line commands are provided by lf: cmd-word (default '') cmd-word-back (default '') cmd-delete-word (default '') + cmd-delete-word-back (default '' and '') cmd-capitalize-word (default '') cmd-uppercase-word (default '') cmd-lowercase-word (default '') @@ -776,6 +777,12 @@ Move the cursor by one word in forward/backward direction. .PP Delete the next word in forward direction. .PP +.EX + cmd-delete-word-back (default '' and '') +.EE +.PP +Delete the previous word in backward direction. +.PP .EX cmd-capitalize-word (default '') cmd-uppercase-word (default '') diff --git a/opts.go b/opts.go index 45bf3b60..bbce7997 100644 --- a/opts.go +++ b/opts.go @@ -351,6 +351,8 @@ func init() { gOpts.cmdkeys[""] = &callExpr{"cmd-word-back", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-capitalize-word", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-delete-word", nil, 1} + gOpts.cmdkeys[""] = &callExpr{"cmd-delete-word-back", nil, 1} + gOpts.cmdkeys[""] = &callExpr{"cmd-delete-word-back", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-uppercase-word", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-lowercase-word", nil, 1} gOpts.cmdkeys[""] = &callExpr{"cmd-transpose-word", nil, 1}