1 parent
170e39b95e
commit
a59a5aa712
2 files changed
+137
-91
No files matched your search
@@ -110,8 +110,8 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
app.ui.printf("findlen: %s", err)
|
app.ui.printf("findlen: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n <= 0 {
|
if n < 0 {
|
||||||
app.ui.print("findlen: value should be a positive number")
|
app.ui.print("findlen: value should be a non-negative number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.findlen = n
|
gOpts.findlen = n
|
||||||
@@ -264,6 +264,115 @@ func splitKeys(s string) (keys []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func insert(app *app, arg string) {
|
||||||
|
switch app.ui.cmdPrefix {
|
||||||
|
case "find: ":
|
||||||
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
if gOpts.findlen == 0 {
|
||||||
|
switch app.nav.findSingle() {
|
||||||
|
case 0:
|
||||||
|
app.ui.print("pattern not found")
|
||||||
|
case 1:
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
default:
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(app.nav.find) < gOpts.findlen {
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !app.nav.findNext() {
|
||||||
|
app.ui.print("pattern not found")
|
||||||
|
} else {
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
case "find-back: ":
|
||||||
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
if gOpts.findlen == 0 {
|
||||||
|
switch app.nav.findSingle() {
|
||||||
|
case 0:
|
||||||
|
app.ui.print("pattern not found")
|
||||||
|
case 1:
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
default:
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(app.nav.find) < gOpts.findlen {
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !app.nav.findPrev() {
|
||||||
|
app.ui.print("pattern not found")
|
||||||
|
} else {
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
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[arg] = wd
|
||||||
|
case "mark-load: ":
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
path, ok := app.nav.marks[arg]
|
||||||
|
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)
|
||||||
|
|
||||||
|
if wd != path {
|
||||||
|
app.nav.marks["'"] = wd
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *callExpr) eval(app *app, args []string) {
|
func (e *callExpr) eval(app *app, args []string) {
|
||||||
switch e.name {
|
switch e.name {
|
||||||
case "up":
|
case "up":
|
||||||
@@ -553,93 +662,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if len(e.args) == 0 {
|
if len(e.args) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch app.ui.cmdPrefix {
|
insert(app, e.args[0])
|
||||||
case "find: ":
|
|
||||||
pattern := string(app.ui.cmdAccLeft) + e.args[0] + string(app.ui.cmdAccRight)
|
|
||||||
if len(pattern) < gOpts.findlen {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
app.nav.find = pattern
|
|
||||||
|
|
||||||
if !app.nav.findNext() {
|
|
||||||
app.ui.print("pattern not found")
|
|
||||||
} else {
|
|
||||||
app.ui.loadFile(app.nav)
|
|
||||||
app.ui.loadFileInfo(app.nav)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.ui.menuBuf = nil
|
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
|
|
||||||
return
|
|
||||||
case "find-back: ":
|
|
||||||
pattern := string(app.ui.cmdAccLeft) + e.args[0] + string(app.ui.cmdAccRight)
|
|
||||||
if len(pattern) < gOpts.findlen {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
app.nav.find = pattern
|
|
||||||
|
|
||||||
if !app.nav.findPrev() {
|
|
||||||
app.ui.print("pattern not found")
|
|
||||||
} else {
|
|
||||||
app.ui.loadFile(app.nav)
|
|
||||||
app.ui.loadFileInfo(app.nav)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.ui.menuBuf = nil
|
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
|
|
||||||
return
|
|
||||||
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 = ""
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting current directory: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if wd != path {
|
|
||||||
app.nav.marks["'"] = wd
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
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 == ">" {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -666,6 +666,29 @@ func findMatch(name, pattern string) bool {
|
|||||||
return strings.HasPrefix(name, pattern)
|
return strings.HasPrefix(name, pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) findSingle() int {
|
||||||
|
count := 0
|
||||||
|
index := 0
|
||||||
|
last := nav.currDir()
|
||||||
|
for i := 0; i < len(last.files); i++ {
|
||||||
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
|
count++
|
||||||
|
if count > 1 {
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
index = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count == 1 {
|
||||||
|
if index > last.ind {
|
||||||
|
nav.down(index - last.ind)
|
||||||
|
} else {
|
||||||
|
nav.up(last.ind - index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) findNext() bool {
|
func (nav *nav) findNext() bool {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind + 1; i < len(last.files); i++ {
|
for i := last.ind + 1; i < len(last.files); i++ {
|
||||||
@@ -677,7 +700,7 @@ func (nav *nav) findNext() bool {
|
|||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < last.ind; i++ {
|
for i := 0; i < last.ind; i++ {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
nav.down(i - last.ind)
|
nav.up(last.ind - i)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -689,7 +712,7 @@ func (nav *nav) findPrev() bool {
|
|||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind - 1; i >= 0; i-- {
|
for i := last.ind - 1; i >= 0; i-- {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
nav.down(i - last.ind)
|
nav.up(last.ind - i)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user