Updating only files where substitutions have been performed.
Fabio Cevasco h3rald@h3rald.com
Mon, 14 Mar 2016 15:11:55 +0100
1 files changed,
4 insertions(+),
1 deletions(-)
jump to
M
far.nim
→
far.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]