add 'mark-save' and 'mark-load' commands for marks

Related #76
This commit is contained in:
Gokcehan committed 2018-07-09 21:35:04 +03:00
1 parent a80900f41e
commit 0d0f7451ac
8 files changed
+72

No files matched your search

+2
View File
@@ -45,6 +45,8 @@ var (
"search-back", "search-back",
"search-next", "search-next",
"search-prev", "search-prev",
"mark-save",
"mark-load",
"sync", "sync",
"echo", "echo",
"cd", "cd",
+2
View File
@@ -45,6 +45,8 @@ The following commands are provided by lf with default keybindings:
search-back (default '?') search-back (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm')
mark-load (default "'")
The following commands are provided by lf without default keybindings: The following commands are provided by lf without default keybindings:
+2
View File
@@ -48,6 +48,8 @@ The following commands are provided by lf with default keybindings:
search-back (default '?') search-back (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm')
mark-load (default "'")
The following commands are provided by lf without default keybindings: The following commands are provided by lf without default keybindings:
+40
View File
@@ -436,6 +436,11 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "mark-save":
app.ui.cmdPrefix = "mark-save: "
case "mark-load":
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: "
case "sync": case "sync":
if err := app.nav.sync(); err != nil { if err := app.nav.sync(); err != nil {
app.ui.printf("sync: %s", err) app.ui.printf("sync: %s", err)
@@ -483,6 +488,41 @@ func (e *callExpr) eval(app *app, args []string) {
if len(e.args) == 0 { if len(e.args) == 0 {
return return
} }
switch app.ui.cmdPrefix {
case "mark-save: ":
app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
wd, err := os.Getwd()
if err != nil {
log.Printf("getting current directory: %s", err)
return
}
app.nav.marks[e.args[0]] = wd
return
case "mark-load: ":
app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
path, ok := app.nav.marks[e.args[0]]
if !ok {
app.ui.print("mark-load: no such mark")
return
}
if err := app.nav.cd(path); err != nil {
app.ui.printf("%s", err)
return
}
app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
return
}
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
case "cmd-escape": case "cmd-escape":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
+2
View File
@@ -55,6 +55,8 @@ The following commands are provided by lf with default keybindings:
search-back (default '?') search-back (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm')
mark-load (default "'")
.EE .EE
.PP .PP
The following commands are provided by lf without default keybindings: The following commands are provided by lf without default keybindings:
+2
View File
@@ -194,6 +194,7 @@ type nav struct {
dirCache map[string]*dir dirCache map[string]*dir
regCache map[string]*reg regCache map[string]*reg
saves map[string]bool saves map[string]bool
marks map[string]string
selections map[string]int selections map[string]int
selectionInd int selectionInd int
height int height int
@@ -270,6 +271,7 @@ func newNav(height int) *nav {
dirCache: make(map[string]*dir), dirCache: make(map[string]*dir),
regCache: make(map[string]*reg), regCache: make(map[string]*reg),
saves: make(map[string]bool), saves: make(map[string]bool),
marks: make(map[string]string),
selections: make(map[string]int), selections: make(map[string]int),
selectionInd: 0, selectionInd: 0,
height: height, height: height,
+2
View File
@@ -109,6 +109,8 @@ func init() {
gOpts.keys["?"] = &callExpr{"search-back", nil, 1} gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
gOpts.keys["n"] = &callExpr{"search-next", nil, 1} gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1} gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1} gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1} gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
+20
View File
@@ -700,6 +700,26 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
return b return b
} }
func listMarks(marks map[string]string) *bytes.Buffer {
t := new(tabwriter.Writer)
b := new(bytes.Buffer)
var keys []string
for k := range marks {
keys = append(keys, k)
}
sort.Strings(keys)
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
fmt.Fprintln(t, "mark\tpath")
for _, k := range keys {
fmt.Fprintf(t, "%s\t%s\n", k, marks[k])
}
t.Flush()
return b
}
func (ui *ui) pollEvent() termbox.Event { func (ui *ui) pollEvent() termbox.Event {
select { select {
case key := <-ui.keyChan: case key := <-ui.keyChan: