cmds command to list all custom commands (aka cmd mappings) (#1265)

This is a natural complement to the recently introduces `maps` and `cmaps`.

I considered using a different output format, since `cmd` definitions can be
long, but I decided against it for now. `lf` already abbreviates commands that
take up several lines, and we can change the output format later if needed.
This commit is contained in:
Ilya Grigoriev authored and GitHub committed 2023-06-04 16:05:13 +03:00
1 parent a9d90bc560
commit b57d76bf97
6 files changed
+30 -2

No files matched your search

+1
View File
@@ -16,6 +16,7 @@ var (
"cmap",
"cmaps",
"cmd",
"cmds",
"quit",
"up",
"half-up",
+5
View File
@@ -81,6 +81,7 @@ The following commands are provided by lf:
tag-toggle (default 't')
maps
cmaps
cmds
jumps
The following command line commands are provided by lf:
@@ -620,6 +621,10 @@ Capitalize/uppercase/lowercase the current word and jump to the next word.
List all key mappings in normal mode or command-line editing mode.
cmds
List all custom commands defined using the `cmd` command
jumps
List the contents of the jump list, in order of the most recently visited locations.
+5
View File
@@ -84,6 +84,7 @@ The following commands are provided by lf:
tag-toggle (default 't')
maps
cmaps
cmds
jumps
The following command line commands are provided by lf:
@@ -648,6 +649,10 @@ Capitalize/uppercase/lowercase the current word and jump to the next word.
List all key mappings in normal mode or command-line editing mode.
cmds
List all custom commands defined using the 'cmd' command
jumps
List the contents of the jump list, in order of the most recently visited
+2
View File
@@ -2525,6 +2525,8 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdAccLeft = acc
update(app)
case "cmds":
app.runPagerOnText(listCmds())
case "maps":
app.runPagerOnText(listBinds(gOpts.keys))
case "cmaps":
+7
View File
@@ -96,6 +96,7 @@ The following commands are provided by lf:
tag-toggle (default 't')
maps
cmaps
cmds
jumps
.EE
.PP
@@ -764,6 +765,12 @@ Capitalize/uppercase/lowercase the current word and jump to the next word.
.PP
List all key mappings in normal mode or command-line editing mode.
.PP
.EX
cmds
.EE
.PP
List all custom commands defined using the `cmd` command
.PP
.EX
jumps
.EE
+10 -2
View File
@@ -1052,7 +1052,7 @@ func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok b
return
}
func listBinds(binds map[string]expr) *bytes.Buffer {
func listExprMap(binds map[string]expr, title string) *bytes.Buffer {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
@@ -1063,7 +1063,7 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
sort.Strings(keys)
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
fmt.Fprintln(t, "keys\tcommand")
fmt.Fprintf(t, "%s\tcommand\n", title)
for _, k := range keys {
fmt.Fprintf(t, "%s\t%v\n", k, binds[k])
}
@@ -1072,6 +1072,14 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
return b
}
func listBinds(binds map[string]expr) *bytes.Buffer {
return listExprMap(binds, "keys")
}
func listCmds() *bytes.Buffer {
return listExprMap(gOpts.cmds, "name")
}
func listJumps(jumps []string, ind int) *bytes.Buffer {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)