Add autosave option

This commit is contained in:
Zachary Yedidia
2019-08-04 14:22:24 -07:00
parent bc6dd990e5
commit c0293b5d0e
9 changed files with 73 additions and 29 deletions

View File

@@ -0,0 +1,30 @@
package config
import (
"log"
"time"
)
var Autosave chan bool
func init() {
Autosave = make(chan bool)
}
func StartAutoSave() {
go func() {
for {
autotime := time.Duration(GlobalSettings["autosave"].(float64))
if autotime < 1 {
break
}
time.Sleep(autotime * time.Second)
log.Println("Autosave")
Autosave <- true
}
}()
}
func StopAutoSave() {
GlobalSettings["autosave"] = float64(0)
}

View File

@@ -2,7 +2,6 @@ package config
const (
DoubleClickThreshold = 400 // How many milliseconds to wait before a second click is not a double click
AutosaveTime = 8 // Number of seconds to wait before autosaving
)
var Bindings map[string]string

File diff suppressed because one or more lines are too long

View File

@@ -30,6 +30,7 @@ var (
// Options with validators
var optionValidators = map[string]optionValidator{
"autosave": validateNonNegativeValue,
"tabsize": validatePositiveValue,
"scrollmargin": validateNonNegativeValue,
"scrollspeed": validateNonNegativeValue,
@@ -150,7 +151,6 @@ func GetGlobalOption(name string) interface{} {
var defaultCommonSettings = map[string]interface{}{
"autoindent": true,
"autosave": false,
"basename": false,
"colorcolumn": float64(0),
"cursorline": true,
@@ -209,6 +209,7 @@ func DefaultCommonSettings() map[string]interface{} {
}
var defaultGlobalSettings = map[string]interface{}{
"autosave": float64(0),
"colorscheme": "default",
"infobar": true,
"keymenu": false,