From afa90fe64772267c99288a3466cb197e50fe57d7 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Mon, 28 Mar 2022 18:02:17 +0300 Subject: [PATCH] use multiple selections for tag command cc #791 --- doc.go | 4 ++-- docstring.go | 6 +++--- eval.go | 18 ++++++++++++------ lf.1 | 4 ++-- nav.go | 12 +++++++----- opts.go | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/doc.go b/doc.go index 9f7ddf39..a41c7779 100644 --- a/doc.go +++ b/doc.go @@ -467,11 +467,11 @@ Remove a bookmark assigned to the given key. tag -Tag a file with a single width character given in the argument. +Tag a file with "*" or a single width character given in the argument. tag-toggle (default 't') -Tag a file with a single width character given in the argument if the file is untagged, otherwise remove the tag. +Tag a file with "*" or a single width character given in the argument if the file is untagged, otherwise remove the tag. Command Line Commands diff --git a/docstring.go b/docstring.go index f64113f1..eea3dbe3 100644 --- a/docstring.go +++ b/docstring.go @@ -492,12 +492,12 @@ Remove a bookmark assigned to the given key. tag -Tag a file with a single width character given in the argument. +Tag a file with "*" or a single width character given in the argument. tag-toggle (default 't') -Tag a file with a single width character given in the argument if the file -is untagged, otherwise remove the tag. +Tag a file with "*" or a single width character given in the argument if the +file is untagged, otherwise remove the tag. Command Line Commands diff --git a/eval.go b/eval.go index 18a9bf9b..7248220b 100644 --- a/eval.go +++ b/eval.go @@ -988,9 +988,12 @@ func (e *callExpr) eval(app *app, args []string) { return } - if len(e.args) == 0 { - app.ui.echoerr("tag-toggle: missing default tag") - } else if err := app.nav.toggleTag(e.args[0]); err != nil { + tag := "*" + if len(e.args) != 0 { + tag = e.args[0] + } + + if err := app.nav.tagToggle(tag); err != nil { app.ui.echoerrf("tag-toggle: %s", err) } else if err := app.nav.writeTags(); err != nil { app.ui.echoerrf("tag-toggle: %s", err) @@ -1010,9 +1013,12 @@ func (e *callExpr) eval(app *app, args []string) { return } - if len(e.args) == 0 { - app.ui.echoerr("tag: missing tag") - } else if err := app.nav.tag(e.args[0]); err != nil { + tag := "*" + if len(e.args) != 0 { + tag = e.args[0] + } + + if err := app.nav.tag(tag); err != nil { app.ui.echoerrf("tag: %s", err) } else if err := app.nav.writeTags(); err != nil { app.ui.echoerrf("tag: %s", err) diff --git a/lf.1 b/lf.1 index b8b54d2e..3f720ce7 100644 --- a/lf.1 +++ b/lf.1 @@ -579,13 +579,13 @@ Remove a bookmark assigned to the given key. tag .EE .PP -Tag a file with a single width character given in the argument. +Tag a file with "*" or a single width character given in the argument. .PP .EX tag-toggle (default 't') .EE .PP -Tag a file with a single width character given in the argument if the file is untagged, otherwise remove the tag. +Tag a file with "*" or a single width character given in the argument if the file is untagged, otherwise remove the tag. .SH COMMAND LINE COMMANDS This section shows information about command line commands. These should be mostly compatible with readline keybindings. A character refers to a unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters. .PP diff --git a/nav.go b/nav.go index 6125dca3..b675879e 100644 --- a/nav.go +++ b/nav.go @@ -964,7 +964,7 @@ func (nav *nav) toggle() { nav.toggleSelection(curr.path) } -func (nav *nav) toggleTagSelection(path string, tag string) { +func (nav *nav) tagToggleSelection(path string, tag string) { if _, ok := nav.tags[path]; ok { delete(nav.tags, path) } else { @@ -972,7 +972,7 @@ func (nav *nav) toggleTagSelection(path string, tag string) { } } -func (nav *nav) toggleTag(tag string) error { +func (nav *nav) tagToggle(tag string) error { list, err := nav.currFileOrSelections() if err != nil { return err @@ -983,14 +983,14 @@ func (nav *nav) toggleTag(tag string) error { } for _, path := range list { - nav.toggleTagSelection(path, tag) + nav.tagToggleSelection(path, tag) } return nil } func (nav *nav) tag(tag string) error { - curr, err := nav.currFile() + list, err := nav.currFileOrSelections() if err != nil { return err } @@ -999,7 +999,9 @@ func (nav *nav) tag(tag string) error { return errors.New("tag should be single width character") } - nav.tags[curr.path] = tag + for _, path := range list { + nav.tags[path] = tag + } return nil } diff --git a/opts.go b/opts.go index a6052b9f..5c79cd78 100644 --- a/opts.go +++ b/opts.go @@ -149,7 +149,7 @@ func init() { gOpts.keys["["] = &callExpr{"jump-prev", nil, 1} gOpts.keys["]"] = &callExpr{"jump-next", nil, 1} gOpts.keys[""] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1} - gOpts.keys["t"] = &callExpr{"tag-toggle", []string{"*"}, 1} + gOpts.keys["t"] = &callExpr{"tag-toggle", nil, 1} gOpts.keys["v"] = &callExpr{"invert", nil, 1} gOpts.keys["u"] = &callExpr{"unselect", nil, 1} gOpts.keys["y"] = &callExpr{"copy", nil, 1}