From 4833ec5f8dec865fbf600a0aeab2bc64fc620f96 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 14 Dec 2020 19:38:25 +0300 Subject: [PATCH] Do not duplicate do-files It does not hurt redo workability itself, but confuses redo-whichdo. --- do.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/do.go b/do.go index 4ed91dd..360cc29 100644 --- a/do.go +++ b/do.go @@ -49,6 +49,7 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { if exists { return doFile, 0, nil } + doFileOrig := doFile levels := []string{} extsOrig := strings.Split(tgt, ".")[1:] dirAbsPrev := "" @@ -59,6 +60,19 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { doFile = strings.Join(append( []string{"default"}, append(exts, "do")..., ), ".") + if len(levels) > 0 || doFile != doFileOrig { + exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) + if err != nil { + return "", 0, err + } + if exists { + return doFile, len(levels), nil + } + } + exts = exts[1:] + } + doFile = "default.do" + if len(levels) > 0 || doFile != doFileOrig { exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) if err != nil { return "", 0, err @@ -66,15 +80,6 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { if exists { return doFile, len(levels), nil } - exts = exts[1:] - } - doFile = "default.do" - exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) - if err != nil { - return "", 0, err - } - if exists { - return doFile, len(levels), nil } levels = append(levels, "..") dirAbs, err := filepath.Abs(updir) -- 2.44.0