]> git.lizzy.rs Git - micro.git/commitdiff
Fix autosave not running by default
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 9 Oct 2020 03:33:34 +0000 (23:33 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 9 Oct 2020 03:33:34 +0000 (23:33 -0400)
cmd/micro/micro.go
internal/config/autosave.go

index 502fb1376bca079c6ac4b41ca519daa645279e07..0a2a55aa8dc4f51481c7b2bde6493d17ee3048b1 100644 (file)
@@ -354,6 +354,11 @@ func main() {
                action.InfoBar.Error(clipErr, " or change 'clipboard' option")
        }
 
+       if a := config.GetGlobalOption("autosave").(float64); a > 0 {
+               config.SetAutoTime(int(a))
+               config.StartAutoSave()
+       }
+
        screen.Events = make(chan tcell.Event)
 
        // Here is the event loop which runs in a separate thread
index db473081aab79dc5910da9c816ac8addd4325eb0..2d0f8cec30a2c84f388a6bd20f1dd8c99e207e71 100644 (file)
@@ -31,14 +31,13 @@ func GetAutoTime() int {
 func StartAutoSave() {
        go func() {
                for {
-                       if autotime < 1 {
-                               break
-                       }
-                       time.Sleep(time.Duration(autotime) * time.Second)
-                       // it's possible autotime was changed while sleeping
-                       if autotime < 1 {
+                       autolock.Lock()
+                       a := autotime
+                       autolock.Unlock()
+                       if a < 1 {
                                break
                        }
+                       time.Sleep(time.Duration(a) * time.Second)
                        Autosave <- true
                }
        }()