diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 775301ee..159e646f 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -352,9 +352,11 @@ func main() { } else { fmt.Println("Micro encountered an error:", errors.Wrap(err, 2).ErrorStack(), "\nIf you can reproduce this error, please report it at https://github.com/zyedidia/micro/issues") } - // backup all open buffers + // immediately backup all buffers with unsaved changes for _, b := range buffer.OpenBuffers { - b.Backup() + if b.Modified() { + b.Backup() + } } exit(1) } diff --git a/cmd/micro/micro_test.go b/cmd/micro/micro_test.go index 31007cb1..7235bac1 100644 --- a/cmd/micro/micro_test.go +++ b/cmd/micro/micro_test.go @@ -55,9 +55,11 @@ func startup(args []string) (tcell.SimulationScreen, error) { if err := recover(); err != nil { screen.Screen.Fini() fmt.Println("Micro encountered an error:", err) - // backup all open buffers + // immediately backup all buffers with unsaved changes for _, b := range buffer.OpenBuffers { - b.Backup() + if b.Modified() { + b.Backup() + } } // Print the stack trace too log.Fatalf(errors.Wrap(err, 2).ErrorStack())