From 24e224ca65c0e2f7b80cb0b33606f1de14bf9264 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sat, 13 May 2023 23:43:08 +1000 Subject: [PATCH] Add `jumps` command for displaying the jump list (#1233) * Add `jumps` command for displaying the jump list * Mention jump count in documentation * Reverse order --- complete.go | 1 + doc.go | 7 +++++++ docstring.go | 9 +++++++++ eval.go | 5 +++++ lf.1 | 7 +++++++ ui.go | 24 ++++++++++++++++++++++++ 6 files changed, 53 insertions(+) diff --git a/complete.go b/complete.go index 8900518c..b2698e3f 100644 --- a/complete.go +++ b/complete.go @@ -29,6 +29,7 @@ var ( "open", "jump-next", "jump-prev", + "jumps", "top", "bottom", "high", diff --git a/doc.go b/doc.go index 93cacce4..dfe9cd2f 100644 --- a/doc.go +++ b/doc.go @@ -81,6 +81,7 @@ The following commands are provided by lf: tag-toggle (default 't') maps cmaps + jumps The following command line commands are provided by lf: @@ -613,6 +614,12 @@ Capitalize/uppercase/lowercase the current word and jump to the next word. List all key mappings in normal mode or command-line editing mode. + jumps + +List the contents of the jump list, in order of the most recently visited locations. +Each location is marked with the count that can be used with the `jump-prev` and `jump-next` commands (e.g. use `3[` to move three spaces backwards in the jump list). +A '>' is used to mark the current location in the jump list. + # Options This section shows information about options to customize the behavior. diff --git a/docstring.go b/docstring.go index d9683721..d67e17df 100644 --- a/docstring.go +++ b/docstring.go @@ -84,6 +84,7 @@ The following commands are provided by lf: tag-toggle (default 't') maps cmaps + jumps The following command line commands are provided by lf: @@ -641,6 +642,14 @@ Capitalize/uppercase/lowercase the current word and jump to the next word. List all key mappings in normal mode or command-line editing mode. + jumps + +List the contents of the jump list, in order of the most recently visited +locations. Each location is marked with the count that can be used with the +'jump-prev' and 'jump-next' commands (e.g. use '3[' to move three spaces +backwards in the jump list). A '>' is used to mark the current location in the +jump list. + # Options This section shows information about options to customize the behavior. diff --git a/eval.go b/eval.go index 2b1a10b1..8fdf96da 100644 --- a/eval.go +++ b/eval.go @@ -2509,6 +2509,11 @@ func (e *callExpr) eval(app *app, args []string) { io.Copy(app.cmdIn, listBinds(gOpts.cmdkeys)) app.cmdIn.Close() cleanUp() + case "jumps": + cleanUp := app.runShell(envPager, nil, "$|") + io.Copy(app.cmdIn, listJumps(app.nav.jumpList, app.nav.jumpListInd)) + app.cmdIn.Close() + cleanUp() default: cmd, ok := gOpts.cmds[e.name] if !ok { diff --git a/lf.1 b/lf.1 index ac1aad21..9dfbf0f9 100644 --- a/lf.1 +++ b/lf.1 @@ -96,6 +96,7 @@ The following commands are provided by lf: tag-toggle (default 't') maps cmaps + jumps .EE .PP The following command line commands are provided by lf: @@ -754,6 +755,12 @@ Capitalize/uppercase/lowercase the current word and jump to the next word. .EE .PP List all key mappings in normal mode or command-line editing mode. +.PP +.EX + jumps +.EE +.PP +List the contents of the jump list, in order of the most recently visited locations. Each location is marked with the count that can be used with the `jump-prev` and `jump-next` commands (e.g. use `3[` to move three spaces backwards in the jump list). A '>' is used to mark the current location in the jump list. .SH OPTIONS This section shows information about options to customize the behavior. Character ':' is used as the separator for list options '[]int' and '[]string'. .PP diff --git a/ui.go b/ui.go index 6dbad090..4534ce16 100644 --- a/ui.go +++ b/ui.go @@ -1056,6 +1056,30 @@ func listBinds(binds map[string]expr) *bytes.Buffer { return b } +func listJumps(jumps []string, ind int) *bytes.Buffer { + t := new(tabwriter.Writer) + b := new(bytes.Buffer) + + maxlength := len(strconv.Itoa(max(ind, len(jumps)-1-ind))) + + t.Init(b, 0, gOpts.tabstop, 2, '\t', 0) + fmt.Fprintln(t, " jump\tpath") + // print jumps in order of most recent, Vim uses the opposite order + for i := len(jumps) - 1; i >= 0; i-- { + switch { + case i < ind: + fmt.Fprintf(t, " %*d\t%s\n", maxlength, ind-i, jumps[i]) + case i > ind: + fmt.Fprintf(t, " %*d\t%s\n", maxlength, i-ind, jumps[i]) + default: + fmt.Fprintf(t, "> %*d\t%s\n", maxlength, 0, jumps[i]) + } + } + t.Flush() + + return b +} + func listMarks(marks map[string]string) *bytes.Buffer { t := new(tabwriter.Writer) b := new(bytes.Buffer)