From 5927a506f4320ce3358071356980a517b7639d85 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 19 Mar 2022 17:39:04 +0300 Subject: [PATCH] cleanup --- doc.go | 2 +- docstring.go | 2 +- eval.go | 70 ++++++++++++++++++++++++++-------------------------- lf.1 | 2 +- nav.go | 39 ++++++++++++++--------------- ui.go | 4 +-- 6 files changed, 59 insertions(+), 60 deletions(-) diff --git a/doc.go b/doc.go index f439b00..167bdf0 100644 --- a/doc.go +++ b/doc.go @@ -438,7 +438,7 @@ Read a pattern to search for a file name match in the forward/backward direction setfilter Read a pattern to filter out and only view files matching the pattern. -setfilter does the same but uses an argument to set the filter immediatly. +setfilter does the same but uses an argument to set the filter immediately. You can supply an argument to filter, in order to use that as the starting prompt. (See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options) diff --git a/docstring.go b/docstring.go index 8664b95..0acafee 100644 --- a/docstring.go +++ b/docstring.go @@ -459,7 +459,7 @@ direction and jump to the next/previous match. setfilter Read a pattern to filter out and only view files matching the pattern. -setfilter does the same but uses an argument to set the filter immediatly. +setfilter does the same but uses an argument to set the filter immediately. You can supply an argument to filter, in order to use that as the starting prompt. diff --git a/eval.go b/eval.go index 09dcb92..2b056e4 100644 --- a/eval.go +++ b/eval.go @@ -793,7 +793,7 @@ func insert(app *app, arg string) { func (e *callExpr) eval(app *app, args []string) { switch e.name { case "up": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.up(e.count) { @@ -801,7 +801,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "half-up": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.up(e.count * app.nav.height / 2) { @@ -809,7 +809,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "page-up": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.up(e.count * app.nav.height) { @@ -817,7 +817,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "scrollup": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.scrollup(e.count) { @@ -825,7 +825,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "down": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.down(e.count) { @@ -833,7 +833,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "half-down": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.down(e.count * app.nav.height / 2) { @@ -841,7 +841,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "page-down": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.down(e.count * app.nav.height) { @@ -849,7 +849,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "scrolldown": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.scrolldown(e.count) { @@ -857,7 +857,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "updir": - if (!app.nav.init) { + if !app.nav.init { return } resetIncCmd(app) @@ -873,7 +873,7 @@ func (e *callExpr) eval(app *app, args []string) { restartIncCmd(app) onChdir(app) case "open": - if (!app.nav.init) { + if !app.nav.init { return } curr, err := app.nav.currFile() @@ -948,7 +948,7 @@ func (e *callExpr) eval(app *app, args []string) { case "quit": app.quitChan <- struct{}{} case "top": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.top() { @@ -956,7 +956,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "bottom": - if (!app.nav.init) { + if !app.nav.init { return } if app.nav.bottom() { @@ -964,7 +964,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "toggle": - if (!app.nav.init) { + if !app.nav.init { return } if len(e.args) == 0 { @@ -984,14 +984,14 @@ func (e *callExpr) eval(app *app, args []string) { } } case "invert": - if (!app.nav.init) { + if !app.nav.init { return } app.nav.invert() case "unselect": app.nav.unselect() case "calcdirsize": - if (!app.nav.init) { + if !app.nav.init { return } err := app.nav.calcDirSize() @@ -1003,7 +1003,7 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.sort() app.ui.sort() case "copy": - if (!app.nav.init) { + if !app.nav.init { return } @@ -1025,7 +1025,7 @@ func (e *callExpr) eval(app *app, args []string) { } app.ui.loadFileInfo(app.nav) case "cut": - if (!app.nav.init) { + if !app.nav.init { return } @@ -1047,7 +1047,7 @@ func (e *callExpr) eval(app *app, args []string) { } app.ui.loadFileInfo(app.nav) case "paste": - if (!app.nav.init) { + if !app.nav.init { return } @@ -1060,7 +1060,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) case "delete": - if (!app.nav.init) { + if !app.nav.init { return } @@ -1096,7 +1096,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) case "clear": - if (!app.nav.init) { + if !app.nav.init { return } if err := saveFiles(nil, false); err != nil { @@ -1117,7 +1117,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) case "draw": case "redraw": - if (!app.nav.init) { + if !app.nav.init { return } app.ui.renew() @@ -1128,13 +1128,13 @@ func (e *callExpr) eval(app *app, args []string) { } app.ui.loadFile(app.nav, true) case "load": - if (!app.nav.init) { + if !app.nav.init { return } app.nav.renew() app.ui.loadFile(app.nav, true) case "reload": - if (!app.nav.init) { + if !app.nav.init { return } if err := app.nav.reload(); err != nil { @@ -1194,7 +1194,7 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.findBack = true app.ui.loadFileInfo(app.nav) case "find-next": - if (!app.nav.init) { + if !app.nav.init { return } dir := app.nav.currDir() @@ -1211,7 +1211,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "find-prev": - if (!app.nav.init) { + if !app.nav.init { return } dir := app.nav.currDir() @@ -1228,7 +1228,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } case "search": - if (!app.nav.init) { + if !app.nav.init { return } if app.ui.cmdPrefix == ">" { @@ -1242,7 +1242,7 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.searchBack = false app.ui.loadFileInfo(app.nav) case "search-back": - if (!app.nav.init) { + if !app.nav.init { return } if app.ui.cmdPrefix == ">" { @@ -1256,7 +1256,7 @@ func (e *callExpr) eval(app *app, args []string) { app.nav.searchBack = true app.ui.loadFileInfo(app.nav) case "search-next": - if (!app.nav.init) { + if !app.nav.init { return } for i := 0; i < e.count; i++ { @@ -1277,7 +1277,7 @@ func (e *callExpr) eval(app *app, args []string) { } } case "search-prev": - if (!app.nav.init) { + if !app.nav.init { return } for i := 0; i < e.count; i++ { @@ -1298,7 +1298,7 @@ func (e *callExpr) eval(app *app, args []string) { } } case "filter": - if (!app.nav.init) { + if !app.nav.init { return } if app.ui.cmdPrefix == ">" { @@ -1315,7 +1315,7 @@ func (e *callExpr) eval(app *app, args []string) { } app.ui.loadFileInfo(app.nav) case "setfilter": - if (!app.nav.init) { + if !app.nav.init { return } log.Printf("filter: %s", e.args) @@ -1345,7 +1345,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.menuBuf = listMarks(app.nav.marks) app.ui.cmdPrefix = "mark-remove: " case "rename": - if (!app.nav.init) { + if !app.nav.init { return } if cmd, ok := gOpts.cmds["rename"]; ok { @@ -1421,7 +1421,7 @@ func (e *callExpr) eval(app *app, args []string) { onChdir(app) } case "select": - if (!app.nav.init) { + if !app.nav.init { return } @@ -1461,7 +1461,7 @@ func (e *callExpr) eval(app *app, args []string) { onChdir(app) } case "glob-select": - if (!app.nav.init) { + if !app.nav.init { return } if len(e.args) != 1 { @@ -1473,7 +1473,7 @@ func (e *callExpr) eval(app *app, args []string) { return } case "glob-unselect": - if (!app.nav.init) { + if !app.nav.init { return } if len(e.args) != 1 { diff --git a/lf.1 b/lf.1 index be1df4a..868dd78 100644 --- a/lf.1 +++ b/lf.1 @@ -543,7 +543,7 @@ Read a pattern to search for a file name match in the forward/backward direction setfilter .EE .PP -Read a pattern to filter out and only view files matching the pattern. setfilter does the same but uses an argument to set the filter immediatly. You can supply an argument to filter, in order to use that as the starting prompt. +Read a pattern to filter out and only view files matching the pattern. setfilter does the same but uses an argument to set the filter immediately. You can supply an argument to filter, in order to use that as the starting prompt. .PP (See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options) .PP diff --git a/nav.go b/nav.go index e8a6f40..f9d6452 100644 --- a/nav.go +++ b/nav.go @@ -401,9 +401,8 @@ func (nav *nav) loadDir(path string) *dir { nav.checkDir(d) return d - } else { - return nav.loadDirInternal(path) } + return nav.loadDirInternal(path) } func (nav *nav) checkDir(dir *dir) { @@ -554,7 +553,7 @@ func (nav *nav) reload() error { } func (nav *nav) position() { - if (!nav.init) { + if !nav.init { return } @@ -566,7 +565,7 @@ func (nav *nav) position() { } func (nav *nav) exportFiles() { - if (!nav.init) { + if !nav.init { return } @@ -1598,7 +1597,6 @@ func (nav *nav) currFileOrSelections() (list []string, err error) { } func (nav *nav) calcDirSize() error { - calc := func(f *file) error { if f.IsDir() { total, err := copySize([]string{f.path}) @@ -1616,25 +1614,26 @@ func (nav *nav) calcDirSize() error { return errors.New("no file selected") } return calc(curr) - } else { - for sel, _ := range nav.selections { - lstat, err := os.Lstat(sel) - if err != nil || !lstat.IsDir() { - continue - } - path, name := filepath.Dir(sel), filepath.Base(sel) - dir := nav.loadDir(path) + } - for _, f := range dir.files { - if f.Name() == name { - err := calc(f) - if err != nil { - return err - } - break + for sel := range nav.selections { + lstat, err := os.Lstat(sel) + if err != nil || !lstat.IsDir() { + continue + } + path, name := filepath.Dir(sel), filepath.Base(sel) + dir := nav.loadDir(path) + + for _, f := range dir.files { + if f.Name() == name { + err := calc(f) + if err != nil { + return err } + break } } } + return nil } diff --git a/ui.go b/ui.go index 0f57542..f147043 100644 --- a/ui.go +++ b/ui.go @@ -641,7 +641,7 @@ type reg struct { } func (ui *ui) loadFile(nav *nav, volatile bool) { - if (!nav.init) { + if !nav.init { return } @@ -666,7 +666,7 @@ func (ui *ui) loadFile(nav *nav, volatile bool) { } func (ui *ui) loadFileInfo(nav *nav) { - if (!nav.init) { + if !nav.init { return }