all repos — fae @ 42766a9db04fb0c36ce72c633e507cff2386a073

A minuscule find and edit utility.

Updating only files where substitutions have been performed.
Fabio Cevasco h3rald@h3rald.com
Mon, 14 Mar 2016 15:11:55 +0100
commit

42766a9db04fb0c36ce72c633e507cff2386a073

parent

f48349e113966a77e49887aea6ff5b26bd194122

1 files changed, 4 insertions(+), 1 deletions(-)

jump to
M far.nimfar.nim

@@ -175,10 +175,12 @@ var contents = ""

var contentsLen = 0 var lineN = 0 var fileLines = newSeq[string]() + var hasSubstitutions = false var file: File if not file.open(f): raise newException(IOError, "Unable to open file '$1'" % f) while file.readline(contents): + hasSubstitutions = false lineN.inc contentsLen = contents.len fileLines.add contents

@@ -199,6 +201,7 @@ for i in 0..(f.len+1):

stdout.write(" ") displayMatch(replacement, matchstart, matchend+offset, fgYellow, lineN) if (options.apply or confirm("Confirm replacement? [Y/n] ")): + hasSubstitutions = true subsN.inc contents = replacement fileLines[fileLines.high] = replacement

@@ -206,7 +209,7 @@ else:

displayFile(f, silent = options.silent) displayMatch(contents, match[0], match[1], fgYellow, lineN, silent = options.silent) match = matchBounds(contents, options.regex, matchend+offset+1, flags = options.flags) - if (not options.test) and (options.substitute != nil): + if (not options.test) and (options.substitute != nil) and hasSubstitutions: f.writefile(fileLines.join("\n")) return [matchesN, subsN]