Skip to content

Commit

Permalink
Add jumps command for displaying the jump list (#1233)
Browse files Browse the repository at this point in the history
* Add `jumps` command for displaying the jump list

* Mention jump count in documentation

* Reverse order
  • Loading branch information
joelim-work committed May 13, 2023
1 parent 2a5c54c commit 24e224c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions complete.go
Expand Up @@ -29,6 +29,7 @@ var (
"open",
"jump-next",
"jump-prev",
"jumps",
"top",
"bottom",
"high",
Expand Down
7 changes: 7 additions & 0 deletions doc.go
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions eval.go
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions lf.1
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions ui.go
Expand Up @@ -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)
Expand Down

0 comments on commit 24e224c

Please sign in to comment.