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:
Juris Arturs Majors 2019-06-25 20:38:34 +02:00 committed by gokcehan
parent bf39c7c63b
commit 16db95707e
8 changed files with 39 additions and 13 deletions

4
app.go
View File

@ -181,10 +181,6 @@ func (app *app) loop() {
log.Print("bye!")
if err := app.nav.writeMarks(); err != nil {
log.Printf("writing marks file: %s", err)
}
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}

View File

@ -51,6 +51,7 @@ var (
"search-next",
"search-prev",
"mark-save",
"mark-remove",
"mark-load",
"sync",
"echo",

1
doc.go
View File

@ -51,6 +51,7 @@ The following commands are provided by lf with default keybindings:
search-prev (default 'N')
mark-save (default 'm')
mark-load (default "'")
mark-remove (default `"`)
The following commands are provided by lf without default keybindings:

View File

@ -54,6 +54,7 @@ The following commands are provided by lf with default keybindings:
search-prev (default 'N')
mark-save (default 'm')
mark-load (default "'")
mark-remove (default '"')
The following commands are provided by lf without default keybindings:

23
eval.go
View File

@ -470,6 +470,12 @@ func insert(app *app, arg string) {
return
}
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: ":
normal(app)
@ -493,6 +499,20 @@ func insert(app *app, arg string) {
if wd != path {
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:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
}
@ -766,6 +786,9 @@ func (e *callExpr) eval(app *app, args []string) {
case "mark-load":
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: "
case "mark-remove":
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: "
case "sync":
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err)

1
lf.1
View File

@ -61,6 +61,7 @@ The following commands are provided by lf with default keybindings:
search-prev (default 'N')
mark-save (default 'm')
mark-load (default "'")
mark-remove (default `"`)
.EE
.PP
The following commands are provided by lf without default keybindings:

20
nav.go
View File

@ -747,7 +747,7 @@ func (nav *nav) sync() error {
nav.saves[f] = cp
}
return nil
return nav.readMarks()
}
func (nav *nav) cd(wd string) error {
@ -975,7 +975,17 @@ func (nav *nav) searchPrev() error {
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 {
nav.marks = make(map[string]string)
f, err := os.Open(gMarksPath)
if os.IsNotExist(err) {
return nil
@ -1001,14 +1011,6 @@ func (nav *nav) readMarks() 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 {
return fmt.Errorf("creating data directory: %s", err)
}

View File

@ -137,6 +137,7 @@ func init() {
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[`"`] = &callExpr{"mark-remove", nil, 1}
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}