Don't overwrite the body if there are no changes.

Fixes issue #1 .
Sorry, it's early :)

How about something like:

var diff bool
if sameSize {
  var err error
  if diff, err = bodyDiff(...); err != nil { ... }
}
if !sameSize || diff {
  writeBody(...)
  showAddr(...)
}

Anyway, there's some nice way to handle it all in the same block. I am sure
of it. Let's find the way.

On Mon Dec 29 2014 at 8:37:26 AM David R. Jenni <notifications@github.com>
wrote:

> In fmt.go <https://github.com/eaburns/Fmt/pull/2#discussion-diff-22311783>
> :
>
> >  	if err != nil {
> >  		fmt.Fprintf(os.Stderr, "format failed: %s\n", err)
> > -		status = 1
> > -		goto out
> > +		exit(1, ffile)
> > +	}
> > +	if !noChange {
>
> I don't understand how this snippet would handle all formatting changes.
> In my eyes it's like this:
>
> if sameSize { // same size, we need to compare ffile and body
>   switch diff, err := bodyDiff(ffile); {
>   case err != nil:
>     fmt.Fprintf(os.Stderr, "failed to diff the body: ", err)
>     fallthrough // Not fatal. Re-write the body anyway.
>   case diff:
>     // No need for a separate writeFile function.
>     // It's not writing a file, it's writing the body and setting the address.
>     // Just do them both here.
>     if err := writeBody(win, ffile); err != nil {...}
>     if err := showAddr(win, q0, q1); err != nil { ... }
>     // cleanup and exit with status 0
>   }
> }
> // The size differs (we know something changed without comparing), so we write the body.
> if err := writeBody(win, ffile); err != nil {...}
> if err := showAddr(win, q0, q1); err != nil { ... }
> // cleanup and exit with status 0
>
> This introduces the code duplication (writeBody, showAddr, cleanup and
> exit) I tried to remove with a function.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/eaburns/Fmt/pull/2/files#r22311783>.
>