Mark clear (#190)
* markclear * Revert "markclear" This reverts commit 5e3a188618cb02f7aa284e9f2c9a00ed8ce3dc14. * Revert "Revert "markclear"" This reverts commit a7a3bfebbf99c10b4a09f197fa997eca461369c4. * markclear with arguments * docs * reverted some whitepsace * some inline comments * additional error handling * wrong argument case * consider case when argument specified clears all marks * code cleanup and removed readMarks from writeMarks * indentation :/ * discussed changes implemnted * return readMarks error in sync() * remove reset marks
This commit is contained in:
parent
bf39c7c63b
commit
16db95707e
4
app.go
4
app.go
@ -181,10 +181,6 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
log.Print("bye!")
|
log.Print("bye!")
|
||||||
|
|
||||||
if err := app.nav.writeMarks(); err != nil {
|
|
||||||
log.Printf("writing marks file: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.writeHistory(); err != nil {
|
if err := app.writeHistory(); err != nil {
|
||||||
log.Printf("writing history file: %s", err)
|
log.Printf("writing history file: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ var (
|
|||||||
"search-next",
|
"search-next",
|
||||||
"search-prev",
|
"search-prev",
|
||||||
"mark-save",
|
"mark-save",
|
||||||
|
"mark-remove",
|
||||||
"mark-load",
|
"mark-load",
|
||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
|
1
doc.go
1
doc.go
@ -51,6 +51,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
search-prev (default 'N')
|
search-prev (default 'N')
|
||||||
mark-save (default 'm')
|
mark-save (default 'm')
|
||||||
mark-load (default "'")
|
mark-load (default "'")
|
||||||
|
mark-remove (default `"`)
|
||||||
|
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
search-prev (default 'N')
|
search-prev (default 'N')
|
||||||
mark-save (default 'm')
|
mark-save (default 'm')
|
||||||
mark-load (default "'")
|
mark-load (default "'")
|
||||||
|
mark-remove (default '"')
|
||||||
|
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
|
23
eval.go
23
eval.go
@ -470,6 +470,12 @@ func insert(app *app, arg string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.marks[arg] = wd
|
app.nav.marks[arg] = wd
|
||||||
|
if err := app.nav.writeMarks(); err != nil {
|
||||||
|
app.ui.echoerrf("mark-save: %s", err)
|
||||||
|
}
|
||||||
|
if err := remote("send sync"); err != nil {
|
||||||
|
app.ui.echoerrf("mark-save: %s", err)
|
||||||
|
}
|
||||||
case app.ui.cmdPrefix == "mark-load: ":
|
case app.ui.cmdPrefix == "mark-load: ":
|
||||||
normal(app)
|
normal(app)
|
||||||
|
|
||||||
@ -493,6 +499,20 @@ func insert(app *app, arg string) {
|
|||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
}
|
}
|
||||||
|
case app.ui.cmdPrefix == "mark-remove: ":
|
||||||
|
normal(app)
|
||||||
|
if err := app.nav.removeMark(arg); err != nil {
|
||||||
|
app.ui.echoerrf("mark-remove: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.writeMarks(); err != nil {
|
||||||
|
app.ui.echoerrf("mark-remove: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := remote("send sync"); err != nil {
|
||||||
|
app.ui.echoerrf("mark-remove: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
}
|
}
|
||||||
@ -766,6 +786,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "mark-load":
|
case "mark-load":
|
||||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||||
app.ui.cmdPrefix = "mark-load: "
|
app.ui.cmdPrefix = "mark-load: "
|
||||||
|
case "mark-remove":
|
||||||
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||||
|
app.ui.cmdPrefix = "mark-remove: "
|
||||||
case "sync":
|
case "sync":
|
||||||
if err := app.nav.sync(); err != nil {
|
if err := app.nav.sync(); err != nil {
|
||||||
app.ui.echoerrf("sync: %s", err)
|
app.ui.echoerrf("sync: %s", err)
|
||||||
|
1
lf.1
1
lf.1
@ -61,6 +61,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
search-prev (default 'N')
|
search-prev (default 'N')
|
||||||
mark-save (default 'm')
|
mark-save (default 'm')
|
||||||
mark-load (default "'")
|
mark-load (default "'")
|
||||||
|
mark-remove (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:
|
||||||
|
20
nav.go
20
nav.go
@ -747,7 +747,7 @@ func (nav *nav) sync() error {
|
|||||||
nav.saves[f] = cp
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nav.readMarks()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) cd(wd string) error {
|
func (nav *nav) cd(wd string) error {
|
||||||
@ -975,7 +975,17 @@ func (nav *nav) searchPrev() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) removeMark(mark string) error {
|
||||||
|
if _, ok := nav.marks[mark]; ok {
|
||||||
|
delete(nav.marks, mark)
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("no such mark")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) readMarks() error {
|
func (nav *nav) readMarks() error {
|
||||||
|
nav.marks = make(map[string]string)
|
||||||
f, err := os.Open(gMarksPath)
|
f, err := os.Open(gMarksPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@ -1001,14 +1011,6 @@ func (nav *nav) readMarks() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) writeMarks() error {
|
func (nav *nav) writeMarks() error {
|
||||||
if len(nav.marks) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := nav.readMarks(); err != nil {
|
|
||||||
return fmt.Errorf("reading marks file: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
||||||
return fmt.Errorf("creating data directory: %s", err)
|
return fmt.Errorf("creating data directory: %s", err)
|
||||||
}
|
}
|
||||||
|
1
opts.go
1
opts.go
@ -137,6 +137,7 @@ func init() {
|
|||||||
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["m"] = &callExpr{"mark-save", nil, 1}
|
||||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
||||||
|
gOpts.keys[`"`] = &callExpr{"mark-remove", 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}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user